add tests

This commit is contained in:
Stavros kois
2023-01-18 15:31:56 +02:00
parent 720adbb739
commit 6c7a33ce1c
14 changed files with 534 additions and 26 deletions

View File

@@ -0,0 +1,64 @@
suite: daemonset annotation test
templates:
- common.yaml
tests:
- it: should pass with default values
documentIndex: &daemonsetDoc 0
set:
controller.type: DaemonSet
asserts:
- hasDocuments:
count: 3
- isKind:
of: DaemonSet
- isNull:
path: metadata.annotations
- matchRegex:
path: spec.template.metadata.annotations.rollme
pattern: "^[a-zA-Z0-9]{5}$"
- it: should pass with controller and global annotations
documentIndex: *daemonsetDoc
set:
controller.type: DaemonSet
some_key: some_value
controller:
annotations:
controller_key: controller_value
controller_key2: "{{ .Values.some_key }}"
global:
annotations:
global_key: global_value
global_key2: "{{ .Values.some_key }}"
asserts:
- equal:
path: metadata.annotations
value:
controller_key: controller_value
controller_key2: some_value
global_key: global_value
global_key2: some_value
- isNull:
path: metadata.annotations.rollme
- matchRegex:
path: spec.template.metadata.annotations.rollme
pattern: "^[a-zA-Z0-9]{5}$"
- it: should pass with podAnnotations set
documentIndex: *daemonsetDoc
set:
controller.type: DaemonSet
some_key: some_value2
podAnnotations:
test: some_value
test2: "{{ .Values.some_key }}"
asserts:
- isSubset:
path: spec.template.metadata.annotations
content:
app: common-test
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/name: common-test
release: RELEASE-NAME
test2: some_value2
test: some_value

View File

@@ -0,0 +1,63 @@
suite: daemonset strategy test
templates:
- common.yaml
tests:
- it: should pass with strategy changed in DaemonSet
documentIndex: &dameonsetDoc 0
set:
controller:
type: DaemonSet
strategy: OnDelete
rollingUpdate:
surge: 5
unavailable: 6
asserts:
- hasDocuments:
count: 3
- isKind:
of: DaemonSet
- equal:
path: spec.updateStrategy
value:
type: OnDelete
- isNull:
path: spec.updateStrategy.rollingUpdate
- it: should pass with strategy changed in DaemonSet
documentIndex: *dameonsetDoc
set:
controller:
type: DaemonSet
strategy: RollingUpdate
rollingUpdate:
surge: 5
unavailable: 6
asserts:
- equal:
path: spec.updateStrategy
value:
type: RollingUpdate
rollingUpdate:
maxSurge: 5
maxUnavailable: 6
- it: should fail with wrong strategy
documentIndex: *dameonsetDoc
set:
controller:
type: DaemonSet
strategy: not_valid_strategy
asserts:
- failedTemplate:
errorMessage: Not a valid strategy type for DaemonSet (not_valid_strategy)
- it: should pass with revisionHistoryLimit changed
documentIndex: *dameonsetDoc
set:
controller:
type: DaemonSet
revisionHistoryLimit: 1
asserts:
- equal:
path: spec.revisionHistoryLimit
value: 1

View File

@@ -0,0 +1,110 @@
suite: daemonset default test
templates:
- common.yaml
tests:
- it: should pass with controller set to DaemonSet
documentIndex: &daemonsetDoc 0
set:
controller.type: DaemonSet
asserts:
- hasDocuments:
count: 3
- isKind:
of: DaemonSet
- isAPIVersion:
of: apps/v1
- equal:
path: spec.revisionHistoryLimit
value: 3
- equal:
path: spec.updateStrategy.type
value: RollingUpdate
- equal:
path: spec.template.spec.serviceAccountName
value: default
- equal:
path: spec.template.spec.hostNetwork
value: false
- equal:
path: spec.template.spec.terminationGracePeriodSeconds
value: 10
- equal:
path: spec.template.spec.enableServiceLinks
value: false
- equal:
path: spec.template.spec.terminationGracePeriodSeconds
value: 10
- isNull:
path: spec.template.spec.hostname
- equal:
path: spec.template.spec.dnsPolicy
value: ClusterFirst
- isNull:
path: spec.template.spec.dnsConfig
- isNull:
path: spec.template.spec.priorityClassName
- isNull:
path: spec.template.spec.schedulerName
- equal:
path: spec.template.spec.containers[0].name
value: RELEASE-NAME-common-test
- equal:
path: spec.template.spec.containers[0].image
value: repo:tag
- isNull:
path: spec.template.spec.containers[0].command
- isNull:
path: spec.template.spec.containers[0].args
- equal:
path: spec.template.spec.containers[0].tty
value: false
- equal:
path: spec.template.spec.containers[0].stdin
value: false
- isNull:
path: spec.template.spec.containers[0].lifecycle
- isNull:
path: spec.template.spec.containers[0].terminationMessagePath
- isNull:
path: spec.template.spec.containers[0].terminationMessagePolicy
- equal:
path: spec.template.spec.securityContext
value:
fsGroup: 568
fsGroupChangePolicy: OnRootMismatch
supplementalGroups: []
- equal:
path: spec.template.spec.containers[0].securityContext
value:
allowPrivilegeEscalation: false
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
runAsUser: 568
runAsGroup: 568
capabilities:
add: []
drop:
- ALL
- equal:
path: spec.template.spec.containers[0].env
value:
- name: TZ
value: UTC
- name: UMASK
value: "002"
- name: UMASK_SET
value: "002"
- name: NVIDIA_VISIBLE_DEVICES
value: void
- name: S6_READ_ONLY_ROOT
value: "1"
- equal:
path: spec.template.spec.containers[0].volumeMounts
value:
- mountPath: /shared
name: shared
- mountPath: /tmp
name: tmp
- mountPath: /var/logs
name: varlogs

View File

@@ -0,0 +1,79 @@
suite: daemonset label test
templates:
- common.yaml
chart:
appVersion: &appVer v1.2.3
tests:
- it: should pass with default values
documentIndex: &daemonsetDoc 0
set:
controller.type: DaemonSet
asserts:
- hasDocuments:
count: 3
- isKind:
of: DaemonSet
- equal:
path: metadata.labels
value:
app: common-test
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: common-test
app.kubernetes.io/version: *appVer
helm-revision: "0"
helm.sh/chart: common-test-1.0.0
release: RELEASE-NAME
- equal:
path: spec.selector.matchLabels
value:
app: common-test
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/name: common-test
release: RELEASE-NAME
- it: should pass with controller and global labels
documentIndex: *daemonsetDoc
set:
controller.type: DaemonSet
some_key: some_value
controller:
labels:
controller_key: controller_value
controller_key2: "{{ .Values.some_key }}"
global:
labels:
global_key: global_value
global_key2: "{{ .Values.some_key }}"
asserts:
- equal:
path: metadata.labels
value:
controller_key: controller_value
controller_key2: some_value
global_key: global_value
global_key2: some_value
app: common-test
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: common-test
app.kubernetes.io/version: *appVer
helm-revision: "0"
helm.sh/chart: common-test-1.0.0
release: RELEASE-NAME
- it: should pass with podLabels set
documentIndex: *daemonsetDoc
set:
controller.type: DaemonSet
some_key: some_value2
podLabels:
test: some_value
test2: "{{ .Values.some_key }}"
asserts:
- equal:
path: spec.template.metadata.labels.test2
value: some_value2
- equal:
path: spec.template.metadata.labels.test
value: some_value

View File

@@ -0,0 +1,38 @@
suite: daemonset name test
templates:
- common.yaml
tests:
- it: should pass with default values
documentIndex: &daemonsetDoc 0
set:
controller.type: DaemonSet
asserts:
- hasDocuments:
count: 3
- isKind:
of: DaemonSet
- equal:
path: metadata.name
value: RELEASE-NAME-common-test
- it: should pass with nameOverride
documentIndex: *daemonsetDoc
set:
controller.type: DaemonSet
nameOverride: overrodeName
asserts:
- equal:
path: metadata.name
value: RELEASE-NAME-overrodeName
- it: should pass with global.nameOverride
documentIndex: *daemonsetDoc
set:
controller.type: DaemonSet
nameOverride: overrodeName
global:
nameOverride: globalOverrodeName
asserts:
- equal:
path: metadata.name
value: RELEASE-NAME-globalOverrodeName

View File

@@ -78,3 +78,23 @@ tests:
asserts:
- failedTemplate:
errorMessage: Not a valid strategy type for Deployment (not_valid_strategy)
- it: should pass with revisionHistoryLimit changed
documentIndex: *deploymentDoc
set:
controller:
revisionHistoryLimit: 1
asserts:
- equal:
path: spec.revisionHistoryLimit
value: 1
- it: should pass with replicas changed
documentIndex: *deploymentDoc
set:
controller:
replicas: 6
asserts:
- equal:
path: spec.replicas
value: 6

View File

@@ -8,7 +8,7 @@ tests:
- hasDocuments:
count: 3
- isKind:
of: Deployment
of: StatefulSet
- equal:
path: metadata.name
value: RELEASE-NAME-common-test

View File

@@ -20,6 +20,7 @@ tests:
- it: should pass with controller and global annotations
documentIndex: *statefulsetDoc
set:
controller.type: StatefulSet
some_key: some_value
controller:
annotations:
@@ -46,6 +47,7 @@ tests:
- it: should pass with podAnnotations set
documentIndex: *statefulsetDoc
set:
controller.type: StatefulSet
some_key: some_value2
podAnnotations:
test: some_value

View File

@@ -50,3 +50,25 @@ tests:
asserts:
- failedTemplate:
errorMessage: Not a valid strategy type for StatefulSet (not_valid_strategy)
- it: should pass with revisionHistoryLimit changed
documentIndex: *statefulsetDoc
set:
controller:
type: StatefulSet
revisionHistoryLimit: 1
asserts:
- equal:
path: spec.revisionHistoryLimit
value: 1
- it: should pass with replicas changed
documentIndex: *statefulsetDoc
set:
controller:
type: StatefulSet
replicas: 6
asserts:
- equal:
path: spec.replicas
value: 6

View File

@@ -0,0 +1,79 @@
suite: statefulset label test
templates:
- common.yaml
chart:
appVersion: &appVer v1.2.3
tests:
- it: should pass with default values
documentIndex: &statefulsetDoc 0
set:
controller.type: StatefulSet
asserts:
- hasDocuments:
count: 3
- isKind:
of: StatefulSet
- equal:
path: metadata.labels
value:
app: common-test
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: common-test
app.kubernetes.io/version: *appVer
helm-revision: "0"
helm.sh/chart: common-test-1.0.0
release: RELEASE-NAME
- equal:
path: spec.selector.matchLabels
value:
app: common-test
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/name: common-test
release: RELEASE-NAME
- it: should pass with controller and global labels
documentIndex: *statefulsetDoc
set:
controller.type: StatefulSet
some_key: some_value
controller:
labels:
controller_key: controller_value
controller_key2: "{{ .Values.some_key }}"
global:
labels:
global_key: global_value
global_key2: "{{ .Values.some_key }}"
asserts:
- equal:
path: metadata.labels
value:
controller_key: controller_value
controller_key2: some_value
global_key: global_value
global_key2: some_value
app: common-test
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: common-test
app.kubernetes.io/version: *appVer
helm-revision: "0"
helm.sh/chart: common-test-1.0.0
release: RELEASE-NAME
- it: should pass with podLabels set
documentIndex: *statefulsetDoc
set:
controller.type: StatefulSet
some_key: some_value2
podLabels:
test: some_value
test2: "{{ .Values.some_key }}"
asserts:
- equal:
path: spec.template.metadata.labels.test2
value: some_value2
- equal:
path: spec.template.metadata.labels.test
value: some_value

View File

@@ -0,0 +1,38 @@
suite: statefulset name test
templates:
- common.yaml
tests:
- it: should pass with default values
documentIndex: &statefulsetDoc 0
set:
controller.type: StatefulSet
asserts:
- hasDocuments:
count: 3
- isKind:
of: StatefulSet
- equal:
path: metadata.name
value: RELEASE-NAME-common-test
- it: should pass with nameOverride
documentIndex: *statefulsetDoc
set:
controller.type: StatefulSet
nameOverride: overrodeName
asserts:
- equal:
path: metadata.name
value: RELEASE-NAME-overrodeName
- it: should pass with global.nameOverride
documentIndex: *statefulsetDoc
set:
controller.type: StatefulSet
nameOverride: overrodeName
global:
nameOverride: globalOverrodeName
asserts:
- equal:
path: metadata.name
value: RELEASE-NAME-globalOverrodeName

View File

@@ -3,10 +3,3 @@ service:
ports:
main:
port: 65535
# controller:
# type: Job
# cron:
# enabled: true
# schedule: "* * * * *"

View File

@@ -22,7 +22,7 @@ spec:
revisionHistoryLimit: {{ .Values.controller.revisionHistoryLimit }}
{{- $strategy := default "RollingUpdate" .Values.controller.strategy -}}
{{- if not (mustHas $strategy (list "OnDelete" "RollingUpdate")) -}}
{{- fail (printf "Not a valid strategy type for Daemonset (%s)" $strategy) -}}
{{- fail (printf "Not a valid strategy type for DaemonSet (%s)" $strategy) -}}
{{- end }}
updateStrategy:
type: {{ $strategy }}

View File

@@ -21,9 +21,6 @@ metadata:
spec:
revisionHistoryLimit: {{ .Values.controller.revisionHistoryLimit }}
replicas: {{ .Values.controller.replicas }}
selector:
matchLabels:
{{- include "ix.v1.common.labels.selectorLabels" . | nindent 6 }}
serviceName: {{ include "ix.v1.common.names.fullname" . }}
{{- $strategy := default "RollingUpdate" .Values.controller.strategy -}}
{{- if not (mustHas $strategy (list "OnDelete" "RollingUpdate")) -}}
@@ -40,7 +37,22 @@ spec:
{{- with $rollingUpdate.partition }}
partition: {{ . }}
{{- end -}}
{{- end -}}
{{- end }}
selector:
matchLabels:
{{- include "ix.v1.common.labels.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with (mustMerge (include "ix.v1.common.labels.selectorLabels" . | fromYaml) (include "ix.v1.common.annotations.workload" . | fromYaml) (include "ix.v1.common.podAnnotations" . | fromYaml)) }}
annotations:
{{- . | toYaml | trim | nindent 8 }}
{{- end -}}
{{- with (mustMerge (include "ix.v1.common.labels.selectorLabels" . | fromYaml) (include "ix.v1.common.podLabels" . | fromYaml)) }}
labels:
{{- . | toYaml | trim | nindent 8 }}
{{- end }}
spec:
{{- include "ix.v1.common.controller.pod" $ | trim | nindent 6 }}
{{- if .Values.volumeClaimTemplates }}
volumeClaimTemplates:
{{- range $index, $vct := .Values.volumeClaimTemplates }}
@@ -56,18 +68,6 @@ spec:
requests:
storage: {{ tpl ($vct.size | default $.Values.global.defaults.VCTSize) $ | quote }}
{{- end -}}
{{- end }}
template:
metadata:
{{- with (mustMerge (include "ix.v1.common.labels.selectorLabels" . | fromYaml) (include "ix.v1.common.annotations.workload" . | fromYaml) (include "ix.v1.common.podAnnotations" . | fromYaml)) }}
annotations:
{{- . | toYaml | trim | nindent 8 }}
{{- end -}}
{{- with (mustMerge (include "ix.v1.common.labels.selectorLabels" . | fromYaml) (include "ix.v1.common.podLabels" . | fromYaml)) }}
labels:
{{- . | toYaml | trim | nindent 8 }}
{{- end }}
spec:
{{- include "ix.v1.common.controller.pod" $ | trim | nindent 6 }}
{{- end -}}
{{- end }}
{{/*TODO: unittests*/}}