diff --git a/library/common-test/tests/pod/dns_config_test.yaml b/library/common-test/tests/pod/dns_config_test.yaml new file mode 100644 index 0000000000..d41ae2e54c --- /dev/null +++ b/library/common-test/tests/pod/dns_config_test.yaml @@ -0,0 +1,237 @@ +suite: pod dns config test +templates: + - common.yaml +tests: + - it: should pass with empty dnsConfig + set: + podOptions: + dnsConfig: + nameservers: [] + searches: [] + options: [] + controllers: + controller-name1: + enabled: true + primary: true + type: Deployment + podSpec: {} + asserts: + - documentIndex: &deploymentDoc 0 + isKind: + of: Deployment + - documentIndex: *deploymentDoc + isNull: + path: spec.template.spec.dnsConfig + + - it: should pass with dnsConfig from "global" + set: + podOptions: + dnsConfig: + nameservers: + - 1.1.1.1 + - 2.2.2.2 + searches: + - example.com + - example.org + options: + - name: ndots + value: "2" + - name: edns0 + controllers: + controller-name1: + enabled: true + primary: true + type: Deployment + podSpec: {} + asserts: + - documentIndex: *deploymentDoc + equal: + path: spec.template.spec.dnsConfig + value: + nameservers: + - 1.1.1.1 + - 2.2.2.2 + searches: + - example.com + - example.org + options: + - name: ndots + value: "2" + - name: edns0 + + - it: should pass with dnsPolicy from "pod" + set: + podOptions: + dnsConfig: + nameservers: + - 1.1.1.1 + searches: + - example.org + options: + - name: edns0 + controllers: + controller-name1: + enabled: true + primary: true + type: Deployment + podSpec: + dnsConfig: + nameservers: + - 1.1.1.1 + - 2.2.2.2 + searches: + - example.com + - example.org + options: + - name: ndots + value: "2" + - name: edns0 + asserts: + - documentIndex: *deploymentDoc + equal: + path: spec.template.spec.dnsConfig + value: + nameservers: + - 1.1.1.1 + - 2.2.2.2 + searches: + - example.com + - example.org + options: + - name: ndots + value: "2" + - name: edns0 + + - it: should pass with dnsPolicy from "pod" with tpl + set: + ns1: 1.1.1.1 + s1: example.com + property: ndots + value: 2 + controllers: + controller-name1: + enabled: true + primary: true + type: Deployment + podSpec: + dnsPolicy: None + dnsConfig: + nameservers: + - "{{ .Values.ns1 }}" + - 2.2.2.2 + searches: + - "{{ .Values.s1 }}" + - example.org + options: + - name: "{{ .Values.property }}" + value: "{{ .Values.value }}" + - name: edns0 + asserts: + - documentIndex: *deploymentDoc + equal: + path: spec.template.spec.dnsConfig + value: + nameservers: + - 1.1.1.1 + - 2.2.2.2 + searches: + - example.com + - example.org + options: + - name: ndots + value: "2" + - name: edns0 + + # Failures + - it: should fail with dnsPolicy set to None and no nameservers + set: + podOptions: + dnsPolicy: None + controllers: + controller-name1: + enabled: true + primary: true + type: Deployment + podSpec: + dnsConfig: + nameservers: [] + asserts: + - failedTemplate: + errorMessage: Expected non-empty with set to [None]. + + - it: should fail with dnsPolicy set to None and no searches + set: + podOptions: + dnsPolicy: None + controllers: + controller-name1: + enabled: true + primary: true + type: Deployment + podSpec: + dnsConfig: + nameservers: + - 1.1.1.1 + searches: [] + asserts: + - failedTemplate: + errorMessage: Expected non-empty with set to [None]. + + - it: should fail with dnsPolicy set to None and no options + set: + podOptions: + dnsPolicy: None + controllers: + controller-name1: + enabled: true + primary: true + type: Deployment + podSpec: + dnsConfig: + nameservers: + - 1.1.1.1 + searches: + - example.com + options: [] + asserts: + - failedTemplate: + errorMessage: Expected non-empty with set to [None]. + + - it: should fail with more than 3 nameservers + set: + controllers: + controller-name1: + enabled: true + primary: true + type: Deployment + podSpec: + dnsConfig: + nameservers: + - 1.1.1.1 + - 1.1.1.1 + - 1.1.1.1 + - 1.1.1.1 + asserts: + - failedTemplate: + errorMessage: Expected no more than [3] , but got [4] + + - it: should fail with more than 6 Searches + set: + controllers: + controller-name1: + enabled: true + primary: true + type: Deployment + podSpec: + dnsConfig: + searches: + - example.com + - example.com + - example.com + - example.com + - example.com + - example.com + - example.com + asserts: + - failedTemplate: + errorMessage: Expected no more than [6] , but got [7] diff --git a/library/common/1.0.0/templates/lib/pod/_dns.tpl b/library/common/1.0.0/templates/lib/pod/_dns.tpl index f378196d7e..5f18e43e7d 100644 --- a/library/common/1.0.0/templates/lib/pod/_dns.tpl +++ b/library/common/1.0.0/templates/lib/pod/_dns.tpl @@ -75,7 +75,7 @@ dnsConfig: {{- end -}} {{- end -}} - {{- with $config.options -}} + {{- with $config.options }} options: {{- range . }} - name: {{ tpl .name $rootCtx }} diff --git a/library/common/1.0.0/values.yaml b/library/common/1.0.0/values.yaml index deb6a80fd0..b1cba6ab35 100644 --- a/library/common/1.0.0/values.yaml +++ b/library/common/1.0.0/values.yaml @@ -113,7 +113,10 @@ podOptions: hostNetwork: false restartPolicy: Always dnsPolicy: ClusterFirst - dnsConfig: {} + dnsConfig: + options: + - name: ndots + value: "2" hostAliases: [] nodeSelector: {} tolerations: []