From 5a0c941d34c905e6a8a93cd25f21800e9ea9feb6 Mon Sep 17 00:00:00 2001 From: pat-s Date: Sun, 5 Jan 2025 21:56:28 +0100 Subject: [PATCH] set max length for names --- pipeline/backend/kubernetes/utils.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pipeline/backend/kubernetes/utils.go b/pipeline/backend/kubernetes/utils.go index b68bc4731..cb5165f75 100644 --- a/pipeline/backend/kubernetes/utils.go +++ b/pipeline/backend/kubernetes/utils.go @@ -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 }