This commit is contained in:
Stavros kois
2023-01-31 16:44:59 +02:00
parent a82b9c596a
commit 1a2fdde299
7 changed files with 92 additions and 8 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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
```

View File

@@ -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 -}}

View File

@@ -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 -}}