From b9e6e8e7a31c5a90b66ca96e1d665490017fcf7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9iy=C3=AC=20Zhang?= Date: Thu, 4 May 2023 14:57:07 -0700 Subject: [PATCH] fixed issue where the webhook doesn't recognize -next as an invalid label --- pkg/webhook/storageclass.go | 3 ++- pkg/webhook/storageclass_test.go | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/pkg/webhook/storageclass.go b/pkg/webhook/storageclass.go index 18291b7a1..c706f51da 100644 --- a/pkg/webhook/storageclass.go +++ b/pkg/webhook/storageclass.go @@ -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) } diff --git a/pkg/webhook/storageclass_test.go b/pkg/webhook/storageclass_test.go index b398eb27c..838992652 100644 --- a/pkg/webhook/storageclass_test.go +++ b/pkg/webhook/storageclass_test.go @@ -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 {