diff --git a/library/common-test/tests/pod/deployment_dns-network_test.yaml b/library/common-test/tests/pod/deployment_dns-network_test.yaml index fef16390..b066b418 100644 --- a/library/common-test/tests/pod/deployment_dns-network_test.yaml +++ b/library/common-test/tests/pod/deployment_dns-network_test.yaml @@ -248,3 +248,78 @@ tests: - name: ndots value: "2" - name: edns0 + + - it: should fail without ip in hostAliases + set: + hostAliases: + - hostnames: + - hostname1 + asserts: + - failedTemplate: + documentIndex: *deploymentDoc + errorMessage: field is required in hostAliases + + - it: should fail without hostnames in hostAliases + set: + hostAliases: + - ip: 1.1.1.1 + asserts: + - failedTemplate: + documentIndex: *deploymentDoc + errorMessage: At least one is required in hostAliases + + - it: should pass with hostAliases defined + set: + hostAliases: + - ip: 1.1.1.1 + hostnames: + - hostname1 + - hostname2 + - ip: 8.8.8.8 + hostnames: + - hostname3 + - hostname4 + asserts: + - equal: + documentIndex: *deploymentDoc + path: spec.template.spec.hostAliases + value: + - ip: 1.1.1.1 + hostnames: + - hostname1 + - hostname2 + - ip: 8.8.8.8 + hostnames: + - hostname3 + - hostname4 + + - it: should pass with hostAliases defined from tpl + set: + ip1: 1.1.1.1 + ip2: 8.8.8.8 + host1: hostname1 + host2: hostname2 + host3: hostname3 + host4: hostname4 + hostAliases: + - ip: "{{ .Values.ip1 }}" + hostnames: + - "{{ .Values.host1 }}" + - "{{ .Values.host2 }}" + - ip: "{{ .Values.ip2 }}" + hostnames: + - "{{ .Values.host3 }}" + - "{{ .Values.host4 }}" + asserts: + - equal: + documentIndex: *deploymentDoc + path: spec.template.spec.hostAliases + value: + - ip: 1.1.1.1 + hostnames: + - hostname1 + - hostname2 + - ip: 8.8.8.8 + hostnames: + - hostname3 + - hostname4 diff --git a/library/common/1.0.0/templates/lib/chart/_hostAliases.tpl b/library/common/1.0.0/templates/lib/chart/_hostAliases.tpl new file mode 100644 index 00000000..f77e3837 --- /dev/null +++ b/library/common/1.0.0/templates/lib/chart/_hostAliases.tpl @@ -0,0 +1,14 @@ +{{/* Returns host aliases */}} +{{- define "ix.v1.common.hostAliases" -}} + {{- range .Values.hostAliases }} +- ip: {{ (tpl (required " field is required in hostAliases" .ip) $ | quote) }} + {{- if .hostnames }} + hostnames: + {{- range .hostnames }} + - {{ tpl . $ }} + {{- end}} + {{- else -}} + {{- fail "At least one is required in hostAliases" -}} + {{- 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 993b5d87..f3f01056 100644 --- a/library/common/1.0.0/templates/lib/controller/_pod.tpl +++ b/library/common/1.0.0/templates/lib/controller/_pod.tpl @@ -17,6 +17,10 @@ dnsPolicy: {{ . }} dnsConfig: {{- . | nindent 2 }} {{- end -}} +{{- with (include "ix.v1.common.hostAliases" . | trim) }} +hostAliases: + {{- . | nindent 2 }} +{{- end -}} {{- with .Values.termination.gracePeriodSeconds }} terminationGracePeriodSeconds: {{ . }} {{- end }} @@ -30,5 +34,5 @@ containers: {{- with (include "ix.v1.common.controller.volumes" . | trim) }} volumes: {{- . | nindent 2 }} -{{- end }} +{{- end -}} {{- end -}} diff --git a/library/common/1.0.0/values.yaml b/library/common/1.0.0/values.yaml index 16ae67d3..93a4e964 100644 --- a/library/common/1.0.0/values.yaml +++ b/library/common/1.0.0/values.yaml @@ -53,6 +53,8 @@ dnsPolicy: "" dnsConfig: {} +hostAliases: [] + # TODO: docs podSecurityContext: runAsUser: 568