From 1a2fdde29978ab7365713f64055a7ae1d581ee0a Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Tue, 31 Jan 2023 16:44:59 +0200 Subject: [PATCH] hostname --- .../common-test/tests/pod/hostname_test.yaml | 56 +++++++++++++++++++ .../tests/pod/priority_class_name_test.yaml | 6 +- .../tests/pod/restart_policy_test.yaml | 4 +- .../tests/pod/scheduler_name_test.yaml | 6 +- library/common/1.0.0/docs/controllers.md | 2 + .../1.0.0/templates/lib/controller/_pod.tpl | 4 ++ .../1.0.0/templates/lib/pod/_hostname.tpl.tpl | 22 ++++++++ 7 files changed, 92 insertions(+), 8 deletions(-) create mode 100644 library/common-test/tests/pod/hostname_test.yaml create mode 100644 library/common/1.0.0/templates/lib/pod/_hostname.tpl.tpl diff --git a/library/common-test/tests/pod/hostname_test.yaml b/library/common-test/tests/pod/hostname_test.yaml new file mode 100644 index 0000000000..1b72d5e72a --- /dev/null +++ b/library/common-test/tests/pod/hostname_test.yaml @@ -0,0 +1,56 @@ +suite: pod hostname name test +templates: + - common.yaml +tests: + - it: should pass with empty hostname + set: + controllers: + controller-name1: + enabled: true + primary: true + type: StatefulSet + podSpec: {} + asserts: + - documentIndex: &statefulSetDoc 0 + isKind: + of: StatefulSet + - documentIndex: *statefulSetDoc + isNull: + path: spec.template.spec.hostname + + - it: should pass with hostname set + set: + controllers: + controller-name1: + enabled: true + primary: true + type: StatefulSet + podSpec: + hostname: some-other-hostname + asserts: + - documentIndex: *statefulSetDoc + isKind: + of: StatefulSet + - documentIndex: *statefulSetDoc + equal: + path: spec.template.spec.hostname + value: some-other-hostname + + - it: should pass with hostname from "pod" with tpl + set: + host: some-other-hostname + controllers: + controller-name1: + enabled: true + primary: true + type: StatefulSet + podSpec: + hostname: "{{ .Values.host }}" + asserts: + - documentIndex: *statefulSetDoc + isKind: + of: StatefulSet + - documentIndex: *statefulSetDoc + equal: + path: spec.template.spec.hostname + value: some-other-hostname diff --git a/library/common-test/tests/pod/priority_class_name_test.yaml b/library/common-test/tests/pod/priority_class_name_test.yaml index bb69913178..82796787b3 100644 --- a/library/common-test/tests/pod/priority_class_name_test.yaml +++ b/library/common-test/tests/pod/priority_class_name_test.yaml @@ -31,7 +31,7 @@ tests: type: Deployment podSpec: {} asserts: - - documentIndex: &deploymentDoc 0 + - documentIndex: *deploymentDoc isKind: of: Deployment - documentIndex: *deploymentDoc @@ -51,7 +51,7 @@ tests: podSpec: priorityClassName: some-other-priority-class asserts: - - documentIndex: &deploymentDoc 0 + - documentIndex: *deploymentDoc isKind: of: Deployment - documentIndex: *deploymentDoc @@ -72,7 +72,7 @@ tests: podSpec: priorityClassName: "{{ .Values.priorityclass }}" asserts: - - documentIndex: &deploymentDoc 0 + - documentIndex: *deploymentDoc isKind: of: Deployment - documentIndex: *deploymentDoc diff --git a/library/common-test/tests/pod/restart_policy_test.yaml b/library/common-test/tests/pod/restart_policy_test.yaml index 7e472ab9da..f52754316c 100644 --- a/library/common-test/tests/pod/restart_policy_test.yaml +++ b/library/common-test/tests/pod/restart_policy_test.yaml @@ -32,7 +32,7 @@ tests: type: Deployment podSpec: {} asserts: - - documentIndex: &deploymentDoc 0 + - documentIndex: *deploymentDoc isKind: of: Deployment - documentIndex: *deploymentDoc @@ -93,7 +93,7 @@ tests: podSpec: restartPolicy: "{{ .Values.policy }}" asserts: - - documentIndex: &jobDoc 0 + - documentIndex: *jobDoc isKind: of: Job - documentIndex: *jobDoc diff --git a/library/common-test/tests/pod/scheduler_name_test.yaml b/library/common-test/tests/pod/scheduler_name_test.yaml index 4f5d4a995b..c76bd3f87a 100644 --- a/library/common-test/tests/pod/scheduler_name_test.yaml +++ b/library/common-test/tests/pod/scheduler_name_test.yaml @@ -31,7 +31,7 @@ tests: type: Deployment podSpec: {} asserts: - - documentIndex: &deploymentDoc 0 + - documentIndex: *deploymentDoc isKind: of: Deployment - documentIndex: *deploymentDoc @@ -51,7 +51,7 @@ tests: podSpec: schedulerName: some-other-scheduler asserts: - - documentIndex: &deploymentDoc 0 + - documentIndex: *deploymentDoc isKind: of: Deployment - documentIndex: *deploymentDoc @@ -72,7 +72,7 @@ tests: podSpec: schedulerName: "{{ .Values.scheduler }}" asserts: - - documentIndex: &deploymentDoc 0 + - documentIndex: *deploymentDoc isKind: of: Deployment - documentIndex: *deploymentDoc diff --git a/library/common/1.0.0/docs/controllers.md b/library/common/1.0.0/docs/controllers.md index 49c26bf402..a255ffcb34 100644 --- a/library/common/1.0.0/docs/controllers.md +++ b/library/common/1.0.0/docs/controllers.md @@ -17,6 +17,7 @@ | controllers.[controller-name].podSpec.restartPolicy | `string` | ❌ | ✅ | `{{ .Values.podOptions.restartPolicy }}` (Always) | Pod's restartPolicy. (Always, Never, OnFailure) | | controllers.[controller-name].podSpec.schedulerName | `string` | ❌ | ✅ | `{{ .Values.podOptions.schedulerName }}` ("") | Pod's schedulerName | | controllers.[controller-name].podSpec.priorityClassName | `string` | ❌ | ✅ | `{{ .Values.podOptions.priorityClassName }}` ("") | Pod's priorityClassName | +| controllers.[controller-name].podSpec.hostname | `string` | ❌ | ✅ | `""` | Pod's hostname | --- @@ -60,4 +61,5 @@ controllers: enableServiceLinks: false schedulerName: some-scheduler priorityClassName: some-priority-class-name + hostname: some-hostname ``` 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 b40458f46a..938b2ddde5 100644 --- a/library/common/1.0.0/templates/lib/controller/_pod.tpl +++ b/library/common/1.0.0/templates/lib/controller/_pod.tpl @@ -7,6 +7,7 @@ objectData: The object data to be used to render the Pod. {{- define "ix.v1.common.lib.controller.pod" -}} {{- $rootCtx := .rootCtx -}} {{- $objectData := .objectData -}} +#TODO:serviceAccountName: {{- with (include "ix.v1.common.lib.pod.imagePullSecrets" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim) }} imagePullSecrets: {{- . | nindent 2 }} @@ -20,4 +21,7 @@ schedulerName: {{ . }} {{- with (include "ix.v1.common.lib.pod.priorityClassName" (dict "rootCtx" $rootCtx "objectData" $objectData)) }} priorityClassName: {{ . }} {{- end }} + {{- with (include "ix.v1.common.lib.pod.hostname" (dict "rootCtx" $rootCtx "objectData" $objectData)) }} +hostname: {{ . }} + {{- end }} {{- end -}} diff --git a/library/common/1.0.0/templates/lib/pod/_hostname.tpl.tpl b/library/common/1.0.0/templates/lib/pod/_hostname.tpl.tpl new file mode 100644 index 0000000000..8892f184ea --- /dev/null +++ b/library/common/1.0.0/templates/lib/pod/_hostname.tpl.tpl @@ -0,0 +1,22 @@ +{{/* Returns Host Name */}} +{{/* Call this template: +{{ include "ix.v1.common.lib.pod.hostname" (dict "rootCtx" $ "objectData" $objectData) }} +rootCtx: The root context of the template. It is used to access the global context. +objectData: The object data to be used to render the Pod. +*/}} +{{- define "ix.v1.common.lib.pod.hostname" -}} + {{- $rootCtx := .rootCtx -}} + {{- $objectData := .objectData -}} + + {{- $hostname := "" -}} + + {{- with $objectData.podSpec.hostname -}} + {{- $hostname = tpl . $rootCtx -}} + {{- end -}} + + {{- if $hostname -}} + {{- include "ix.v1.common.lib.chart.names.validation" (dict "name" $hostname) -}} + {{- end -}} + + {{- $hostname -}} +{{- end -}}