Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/csi-provisioner/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

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 ""

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

Copy link
Author

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.

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?

shortName := fmt.Sprintf("%s-%s", prefix, hash(name))
Expand Down
4 changes: 4 additions & 0 deletions cmd/csi-provisioner/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Copy link
Contributor

@jsafrane jsafrane Feb 5, 2025

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.

},
"very very long, ignore suffix": {
expected: fmt.Sprintf("%s-%s", externalProvisioner, "df38e37f"),
nodeName: fmt.Sprintf("node%s", strings.Repeat("a", 63)),
},
Expand Down