diff --git a/library/common-test/tests/pod/deployment_container_other_test.yaml b/library/common-test/tests/pod/deployment_container_other_test.yaml index d986adbe..639daa95 100644 --- a/library/common-test/tests/pod/deployment_container_other_test.yaml +++ b/library/common-test/tests/pod/deployment_container_other_test.yaml @@ -146,3 +146,40 @@ tests: - failedTemplate: documentIndex: *deploymentDoc errorMessage: No commands were given for postStart lifecycle hook + + - it: should fail with no value in a key in nodeSelector + set: + nodeSelector: + diskType: + asserts: + - failedTemplate: + documentIndex: *deploymentDoc + errorMessage: Value is required on every key in + + - it: should pass with nodeSelector set + set: + nodeSelector: + diskType: ssd + cpuType: intel + asserts: + - equal: + documentIndex: *deploymentDoc + path: spec.template.spec.nodeSelector + value: + diskType: ssd + cpuType: intel + + - it: should pass with nodeSelector set from tpl + set: + some_key: ssd + some_other_key: intel + nodeSelector: + diskType: "{{ .Values.some_key }}" + cpuType: "{{ .Values.some_other_key }}" + asserts: + - equal: + documentIndex: *deploymentDoc + path: spec.template.spec.nodeSelector + value: + diskType: ssd + cpuType: intel diff --git a/library/common/1.0.0/templates/lib/chart/_nodeSelector.tpl b/library/common/1.0.0/templates/lib/chart/_nodeSelector.tpl new file mode 100644 index 00000000..cc8854c5 --- /dev/null +++ b/library/common/1.0.0/templates/lib/chart/_nodeSelector.tpl @@ -0,0 +1,11 @@ +{{/* Returns node selector */}} +{{- define "ix.v1.common.nodeSelector" -}} + {{- with .Values.nodeSelector -}} + {{- range $k, $v := . }} + {{- if (not $v) -}} + {{- fail "Value is required on every key in " -}} + {{- end }} +{{ $k }}: {{ tpl $v $ }} + {{- end }} + {{- end -}} +{{- end -}} diff --git a/library/common/1.0.0/templates/lib/controller/_pod.tpl b/library/common/1.0.0/templates/lib/controller/_pod.tpl index f3f01056..769f8528 100644 --- a/library/common/1.0.0/templates/lib/controller/_pod.tpl +++ b/library/common/1.0.0/templates/lib/controller/_pod.tpl @@ -21,6 +21,10 @@ dnsConfig: hostAliases: {{- . | nindent 2 }} {{- end -}} +{{- with (include "ix.v1.common.nodeSelector" . | trim) }} +nodeSelector: + {{- . | nindent 2 }} +{{- end -}} {{- with .Values.termination.gracePeriodSeconds }} terminationGracePeriodSeconds: {{ . }} {{- end }} diff --git a/library/common/1.0.0/values.yaml b/library/common/1.0.0/values.yaml index 93a4e964..38c41c00 100644 --- a/library/common/1.0.0/values.yaml +++ b/library/common/1.0.0/values.yaml @@ -55,6 +55,8 @@ dnsConfig: {} hostAliases: [] +nodeSelector: {} + # TODO: docs podSecurityContext: runAsUser: 568