Skip to content

Commit

Permalink
Merge pull request #516 from k8s-infra-cherrypick-robot/cherry-pick-5…
Browse files Browse the repository at this point in the history
…04-to-release-1.3

[release-1.3] fixed issue where the webhook doesn't recognize -next as an invalid label
  • Loading branch information
k8s-ci-robot authored May 18, 2023
2 parents c0e16db + b9e6e8e commit b7184c5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/webhook/storageclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func applyV1StorageClassPatch(sc *storagev1.StorageClass) *v1.AdmissionResponse
}

func validateInstanceLabel(label string) bool {
regex, _ := regexp.Compile(`^[\p{Ll}0-9_-]{0,63}$`)
// https://cloud.google.com/filestore/docs/managing-labels#requirements
regex, _ := regexp.Compile(`^(([a-z][a-z0-9_-]{0,61})?[a-z0-9])?$`)
return regex.MatchString(label)
}
15 changes: 15 additions & 0 deletions pkg/webhook/storageclass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,21 @@ func TestValidateInstanceLabel(t *testing.T) {
label: "abc-*",
isValid: false,
},
{
name: "label start with none-letter",
label: "-next",
isValid: false,
},
{
name: "label start with number",
label: "123",
isValid: false,
},
{
name: "label end with none-letter",
label: "next-",
isValid: false,
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit b7184c5

Please sign in to comment.