add initial statefulset tests

This commit is contained in:
Stavros kois
2023-01-17 20:29:17 +02:00
parent 2b9c549d13
commit 720adbb739
7 changed files with 366 additions and 2 deletions

View File

@@ -11,6 +11,15 @@ tests:
of: Deployment
- isAPIVersion:
of: apps/v1
- equal:
path: spec.revisionHistoryLimit
value: 3
- equal:
path: spec.replicas
value: 1
- equal:
path: spec.strategy.type
value: Recreate
- equal:
path: spec.template.spec.serviceAccountName
value: default

View File

@@ -0,0 +1,62 @@
suite: statefulset annotation 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
- 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: *statefulsetDoc
set:
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: *statefulsetDoc
set:
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,52 @@
suite: statefulset strategy test
templates:
- common.yaml
tests:
- it: should pass with strategy changed in StatefulSet
documentIndex: &statefulsetDoc 0
set:
controller:
type: StatefulSet
strategy: OnDelete
rollingUpdate:
partition: 5
unavailable: 6
asserts:
- hasDocuments:
count: 3
- isKind:
of: StatefulSet
- equal:
path: spec.updateStrategy
value:
type: OnDelete
- isNull:
path: spec.updateStrategy.rollingUpdate
- it: should pass with strategy changed in StatefulSet
documentIndex: *statefulsetDoc
set:
controller:
type: StatefulSet
strategy: RollingUpdate
rollingUpdate:
partition: 5
unavailable: 6
asserts:
- equal:
path: spec.updateStrategy
value:
type: RollingUpdate
rollingUpdate:
partition: 5
maxUnavailable: 6
- it: should fail with wrong strategy
documentIndex: *statefulsetDoc
set:
controller:
type: StatefulSet
strategy: not_valid_strategy
asserts:
- failedTemplate:
errorMessage: Not a valid strategy type for StatefulSet (not_valid_strategy)

View File

@@ -0,0 +1,116 @@
suite: statefulset default test
templates:
- common.yaml
tests:
- it: should pass with controller set to StatefulSet
documentIndex: &statefulsetDoc 0
set:
controller.type: StatefulSet
asserts:
- hasDocuments:
count: 3
- isKind:
of: StatefulSet
- isAPIVersion:
of: apps/v1
- equal:
path: spec.serviceName
value: RELEASE-NAME-common-test
- equal:
path: spec.revisionHistoryLimit
value: 3
- equal:
path: spec.replicas
value: 1
- 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,125 @@
suite: statefulset vct test
templates:
- common.yaml
tests:
- it: should pass with vct defined in StatefulSet
documentIndex: &statefulsetDoc 0
set:
controller.type: StatefulSet
volumeClaimTemplates:
data:
enabled: true
mountPath: "/bitnami/mariadb"
asserts:
- isKind:
of: StatefulSet
- equal:
path: spec.volumeClaimTemplates[0]
value:
metadata:
name: data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 999Gi
- it: should pass with multiple vct defined in StatefulSet
documentIndex: *statefulsetDoc
set:
controller.type: StatefulSet
volumeClaimTemplates:
data:
enabled: true
mountPath: "/bitnami/mariadb"
other-data:
enabled: true
mountPath: "/bitnami/mariadb"
asserts:
- isKind:
of: StatefulSet
- equal:
path: spec.volumeClaimTemplates[0]
value:
metadata:
name: data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 999Gi
- equal:
path: spec.volumeClaimTemplates[1]
value:
metadata:
name: other-data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 999Gi
- equal:
path: spec.template.spec.containers[0].volumeMounts
value:
- mountPath: /shared
name: shared
- mountPath: /tmp
name: tmp
- mountPath: /var/logs
name: varlogs
- mountPath: /bitnami/mariadb
name: data
- mountPath: /bitnami/mariadb
name: other-data
- it: should pass with vct size changed in StatefulSet
documentIndex: *statefulsetDoc
set:
controller.type: StatefulSet
volumeClaimTemplates:
data:
enabled: true
size: 10Gi
mountPath: "/bitnami/mariadb"
asserts:
- isKind:
of: StatefulSet
- equal:
path: spec.volumeClaimTemplates[0]
value:
metadata:
name: data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
- it: should pass with accessMode changed in StatefulSet
documentIndex: *statefulsetDoc
set:
controller.type: StatefulSet
volumeClaimTemplates:
data:
enabled: true
size: 10Gi
accessMode: ReadWriteMany
mountPath: "/bitnami/mariadb"
asserts:
- isKind:
of: StatefulSet
- equal:
path: spec.volumeClaimTemplates[0]
value:
metadata:
name: data
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 10Gi

View File

@@ -16,7 +16,7 @@
{{- end -}}
{{/* TODO: write tests when statefulset is ready */}}
{{- if eq $root.Values.controller.type "statefulset" -}}
{{- if eq $root.Values.controller.type "StatefulSet" -}}
{{- range $index, $vct := $root.Values.volumeClaimTemplates -}}
{{- include "ix.v1.common.container.volumeMount" (dict "root" $root
"item" $vct

View File

@@ -27,7 +27,7 @@ spec:
serviceName: {{ include "ix.v1.common.names.fullname" . }}
{{- $strategy := default "RollingUpdate" .Values.controller.strategy -}}
{{- if not (mustHas $strategy (list "OnDelete" "RollingUpdate")) -}}
{{- fail (printf "Not a valid strategy type for Deployment (%s)" $strategy) -}}
{{- fail (printf "Not a valid strategy type for StatefulSet (%s)" $strategy) -}}
{{- end }}
updateStrategy:
type: {{ $strategy }}