diff --git a/charts/pod-director/templates/configmap.yaml b/charts/pod-director/templates/configmap.yaml index 0cd357f..7ca4ad9 100644 --- a/charts/pod-director/templates/configmap.yaml +++ b/charts/pod-director/templates/configmap.yaml @@ -1,4 +1,5 @@ {{- $labelKeyRegex := "^([a-z0-9]([-a-z0-9]*[a-z0-9])?\\.)*([a-z0-9]([-a-z0-9]*[a-z0-9])?\\/)?[a-z0-9]([-a-z0-9]*[a-z0-9])?$" }} +{{- $labelValueRegex := "^[a-z0-9]([-a-z0-9]*[a-z0-9])?$" }} {{- $groupLabel := .Values.config.groupLabel }} {{- if $groupLabel }} {{- if gt (len $groupLabel) 63 }} @@ -8,6 +9,14 @@ {{- fail (printf "The group label '%s' is not a valid label" $groupLabel) }} {{- end }} {{- end }} +{{- range $groupName := keys .Values.config.groups }} + {{- if gt (len $groupName) 63 }} + {{- fail (printf "The group name '%s' is longer than the maximum length 63 for label values" $groupName) }} + {{- end }} + {{- if not (mustRegexMatch $labelValueRegex $groupName) }} + {{- fail (printf "The group name '%s' is not a valid label value and thus cannot be a group name" $groupName) }} + {{- end }} +{{- end }} apiVersion: v1 kind: ConfigMap metadata: diff --git a/charts/pod-director/tests/configmap_test.yaml b/charts/pod-director/tests/configmap_test.yaml index 06dafea..e29f05e 100644 --- a/charts/pod-director/tests/configmap_test.yaml +++ b/charts/pod-director/tests/configmap_test.yaml @@ -39,3 +39,25 @@ tests: asserts: - failedTemplate: errorMessage: "The group label 'not-valid-@-label' is not a valid label" + + - it: given a group name with length greater than 63 chars then templating should fail + set: + config: + groups: + "0123456789012345678901234567890123456789012345678901234567890123": + nodeSelector: + role: "test" + asserts: + - failedTemplate: + errorMessage: "The group name '0123456789012345678901234567890123456789012345678901234567890123' is longer than the maximum length 63 for label values" + + - it: given a group name that is an invalid label value then templating should fail + set: + config: + groups: + "SomeGroup@Name": + nodeSelector: + role: "test" + asserts: + - failedTemplate: + errorMessage: "The group name 'SomeGroup@Name' is not a valid label value and thus cannot be a group name"