From 34977aa5d81ef428cedb86e11be41eae585b1240 Mon Sep 17 00:00:00 2001 From: Dario Tranchitella Date: Tue, 21 Nov 2023 12:31:15 +0100 Subject: [PATCH] fix: ensuring resourcequota name doesn't break DNS-1123 Signed-off-by: Dario Tranchitella --- api/v1beta2/tenant_annotations.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/api/v1beta2/tenant_annotations.go b/api/v1beta2/tenant_annotations.go index 519e5836..21093693 100644 --- a/api/v1beta2/tenant_annotations.go +++ b/api/v1beta2/tenant_annotations.go @@ -7,6 +7,7 @@ import ( "crypto/md5" //#nosec "encoding/hex" "fmt" + "strings" ) const ( @@ -18,13 +19,13 @@ const ( ) func createAnnotation(format string, resource fmt.Stringer) (string, error) { - suffix := resource.String() + resourceStr := strings.ReplaceAll(resource.String(), "/", "_") - hash := md5.Sum([]byte(resource.String())) //#nosec + hash := md5.Sum([]byte(resourceStr)) //#nosec hashed := hex.EncodeToString(hash[:]) capsuleHashed := format + hashed - capsuleAnnotation := format + suffix + capsuleAnnotation := format + resourceStr switch { case len(capsuleAnnotation) <= maxAnnotationLength: