set max length for names

This commit is contained in:
pat-s 2025-01-05 21:56:28 +01:00
parent 2db8752372
commit 5a0c941d34
No known key found for this signature in database
GPG key ID: 3C6318841EF78925

View file

@ -34,16 +34,21 @@ var (
func dnsName(i string) (string, error) {
res := strings.ToLower(strings.ReplaceAll(i, "_", "-"))
// Check for invalid characters (dnsDisallowedCharacters)
invalidChars := dnsDisallowedCharacters.FindAllString(res, -1)
if len(invalidChars) > 0 {
return "", fmt.Errorf("name is not a valid kubernetes DNS name: found invalid characters '%v'", strings.Join(invalidChars, ""))
}
// Check if the entire string matches the dnsPattern
if !dnsPattern.MatchString(res) {
return "", fmt.Errorf("name is not a valid kubernetes DNS name")
}
// k8s pod name limit
const maxPodNameLength = 253
if len(res) > maxPodNameLength {
res = res[:maxPodNameLength]
}
return res, nil
}