add tests for restartpolicy

This commit is contained in:
Stavros kois
2023-01-31 16:06:32 +02:00
parent 66361f66e0
commit 8a8eff5fc6
4 changed files with 158 additions and 0 deletions
@@ -0,0 +1,134 @@
suite: pod restart policy test
templates:
- common.yaml
tests:
- it: should pass with restartPolicy set from "global"
set:
podOptions:
restartPolicy: Always
controllers:
controller-name1:
enabled: true
primary: true
type: Deployment
podSpec: {}
asserts:
- documentIndex: &deploymentDoc 0
isKind:
of: Deployment
- documentIndex: *deploymentDoc
equal:
path: spec.template.spec.restartPolicy
value: Always
- it: should pass with restartPolicy set from "pod"
set:
podOptions:
restartPolicy: Never
controllers:
controller-name1:
enabled: true
primary: true
type: Deployment
podSpec:
restartPolicy: Always
asserts:
- documentIndex: *deploymentDoc
isKind:
of: Deployment
- documentIndex: *deploymentDoc
equal:
path: spec.template.spec.restartPolicy
value: Always
- it: should pass with restartPolicy set from "pod" on Jobs
set:
podOptions:
restartPolicy: Never
controllers:
controller-name1:
enabled: true
primary: true
type: Job
podSpec:
restartPolicy: OnFailure
asserts:
- documentIndex: &jobDoc 0
isKind:
of: Job
- documentIndex: *jobDoc
equal:
path: spec.template.spec.restartPolicy
value: OnFailure
# Failures
- it: should fail with restartPolicy to Never on Deployment
set:
podOptions:
restartPolicy: Never
controllers:
controller-name1:
enabled: true
primary: true
type: Deployment
podSpec: {}
asserts:
- failedTemplate:
errorMessage: Expected <restartPolicy to be [Always] for [Deployment] but got [Never]
- it: should fail with restartPolicy to Never on DaemonSet
set:
podOptions:
restartPolicy: Never
controllers:
controller-name1:
enabled: true
primary: true
type: DaemonSet
podSpec: {}
asserts:
- failedTemplate:
errorMessage: Expected <restartPolicy to be [Always] for [DaemonSet] but got [Never]
- it: should fail with restartPolicy to Never on StatefulSet
set:
podOptions:
restartPolicy: Never
controllers:
controller-name1:
enabled: true
primary: true
type: StatefulSet
podSpec: {}
asserts:
- failedTemplate:
errorMessage: Expected <restartPolicy to be [Always] for [StatefulSet] but got [Never]
- it: should fail with restartPolicy to invalid on global
set:
podOptions:
restartPolicy: invalid
controllers:
controller-name1:
enabled: true
primary: true
type: StatefulSet
podSpec: {}
asserts:
- failedTemplate:
errorMessage: Expected <restartPolicy to be one of [Never, Always, OnFailure] but got [invalid]
- it: should fail with restartPolicy to invalid-policy on pod
set:
podOptions:
restartPolicy: invalid
controllers:
controller-name1:
enabled: true
primary: true
type: StatefulSet
podSpec:
restartPolicy: invalid-policy
asserts:
- failedTemplate:
errorMessage: Expected <restartPolicy to be one of [Never, Always, OnFailure] but got [invalid-policy]
@@ -13,4 +13,5 @@ imagePullSecrets:
{{- end }}
hostNetwork: {{ include "ix.v1.common.lib.pod.hostNetwork" (dict "rootCtx" $rootCtx "objectData" $objectData) }}
enableServiceLinks: {{ include "ix.v1.common.lib.pod.enableServiceLinks" (dict "rootCtx" $rootCtx "objectData" $objectData) }}
restartPolicy: {{ include "ix.v1.common.lib.pod.restartPolicy" (dict "rootCtx" $rootCtx "objectData" $objectData) }}
{{- end -}}
@@ -0,0 +1,22 @@
{{- define "ix.v1.common.lib.pod.restartPolicy" -}}
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData -}}
{{/* Initialize from the "defaults" */}}
{{- $policy := $rootCtx.Values.podOptions.restartPolicy -}}
{{/* Override from the pod values, if defined */}}
{{- with $objectData.podSpec.restartPolicy -}}
{{- $policy = . -}}
{{- end -}}
{{- if not (mustHas $policy (list "Always" "Never" "OnFailure")) -}}
{{- fail (printf "Expected <restartPolicy to be one of [Never, Always, OnFailure] but got [%s]" $policy) -}}
{{- end -}}
{{- if and (ne "Always" $policy) (mustHas $objectData.type (list "Deployment" "DaemonSet" "StatefulSet")) -}}
{{- fail (printf "Expected <restartPolicy to be [Always] for [%s] but got [%s]" $objectData.type $policy) -}}
{{- end -}}
{{- $policy -}}
{{- end -}}
+1
View File
@@ -111,6 +111,7 @@ resources:
podOptions:
enableServiceLinks: false
hostNetwork: false
restartPolicy: Always
dnsPolicy: ClusterFirst
dnsConfig: {}
hostAliases: []