-
Notifications
You must be signed in to change notification settings - Fork 78
[release-4.8] OCPBUGS-5527: Fix label key truncation for subscription annotations (#2731) #427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -230,3 +230,61 @@ func TestAddComponents(t *testing.T) { | |
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestComponentLabelKey(t *testing.T) { | ||
| tests := []struct { | ||
| description string | ||
| componentLabelKey string | ||
| name string | ||
| expectedLabel string | ||
| returnsError bool | ||
| }{ | ||
| { | ||
| description: "when componentLabelKey is set then return it", | ||
| componentLabelKey: "my-component-label", | ||
| name: "my-operator", | ||
| expectedLabel: "my-component-label", | ||
| returnsError: false, | ||
| }, | ||
| { | ||
| description: "when componentLabelKey is not set and operator name is less than 63 characters then do not truncate", | ||
| componentLabelKey: "", | ||
| name: "my-operator", | ||
| expectedLabel: ComponentLabelKeyPrefix + "my-operator", | ||
| returnsError: false, | ||
| }, | ||
| { | ||
| description: "when componentLabelKey is not set and operator name is more than 63 characters truncate", | ||
| name: "this-is-my-operator-its-the-coolest-you-got-a-problem-with-that-come-at-me-bro", | ||
| expectedLabel: ComponentLabelKeyPrefix + "this-is-my-operator-its-the-coolest-you-got-a-problem-with-that", | ||
| returnsError: false, | ||
| }, | ||
| { | ||
| description: "when componentLabelKey is not set and operator name is more than 63 characters truncate and drop trailing illegal characters", | ||
| name: "this-is-my-operator-its-the-coolest-you-got-a-problem-with----...---___...---", | ||
| expectedLabel: ComponentLabelKeyPrefix + "this-is-my-operator-its-the-coolest-you-got-a-problem-with", | ||
| returnsError: false, | ||
| }, | ||
| { | ||
| description: "when componentLabelKey is not set and operator name is more than 63 characters and is made up of illegal characters then return error", | ||
| name: "----...---___...-------...---___...-------...---___...-------...---___...---", | ||
| expectedLabel: "", | ||
| returnsError: true, | ||
| }, | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't have the case for a small label key with illegal characters...
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll need to fix this in master. |
||
|
|
||
| for _, tt := range tests { | ||
| operator := &Operator{ | ||
| Operator: &operatorsv1.Operator{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: tt.name, | ||
| }, | ||
| }, | ||
| componentLabelKey: tt.componentLabelKey, | ||
| } | ||
|
|
||
| actualLabel, actualErr := operator.ComponentLabelKey() | ||
| require.Equal(t, tt.returnsError, actualErr != nil, actualErr) | ||
| require.Equal(t, tt.expectedLabel, actualLabel) | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why no one seems to:
Should the illegal characters be checked outside the
len(name)check? Is it possible to set a name with an illegal trailing character? Could that happen?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually prefer your suggestion, but this is a backport of a fix and we attempt to avoid altering the code. We can always create a PR on master to do this though.
The kube api server will reject the create request and OLM will constantly try to create it even with the error, which is why we're backporting this.