This commit is contained in:
Stavros kois
2023-01-28 23:51:59 +02:00
parent b11d668c9e
commit 7204a09c28
8 changed files with 271 additions and 140 deletions
@@ -109,8 +109,11 @@ tests:
- it: should pass with hostNet and changed dnsPolicy
documentIndex: *deploymentDoc
set:
dnsPolicy: Default
hostNetwork: true
controllers:
main:
pod:
dnsPolicy: Default
hostNetwork: true
asserts:
- equal:
path: spec.template.spec.dnsPolicy
@@ -326,8 +329,11 @@ tests:
- it: should fail without hostnames in hostAliases
set:
hostAliases:
- ip: 1.1.1.1
controllers:
main:
pod:
hostAliases:
- ip: 1.1.1.1
asserts:
- failedTemplate:
errorMessage: At least one <hostnames> is required in hostAliases
@@ -34,10 +34,11 @@ tests:
documentIndex: *deploymentDoc
set:
some_key: some_value
controller:
labels:
controller_key: controller_value
controller_key2: "{{ .Values.some_key }}"
controllers:
main:
labels:
controller_key: controller_value
controller_key2: "{{ .Values.some_key }}"
global:
labels:
global_key: global_value
@@ -63,9 +64,12 @@ tests:
documentIndex: *deploymentDoc
set:
some_key: some_value2
podLabels:
test: some_value
test2: "{{ .Values.some_key }}"
controllers:
main:
pod:
labels:
test: some_value
test2: "{{ .Values.some_key }}"
asserts:
- equal:
path: spec.template.metadata.labels.test2
@@ -16,7 +16,9 @@ tests:
- it: should pass with nameOverride
documentIndex: *deploymentDoc
set:
nameOverride: overrodename
controllers:
main:
nameOverride: overrodename
asserts:
- equal:
path: metadata.name
@@ -25,7 +27,9 @@ tests:
- it: should pass with global.nameOverride
documentIndex: *deploymentDoc
set:
nameOverride: overrodename
controllers:
main:
nameOverride: overrodename
global:
nameOverride: globaloverrodename
asserts:
@@ -16,7 +16,7 @@ tests:
fsGroupChangePolicy: OnRootMismatch
supplementalGroups: []
- it: should pass with changed podSecurity values
- it: should pass with changed podSecurity values from default
documentIndex: *deploymentDoc
set:
podSecurityContext:
@@ -33,42 +33,77 @@ tests:
supplementalGroups:
- 1000
- it: should pass with changed podSecurity values
documentIndex: *deploymentDoc
set:
controllers:
main:
pod:
securityContext:
fsGroup: 999
fsGroupChangePolicy: Always
supplementalGroups:
- 1000
asserts:
- equal:
path: spec.template.spec.securityContext
value:
fsGroup: 999
fsGroupChangePolicy: Always
supplementalGroups:
- 1000
- it: should fail with invalid fsGroupChangePolicy
set:
podSecurityContext:
fsGroupChangePolicy: invalid_policy
controllers:
main:
pod:
securityContext:
fsGroupChangePolicy: invalid_policy
asserts:
- failedTemplate:
errorMessage: Invalid option for fsGroupChangePolicy. Valid options are <Always> and <OnRootMismatch>.
- it: should fail with empty fsGroupChangePolicy
set:
podSecurityContext:
fsGroupChangePolicy:
controllers:
main:
pod:
securityContext:
fsGroupChangePolicy:
asserts:
- failedTemplate:
errorMessage: <fsGroupChangePolicy> key cannot be empty. Set a value or remove the key for the default (OnRootMismatch) to take effect.
- it: should fail with empty fsGroup
set:
podSecurityContext:
fsGroup:
controllers:
main:
pod:
securityContext:
fsGroup:
asserts:
- failedTemplate:
errorMessage: <fsGroup> key cannot be empty. Set a value or remove the key for the default (568) to take effect.
- it: should fail with non-int fsGroup
set:
podSecurityContext:
fsGroup: "1000"
controllers:
main:
pod:
securityContext:
fsGroup: "1000"
asserts:
- failedTemplate:
errorMessage: <fsGroup> key has value of ("1000"). But must be an int.
- it: should fail with empty supplementalGroups
set:
podSecurityContext:
supplementalGroups:
controllers:
main:
pod:
securityContext:
supplementalGroups:
asserts:
- failedTemplate:
errorMessage: <supplementalGroups> key has a value (<nil>). But it must be a list. Set a list value or remove the key for the default ([]) to take effect.
@@ -45,7 +45,10 @@ tests:
- it: should pass overriding global and per pod runtime
documentIndex: *deploymentDoc
set:
runtimeClassName: perpod
controllers:
main:
pod:
runtimeClassName: perpod
scaleGPU:
something: blabla
globalDefaults:
@@ -82,7 +85,10 @@ tests:
- it: should pass with pod runtime set
documentIndex: *deploymentDoc
set:
runtimeClassName: something
controllers:
main:
pod:
runtimeClassName: something
asserts:
- equal:
path: spec.template.spec.runtimeClassName
@@ -15,7 +15,10 @@ tests:
- it: should pass with terminationGracePeriodSeconds set
documentIndex: *deploymentDoc
set:
terminationGracePeriodSeconds: 25
controllers:
main:
pod:
terminationGracePeriodSeconds: 25
asserts:
- equal:
path: spec.template.spec.terminationGracePeriodSeconds
@@ -24,7 +27,10 @@ tests:
- it: should pass with schedulerName set
documentIndex: *deploymentDoc
set:
schedulerName: some_scheduler
controllers:
main:
pod:
schedulerName: some_scheduler
asserts:
- equal:
path: spec.template.spec.schedulerName
@@ -34,7 +40,10 @@ tests:
documentIndex: *deploymentDoc
set:
name: some_scheduler
schedulerName: "{{ .Values.name }}"
controllers:
main:
pod:
schedulerName: "{{ .Values.name }}"
asserts:
- equal:
path: spec.template.spec.schedulerName
@@ -43,7 +52,10 @@ tests:
- it: should pass with schedulerName set
documentIndex: *deploymentDoc
set:
priorityClassName: some_priority_class_name
controllers:
main:
pod:
priorityClassName: some_priority_class_name
asserts:
- equal:
path: spec.template.spec.priorityClassName
@@ -53,7 +65,10 @@ tests:
documentIndex: *deploymentDoc
set:
name: some_priority_class_name
priorityClassName: "{{ .Values.name }}"
controllers:
main:
pod:
priorityClassName: "{{ .Values.name }}"
asserts:
- equal:
path: spec.template.spec.priorityClassName
@@ -69,7 +84,10 @@ tests:
- it: should pass with set restartPolicy
documentIndex: *deploymentDoc
set:
restartPolicy: Always
controllers:
main:
pod:
restartPolicy: Always
asserts:
- equal:
path: spec.template.spec.restartPolicy
@@ -77,54 +95,54 @@ tests:
- it: should fail with invalid restartPolicy
set:
restartPolicy: invalid
controllers:
main:
pod:
restartPolicy: invalid
asserts:
- failedTemplate:
errorMessage: Invalid <restartPolicy> (invalid). Valid options are Always, Never, OnFailure
- it: should fail with invalid restartPolicy on Deployment
set:
controller:
type: Deployment
restartPolicy: OnFailure
controllers:
main:
type: Deployment
pod:
restartPolicy: OnFailure
asserts:
- failedTemplate:
errorMessage: Invalid <restartPolicy (OnFailure). Valid option for Deployment, StatefulSet, DaemonSet and ReplicaSet is Always
errorMessage: Invalid <restartPolicy (OnFailure). Valid option for Deployment, StatefulSet, DaemonSet is Always
# Bellow tests cannot be verified currently,
# until templates are created for those controller types
# TODO:
# - it: should fail with invalid restartPolicy on DaemonSet
# set:
# controller:
# type: DaemonSet
# restartPolicy: OnFailure
# asserts:
# - failedTemplate:
# errorMessage: Invalid <restartPolicy (OnFailure). Valid option for Deployment, StatefulSet, DaemonSet and ReplicaSet is Always
- it: should fail with invalid restartPolicy on DaemonSet
set:
controllers:
main:
type: DaemonSet
pod:
restartPolicy: OnFailure
asserts:
- failedTemplate:
errorMessage: Invalid <restartPolicy (OnFailure). Valid option for Deployment, StatefulSet, DaemonSet is Always
# - it: should fail with invalid restartPolicy on StatefulSet
# set:
# controller:
# type: StatefulSet
# restartPolicy: OnFailure
# asserts:
# - failedTemplate:
# errorMessage: Invalid <restartPolicy (OnFailure). Valid option for Deployment, StatefulSet, DaemonSet and ReplicaSet is Always
# - it: should fail with invalid restartPolicy on ReplicaSet
# set:
# controller:
# type: ReplicaSet
# restartPolicy: OnFailure
# asserts:
# - failedTemplate:
# errorMessage: Invalid <restartPolicy (OnFailure). Valid option for Deployment, StatefulSet, DaemonSet and ReplicaSet is Always
- it: should fail with invalid restartPolicy on StatefulSet
set:
controllers:
main:
type: StatefulSet
pod:
restartPolicy: OnFailure
asserts:
- failedTemplate:
errorMessage: Invalid <restartPolicy (OnFailure). Valid option for Deployment, StatefulSet, DaemonSet is Always
- it: should fail with no value in a key in nodeSelector
set:
nodeSelector:
diskType:
controllers:
main:
pod:
nodeSelector:
diskType:
asserts:
- failedTemplate:
errorMessage: Value is required on every key in <nodeSelector>
@@ -132,9 +150,12 @@ tests:
- it: should pass with nodeSelector set
documentIndex: *deploymentDoc
set:
nodeSelector:
diskType: ssd
cpuType: intel
controllers:
main:
pod:
nodeSelector:
diskType: ssd
cpuType: intel
asserts:
- equal:
path: spec.template.spec.nodeSelector
@@ -147,9 +168,12 @@ tests:
set:
some_key: ssd
some_other_key: intel
nodeSelector:
diskType: "{{ .Values.some_key }}"
cpuType: "{{ .Values.some_other_key }}"
controllers:
main:
pod:
nodeSelector:
diskType: "{{ .Values.some_key }}"
cpuType: "{{ .Values.some_other_key }}"
asserts:
- equal:
path: spec.template.spec.nodeSelector
@@ -159,44 +183,59 @@ tests:
- it: should fail with invalid operator in tolerations
set:
tolerations:
- operator: invalid_op
controllers:
main:
pod:
tolerations:
- operator: invalid_op
asserts:
- failedTemplate:
errorMessage: Invalid <operator>. Valid options are Exists, Equal.
- it: should fail with invalid effect in tolerations
set:
tolerations:
- effect: invalid_effect
operator: Exists
controllers:
main:
pod:
tolerations:
- effect: invalid_effect
operator: Exists
asserts:
- failedTemplate:
errorMessage: Invalid <effect> (invalid_effect). Valid options are NoExecute, NoSchedule, PreferNoSchedule
- it: should fail with empty key and operator Equal in tolerations
set:
tolerations:
- key: ""
operator: Equal
controllers:
main:
pod:
tolerations:
- key: ""
operator: Equal
asserts:
- failedTemplate:
errorMessage: <key> is required when <operator> is set to <Equal>
- it: should fail with operator Exists and defined value in tolerations
set:
tolerations:
- value: something
operator: Exists
controllers:
main:
pod:
tolerations:
- value: something
operator: Exists
asserts:
- failedTemplate:
errorMessage: When <operator> is set to <Exists>, you cannot define a <value>
- it: should fail with operator Exists and non-integer tolerationSeconds in tolerations
set:
tolerations:
- tolerationSeconds: not_an_int
operator: Exists
controllers:
main:
pod:
tolerations:
- tolerationSeconds: not_an_int
operator: Exists
asserts:
- failedTemplate:
errorMessage: <tolerationSeconds> must result to an integer.
@@ -204,9 +243,12 @@ tests:
- it: should pass with tolerations defined, with tolerationSeconds set
documentIndex: *deploymentDoc
set:
tolerations:
- operator: Exists
tolerationSeconds: 6000
controllers:
main:
pod:
tolerations:
- operator: Exists
tolerationSeconds: 6000
asserts:
- equal:
path: spec.template.spec.tolerations
@@ -217,8 +259,11 @@ tests:
- it: should pass with tolerations defined, with only operator Exists
documentIndex: *deploymentDoc
set:
tolerations:
- operator: Exists
controllers:
main:
pod:
tolerations:
- operator: Exists
asserts:
- equal:
path: spec.template.spec.tolerations
@@ -229,8 +274,11 @@ tests:
documentIndex: *deploymentDoc
set:
op: Exists
tolerations:
- operator: "{{ .Values.op }}"
controllers:
main:
pod:
tolerations:
- operator: "{{ .Values.op }}"
asserts:
- equal:
path: spec.template.spec.tolerations
@@ -240,9 +288,12 @@ tests:
- it: should pass with tolerations defined, with only operator Equal and key defined
documentIndex: *deploymentDoc
set:
tolerations:
- operator: Equal
key: key1
controllers:
main:
pod:
tolerations:
- operator: Equal
key: key1
asserts:
- equal:
path: spec.template.spec.tolerations
@@ -254,9 +305,12 @@ tests:
documentIndex: *deploymentDoc
set:
some_key: key1
tolerations:
- operator: Equal
key: "{{ .Values.some_key }}"
controllers:
main:
pod:
tolerations:
- operator: Equal
key: "{{ .Values.some_key }}"
asserts:
- equal:
path: spec.template.spec.tolerations
@@ -267,9 +321,12 @@ tests:
- it: should pass with tolerations defined, with operator Exists and effect defined
documentIndex: *deploymentDoc
set:
tolerations:
- operator: Exists
effect: NoExecute
controllers:
main:
pod:
tolerations:
- operator: Exists
effect: NoExecute
asserts:
- equal:
path: spec.template.spec.tolerations
@@ -281,9 +338,12 @@ tests:
documentIndex: *deploymentDoc
set:
ef1: NoExecute
tolerations:
- operator: Exists
effect: "{{ .Values.ef1 }}"
controllers:
main:
pod:
tolerations:
- operator: Exists
effect: "{{ .Values.ef1 }}"
asserts:
- equal:
path: spec.template.spec.tolerations
@@ -294,10 +354,13 @@ tests:
- it: should pass with tolerations defined, with operator Equal and value defined
documentIndex: *deploymentDoc
set:
tolerations:
- operator: Equal
value: some_value
key: key1
controllers:
main:
pod:
tolerations:
- operator: Equal
value: some_value
key: key1
asserts:
- equal:
path: spec.template.spec.tolerations
@@ -310,10 +373,13 @@ tests:
documentIndex: *deploymentDoc
set:
val: some_value
tolerations:
- operator: Equal
value: "{{ .Values.val }}"
key: key1
controllers:
main:
pod:
tolerations:
- operator: Equal
value: "{{ .Values.val }}"
key: key1
asserts:
- equal:
path: spec.template.spec.tolerations
@@ -326,10 +392,13 @@ tests:
documentIndex: *deploymentDoc
set:
val: some_value
tolerations:
- operator: Equal
value: "{{ .Values.val }}"
key: key1
controllers:
main:
pod:
tolerations:
- operator: Equal
value: "{{ .Values.val }}"
key: key1
asserts:
- equal:
path: spec.template.spec.tolerations
@@ -341,12 +410,15 @@ tests:
- it: should pass with tolerations defined, with everything set, multiple entries
documentIndex: *deploymentDoc
set:
tolerations:
- operator: Equal
value: some_value
key: key1
effect: NoExecute
tolerationSeconds: 6000
controllers:
main:
pod:
tolerations:
- operator: Equal
value: some_value
key: key1
effect: NoExecute
tolerationSeconds: 6000
asserts:
- equal:
path: spec.template.spec.tolerations
@@ -368,17 +440,20 @@ tests:
val2: some_value2
k2: key2
ef2: NoSchedule
tolerations:
- operator: "{{ .Values.op1 }}"
value: "{{ .Values.val1 }}"
key: "{{ .Values.k1 }}"
effect: "{{ .Values.ef1 }}"
tolerationSeconds: 6000
- operator: "{{ .Values.op2 }}"
value: "{{ .Values.val2 }}"
key: "{{ .Values.k2 }}"
effect: "{{ .Values.ef2 }}"
tolerationSeconds: 6000
controllers:
main:
pod:
tolerations:
- operator: "{{ .Values.op1 }}"
value: "{{ .Values.val1 }}"
key: "{{ .Values.k1 }}"
effect: "{{ .Values.ef1 }}"
tolerationSeconds: 6000
- operator: "{{ .Values.op2 }}"
value: "{{ .Values.val2 }}"
key: "{{ .Values.k2 }}"
effect: "{{ .Values.ef2 }}"
tolerationSeconds: 6000
asserts:
- equal:
path: spec.template.spec.tolerations
@@ -3,16 +3,15 @@
{{- $dnsPolicy := .dnsPolicy -}}
{{- $hostNetwork := .hostNetwork -}}
{{- $root := .root -}}
{{- $policy := $root.Values.dnsPolicy -}}
{{- if $dnsPolicy -}}
{{- if not (mustHas $dnsPolicy (list "Default" "ClusterFirst" "ClusterFirstWithHostNet" "None")) -}}
{{- fail (printf "Not valid dnsPolicy (%s). Valid options are ClusterFirst, Default, ClusterFirstWithHostNet, None" $dnsPolicy) -}}
{{- end -}}
{{- $policy = $dnsPolicy -}}
{{- else if $hostNetwork -}}
{{- $policy = "ClusterFirstWithHostNet" -}}
{{- end -}}
{{- if not (mustHas $policy (list "Default" "ClusterFirst" "ClusterFirstWithHostNet" "None")) -}}
{{- fail (printf "Not valid dnsPolicy (%s). Valid options are ClusterFirst, Default, ClusterFirstWithHostNet, None" $policy) -}}
{{- end -}}
{{- $policy -}}
{{- end -}}
@@ -27,11 +27,13 @@ priorityClassName: {{ . }}
hostname: {{ . }}
{{- end -}}
{{- $dnsPol := (include "ix.v1.common.dnsPolicy" (dict "dnsPolicy" $values.controllers.main.pod.dnsPolicy "hostNetwork" $hostNet "root" $root) | trim ) -}}
{{- with (include "ix.v1.common.dnsPolicy" (dict "dnsPolicy" $values.controllers.main.pod.dnsPolicy "hostNetwork" $hostNet "root" $root) | trim ) }}
dnsPolicy: {{ . }}
{{- end -}}
{{- with (include "ix.v1.common.dnsConfig" (dict "dnsPolicy" $values.controllers.main.pod.dnsPolicy "dnsConfig" $values.controllers.main.pod.dnsConfig "root" $root) | trim ) }}
{{- $dnsConf := ($values.controllers.main.pod.dnsConfig | default $root.Values.dnsConfig) -}}
{{- with (include "ix.v1.common.dnsConfig" (dict "dnsPolicy" $dnsPol "dnsConfig" $dnsConf "root" $root) | trim ) }}
dnsConfig:
{{- . | nindent 2 }}
{{- end -}}