diff --git a/pkg/api/util/names.go b/pkg/api/util/names.go index 5aec2dfea..a61c1a1be 100644 --- a/pkg/api/util/names.go +++ b/pkg/api/util/names.go @@ -82,7 +82,7 @@ func ComputeSecureUniqueDeterministicNameFromData(fullName string, maxNameLength return fmt.Sprintf("%s-%08x", prefix, hashResult), nil } -// DNSSafeShortenToNCharacters shortens the input string to 52 chars and ensures the last char is an alpha-numeric character. +// DNSSafeShortenToNCharacters shortens the input string to N chars and ensures the last char is an alpha-numeric character. func DNSSafeShortenToNCharacters(in string, maxLength int) string { var alphaNumeric = regexp.MustCompile(`[a-zA-Z\d]`) diff --git a/pkg/api/util/names_test.go b/pkg/api/util/names_test.go index 5a5742c1c..477e67989 100644 --- a/pkg/api/util/names_test.go +++ b/pkg/api/util/names_test.go @@ -122,6 +122,26 @@ func TestDNSSafeShortenToNCharacters(t *testing.T) { } tests := []testcase{ + { + in: "aaaaaaaaaaaaaaa", + maxLength: 0, + expOut: "", + }, + { + in: "aa-----aaaa", + maxLength: 5, + expOut: "aa", + }, + { + in: "aa11111aaaa", + maxLength: 5, + expOut: "aa111", + }, + { + in: "aaAAAAAaaaa", + maxLength: 5, + expOut: "aaAAA", + }, { in: "aaaaaaaaaaaaaaa", maxLength: 3,