Adjust regex to support _ and . and trim them

Now secret names can also contain `_` and `.` and they will be trimmed from start and end of string to be DNS1123 compliant
This commit is contained in:
Eddy Filip
2021-09-08 13:49:32 +03:00
parent e365ebfdfa
commit 88728909ff

View File

@@ -97,7 +97,7 @@ func formatSecretName(value string) string {
return createValidSecretName(value)
}
var invalidDNS1123Chars = regexp.MustCompile("[^a-zA-Z0-9-]+")
var invalidDNS1123Chars = regexp.MustCompile("[^a-zA-Z0-9-_.]+")
func createValidSecretName(value string) string {
result := invalidDNS1123Chars.ReplaceAllString(value, "-")
@@ -107,5 +107,5 @@ func createValidSecretName(value string) string {
}
// first and last character MUST be alphanumeric
return strings.Trim(result, "-")
return strings.Trim(result, "-._")
}