Skip to content

Commit

Permalink
Validate group names as label values
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelin01 committed Aug 14, 2024
1 parent 10cabb0 commit a9c8c89
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
9 changes: 9 additions & 0 deletions charts/pod-director/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
Expand All @@ -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:
Expand Down
22 changes: 22 additions & 0 deletions charts/pod-director/tests/configmap_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit a9c8c89

Please sign in to comment.