Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(helm): validate zone name on install #6739

Merged
merged 1 commit into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/kumactl/cmd/install/install_control_plane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,18 @@ controlPlane:
extraArgs: []string{"--mode", "zone", "--zone", "zone-1"},
errorMsg: "controlPlane.kdsGlobalAddress can't be empty when controlPlane.mode=='zone'",
}),
Entry("--zone is missing when installing zone", errTestCase{
extraArgs: []string{"--kds-global-address", "grpcs://192.168.0.1:5685", "--mode", "zone"},
errorMsg: "Can't have controlPlane.zone to be empty when controlPlane.mode=='zone'",
}),
Entry("--zone is more than 253 characters", errTestCase{
extraArgs: []string{"--kds-global-address", "grpcs://192.168.0.1:5685", "--mode", "zone", "--zone", "takryywlpeftgnlwuwmwwfwohwzqxqlofjfsuuldtatoxlmnniytycvdnduwplvgnpnjwvzmbkqrvgnlovpynrtuyhhrqibdzwbfjrmhvwkkryzfnudghaxmegfvacjlytuyeikuawquolrykwwldjiynaxrpqgxmvwashrkigadzhxdeihcbjurhpmdrnulajpaspqcgzqxsnjrdenhruaawooojpyoprgnnoqiqdhncuztbgfsvhparjlippv"},
errorMsg: "controlPlane.zone must be no more than 253 characters",
}),
Entry("--zone format is invalid when installing zone", errTestCase{
extraArgs: []string{"--kds-global-address", "grpcs://192.168.0.1:5685", "--mode", "zone", "--zone", "Invalid_z0ne"},
errorMsg: "controlPlane.zone must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character",
}),
Entry("--kds-global-address is not valid URL", errTestCase{
extraArgs: []string{"--kds-global-address", "192.168.0.1:1234", "--mode", "zone", "--zone", "zone-1"},
errorMsg: "unable to parse url: parse \"192.168.0.1:1234\"",
Expand Down
8 changes: 8 additions & 0 deletions deployments/charts/kuma/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,14 @@ returns: formatted image string
{{ if eq .Values.controlPlane.mode "zone" }}
{{ if empty .Values.controlPlane.zone }}
{{ fail "Can't have controlPlane.zone to be empty when controlPlane.mode=='zone'" }}
{{ else }}
{{ if gt (len .Values.controlPlane.zone) 253 }}
{{ fail "controlPlane.zone must be no more than 253 characters" }}
{{ else }}
{{ if not (regexMatch "^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$" .Values.controlPlane.zone) }}
{{ fail "controlPlane.zone must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character" }}
{{ end }}
{{ end }}
{{ end }}
{{ if empty .Values.controlPlane.kdsGlobalAddress }}
{{ fail "controlPlane.kdsGlobalAddress can't be empty when controlPlane.mode=='zone', needs to be the global control-plane address" }}
Expand Down