-
Notifications
You must be signed in to change notification settings - Fork 346
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
Fix the managed-by-label getting populated with invalid value. #1334
base: master
Are you sure you want to change the base?
Fix the managed-by-label getting populated with invalid value. #1334
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: vamsikrishna-siddu The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Welcome @vamsikrishna-siddu! |
Hi @vamsikrishna-siddu. Thanks for your PR. I'm waiting for a kubernetes-csi member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
/cc @awels |
@vamsikrishna-siddu: GitHub didn't allow me to request PR reviews from the following users: awels. Note that only kubernetes-csi members and repo collaborators can review this PR, and authors cannot review their own PRs. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Please sign the CLA Authorization first. |
sure |
Hi @mowangdk I have got the CLA Authorization. Can you please review the pr? |
/ok-to-test |
I will try to take a look at this soon, I have been out sick for a few days and I am finally getting to feeling better. |
cmd/csi-provisioner/util.go
Outdated
@@ -36,7 +36,7 @@ func getNameWithMaxLength(base, suffix string, maxLength int) string { | |||
baseLength := maxLength - 10 /*length of -hash-*/ - len(suffix) | |||
|
|||
// if the suffix is too long, ignore it | |||
if baseLength < 0 { | |||
if baseLength <= 0 { | |||
prefix := base[0:min(len(base), max(0, maxLength-9))] | |||
// Calculate hash on initial base-suffix string |
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 think we need to ensure prefix must not equals to ""
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.
And maybe we also need add more ut here to avoid corner cases
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.
Hi @mowangdk ,
with the condition
if baseLength <= 0
the prefix will never by empty.
and I have added a unit test for the above issue. With this it will cover all the corner cases.
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.
@vamsikrishna-siddu Did you mean the prefix outside the if condition? The prefix inside the if condition in getNameWithMaxLength, is not guaranteed i think?
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.
@mowangdk yeah i meant the prefix outside the if condition. But the prefix inside the if condition is also never become empty. The reason is the base is always external-provisioner
and the maxLength is always 63. so the prefix will never be empty. The only case where the prefix will be empty is when we pass the base as empty string. But in code, I dont see any place where we are using this function for any other use case which provides the base as empty string.
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.
yeah,I agreed. But IMHO, it's better not to rely on function parameters because they can change anytime. Instead, parameter validation should be handled within the function itself.
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.
@mowangdk okay got it. I have done the required changes. Can you please review it once again.
looks good to me, I don't think I can /lgtm though |
@@ -45,6 +45,10 @@ func TestGetNameWithMaxLength(t *testing.T) { | |||
nodeName: fmt.Sprintf("node%s", strings.Repeat("a", 39)), | |||
}, | |||
"very long, ignore suffix": { | |||
expected: fmt.Sprintf("%s-%s", externalProvisioner, "a3607ff1"), | |||
nodeName: fmt.Sprintf("node%s", strings.Repeat("a", 49)), |
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.
Please add an unit test also with strings.Repeat("a", 48)
- that's the last that produces e-<hash>-nodeaaaaa...
.
49 here is then the first that skips the node name entirely.
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.
sure
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.
done
5d30e41
to
86f7109
Compare
Signed-off-by: Vamsi Krishna Siddu <[email protected]>
86f7109
to
796fe98
Compare
/lgtm |
What type of PR is this?
/kind bug
What this PR does / why we need it:
There will be a case when the length of the node name is equals to 53 and base length becomes zero. This will make the prefix value to be empty and the label will be generated starting with '-' which is invalid label.
Ex: nodename is
worker1.ocp-virt2-s390x.s390g.lab.eng.rdu2.redhat.com
generated label name:
-53f40b57-worker1.ocp-virt1-s390x.s390g.lab.eng.rdu2.redhat.com
This is causing the issue for the hostpath provisioner while generating csistoragecapacity objects.
W0116 09:21:22.515275 1 reflector.go:547] k8s.io/client-go/informers/factory.go:160: failed to list *v1.CSIStorageCapacity: unable to parse requirement: values[0][csi.storage.k8s.io/managed-by]: Invalid value: "-53f40b57-worker1.ocp-virt1-s390x.s390g.lab.eng.rdu2.redhat.com": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue', or 'my_value', or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?')
Which issue(s) this PR fixes:
Fixes #1333
Special notes for your reviewer:
Does this PR introduce a user-facing change?: