From 928772d8083e0abd868642b59bcf6015647cb355 Mon Sep 17 00:00:00 2001 From: Thomas Eckert Date: Mon, 3 Oct 2022 13:16:49 -0400 Subject: [PATCH] Add tolerations and nodeSelector to server-acl-init-cleanup template with BATS --- .../server-acl-init-cleanup-job.yaml | 8 ++++ .../unit/server-acl-init-cleanup-job.bats | 45 +++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/charts/consul/templates/server-acl-init-cleanup-job.yaml b/charts/consul/templates/server-acl-init-cleanup-job.yaml index 4db5e356e3..f2342cf661 100644 --- a/charts/consul/templates/server-acl-init-cleanup-job.yaml +++ b/charts/consul/templates/server-acl-init-cleanup-job.yaml @@ -62,6 +62,14 @@ spec: limits: memory: "50Mi" cpu: "50m" + {{- if .Values.global.acls.job.tolerations }} + tolerations: + {{ tpl .Values.global.acls.job.tolerations . | indent 12 | trim }} + {{- end }} + {{- if .Values.global.acls.job.nodeSelector }} + nodeSelector: + {{ tpl .Values.global.acls.job.nodeSelector . | indent 12 | trim }} + {{- end }} {{- end }} {{- end }} {{- end }} diff --git a/charts/consul/test/unit/server-acl-init-cleanup-job.bats b/charts/consul/test/unit/server-acl-init-cleanup-job.bats index 3cc17b2682..3fee687e42 100644 --- a/charts/consul/test/unit/server-acl-init-cleanup-job.bats +++ b/charts/consul/test/unit/server-acl-init-cleanup-job.bats @@ -70,3 +70,48 @@ load _helpers yq 'length > 0' | tee /dev/stderr) [ "${actual}" = "true" ] } + +#-------------------------------------------------------------------- +# global.acls.job + +@test "serverACLInitCleanup/Job: tolerations not set by default" { + cd `chart_dir` + local actual=$(helm template \ + -s templates/server-acl-init-job.yaml \ + --set 'global.acls.manageSystemACLs=true' \ + . | tee /dev/stderr | + yq -r '.spec.template.spec.containers[0].tolerations' | tee /dev/stderr) + [ "${actual}" = "null" ] +} + +@test "serverACLInitCleanup/Job: tolerations can be set" { + cd `chart_dir` + local actual=$(helm template \ + -s templates/server-acl-init-job.yaml \ + --set 'global.acls.manageSystemACLs=true' \ + --set 'global.acls.job.tolerations=- key: value' \ + . | tee /dev/stderr | + yq -r '.spec.template.spec.containers[0].tolerations[0].key' | tee /dev/stderr) + [ "${actual}" = "value" ] +} + +@test "serverACLInit/Job: nodeSelector not set by default" { + cd `chart_dir` + local actual=$(helm template \ + -s templates/server-acl-init-job.yaml \ + --set 'global.acls.manageSystemACLs=true' \ + . | tee /dev/stderr | + yq -r '.spec.template.spec.containers[0].nodeSelector' | tee /dev/stderr) + [ "${actual}" = "null" ] +} + +@test "serverACLInit/Job: nodeSelector can be set" { + cd `chart_dir` + local actual=$(helm template \ + -s templates/server-acl-init-job.yaml \ + --set 'global.acls.manageSystemACLs=true' \ + --set 'global.acls.job.nodeSelector=- key: value' \ + . | tee /dev/stderr | + yq -r '.spec.template.spec.containers[0].nodeSelector[0].key' | tee /dev/stderr) + [ "${actual}" = "value" ] +}