daemonset basic spec

This commit is contained in:
Stavros kois
2023-01-30 11:19:48 +02:00
parent b0e37a59ef
commit 921db8ad01
10 changed files with 238 additions and 13 deletions
@@ -1,8 +1,8 @@
suite: deployment name test
suite: controller name test
templates:
- common.yaml
tests:
- it: should generate correct name
- it: should generate correct controller name
set:
controllers:
controller-name:
@@ -12,7 +12,7 @@ tests:
other-controller-name:
enabled: true
primary: false
type: Deployment
type: DaemonSet
asserts:
- documentIndex: &deploymentDoc 0
isKind:
@@ -24,13 +24,13 @@ tests:
equal:
path: metadata.name
value: release-name-common-test
- documentIndex: &deploymentDoc 1
- documentIndex: &daemonSetDoc 1
isKind:
of: Deployment
- documentIndex: *deploymentDoc
of: DaemonSet
- documentIndex: *daemonSetDoc
isAPIVersion:
of: apps/v1
- documentIndex: *deploymentDoc
- documentIndex: *daemonSetDoc
equal:
path: metadata.name
value: release-name-common-test-other-controller-name
@@ -0,0 +1,56 @@
suite: daemonset metadata test
templates:
- common.yaml
chart:
appVersion: &appVer v9.9.9
tests:
- it: should pass with daemonset created with labels and annotations
set:
label1: label1
label2: global_label2
annotation1: annotation1
annotation2: global_annotation2
global:
labels:
g_label1: global_label1
g_label2: "{{ .Values.label2 }}"
annotations:
g_annotation1: global_annotation1
g_annotation2: "{{ .Values.annotation2 }}"
controllers:
controller-name:
enabled: true
primary: true
type: DaemonSet
labels:
label1: "{{ .Values.label1 }}"
label2: label2
annotations:
annotation1: "{{ .Values.annotation1 }}"
annotation2: annotation2
asserts:
- documentIndex: &daemonSetDoc 0
isKind:
of: DaemonSet
- documentIndex: *daemonSetDoc
equal:
path: metadata.annotations
value:
annotation1: annotation1
annotation2: annotation2
g_annotation1: global_annotation1
g_annotation2: global_annotation2
- documentIndex: *daemonSetDoc
equal:
path: metadata.labels
value:
app: common-test-1.0.0
release: release-name
helm-revision: 0
helm.sh/chart: common-test-1.0.0
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/version: v9.9.9
g_label1: global_label1
g_label2: global_label2
label1: label1
label2: label2
@@ -0,0 +1,49 @@
suite: daemonset spec test
templates:
- common.yaml
tests:
- it: should pass with controller enabled
set:
controllers:
controller-name:
enabled: true
primary: true
type: DaemonSet
asserts:
- documentIndex: &daemonSetDoc 0
isKind:
of: DaemonSet
- documentIndex: *daemonSetDoc
isAPIVersion:
of: apps/v1
- documentIndex: *daemonSetDoc
isSubset:
path: spec
content:
revisionHistoryLimit: 3
updateStrategy:
type: RollingUpdate
- it: should apply spec correctly
set:
controllers:
controller-name:
enabled: true
primary: true
type: DaemonSet
revisionHistoryLimit: 4
strategy: RollingUpdate
rollingUpdate:
maxSurge: 5
maxUnavailable: 5
asserts:
- documentIndex: *daemonSetDoc
isSubset:
path: spec
content:
revisionHistoryLimit: 4
updateStrategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 5
maxUnavailable: 5
@@ -0,0 +1,28 @@
suite: daemonset validation test
templates:
- common.yaml
tests:
- it: should fail with invalid strategy
set:
controllers:
controller-name:
enabled: true
primary: true
type: DaemonSet
strategy: not-a-strategy
asserts:
- failedTemplate:
errorMessage: DaemonSet - Expected <strategy> to be one of [OnDelete, RollingUpdate], but got [not-a-strategy]
- it: should fail with rollingUpdate not a dict
set:
controllers:
controller-name:
enabled: true
primary: true
type: DaemonSet
strategy: RollingUpdate
rollingUpdate: "not a dict"
asserts:
- failedTemplate:
errorMessage: DaemonSet - Expected <rollingUpdate> to be a dictionary, but got [string]
@@ -5,7 +5,6 @@ chart:
appVersion: &appVer v9.9.9
tests:
- it: should pass with deployment created with labels and annotations
set:
label1: label1
label2: global_label2
@@ -0,0 +1,38 @@
{{/* DaemonSet Class */}}
{{/* Call this template:
{{ include "ix.v1.common.class.deployment" (dict "objectData" $objectData "rootCtx" $) }}
rootCtx: The root context of the template. It is used to access the global context.
objectData:
name: The name of the configmap.
labels: The labels of the configmap.
annotations: The annotations of the configmap.
replicas: The number of replicas.
revisionHistoryLimit: The number of old ReplicaSets to retain to allow rollback.
strategy: The deployment strategy.
*/}}
{{- define "ix.v1.common.class.daemonset" -}}
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData -}}
{{- include "ix.v1.common.lib.controller.daemonsetValidation" (dict "objectData" $objectData) }}
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: {{ $objectData.name }}
{{- $labels := (mustMerge ($objectData.labels | default dict) (include "ix.v1.common.lib.metadata.allLabels" $rootCtx | fromYaml)) -}}
{{- with (include "ix.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "labels" $labels) | trim) }}
labels:
{{- . | nindent 4 }}
{{- end -}}
{{- $annotations := (mustMerge ($objectData.annotations | default dict) (include "ix.v1.common.lib.metadata.allAnnotations" $rootCtx | fromYaml)) -}}
{{- with (include "ix.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "annotations" $annotations) | trim) }}
annotations:
{{- . | nindent 4 }}
{{- end }}
spec:
{{- include "ix.v1.common.lib.controller.daemonsetSpec" (dict "rootCtx" $rootCtx "objectData" $objectData) | nindent 2 }}
{{- end -}}
@@ -16,7 +16,7 @@ objectData:
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData -}}
{{- include "ix.v1.common.lib.controller.deploymentValidation" (dict "objectData" $objectData "rootCtx" $rootCtx) }}
{{- include "ix.v1.common.lib.controller.deploymentValidation" (dict "objectData" $objectData) }}
---
apiVersion: apps/v1
kind: Deployment
@@ -0,0 +1,25 @@
{{/* DaemonSet Spec */}}
{{/* Call this template:
{{ include "ix.v1.common.lib.controller.daemonsetSpec" (dict "objectData" $objectData "rootCtx" $rootCtx) -}}
rootCtx: The root context of the template. It is used to access the global context.
objectData:
replicas: The number of replicas.
revisionHistoryLimit: The number of old ReplicaSets to retain to allow rollback.
strategy: The daemonset strategy to use to replace existing pods with new ones.
*/}}
{{- define "ix.v1.common.lib.controller.daemonsetSpec" -}}
{{- $objectData := .objectData -}}
{{- $rootCtx := .rootCtx -}}
revisionHistoryLimit: {{ $objectData.revisionHistoryLimit | default 3 }}
updateStrategy:
type: {{ $objectData.strategy | default "RollingUpdate" }}
{{- if and (eq $objectData.strategy "RollingUpdate") $objectData.rollingUpdate }}
rollingUpdate:
{{- with $objectData.rollingUpdate.maxUnavailable }}
maxUnavailable: {{ .}}
{{- end -}}
{{- with $objectData.rollingUpdate.maxSurge }}
maxSurge: {{ . }}
{{- end -}}
{{- end -}}
{{- end -}}
@@ -64,15 +64,14 @@ objectData:
{{/* Deployment Validation */}}
{{/* Call this template:
{{ include "ix.v1.common.lib.controller.basicValidation" (dict "objectData" $objectData) -}}
{{ include "ix.v1.common.lib.controller.deploymentValidation" (dict "objectData" $objectData) -}}
rootCtx: The root context of the template. It is used to access the global context.
objectData:
labels: The labels of the object.
annotations: The annotations of the object.
strategy: The strategy of the object.
rollingUpdate: The rollingUpdate of the object.
*/}}
{{- define "ix.v1.common.lib.controller.deploymentValidation" -}}
{{- $objectData := .objectData -}}
{{- $rootCtx := .rootCtx -}}
{{- if $objectData.strategy -}}
{{- $strategy := $objectData.strategy -}}
@@ -92,3 +91,33 @@ objectData:
{{- end -}}
{{- end -}}
{{/* DaemonSet Validation */}}
{{/* Call this template:
{{ include "ix.v1.common.lib.controller.daemonsetValidation" (dict "objectData" $objectData) -}}
rootCtx: The root context of the template. It is used to access the global context.
objectData:
strategy: The strategy of the object.
rollingUpdate: The rollingUpdate of the object.
*/}}
{{- define "ix.v1.common.lib.controller.daemonsetValidation" -}}
{{- $objectData := .objectData -}}
{{- if $objectData.strategy -}}
{{- $strategy := $objectData.strategy -}}
{{- if not (mustHas $strategy (list "OnDelete" "RollingUpdate")) -}}
{{- fail (printf "DaemonSet - Expected <strategy> to be one of [OnDelete, RollingUpdate], but got [%v]" $strategy) -}}
{{- end -}}
{{- end -}}
{{- if $objectData.rollingUpdate -}}
{{- $rollUp := $objectData.rollingUpdate -}}
{{- if and $rollUp (not (kindIs "map" $rollUp)) -}}
{{- fail (printf "DaemonSet - Expected <rollingUpdate> to be a dictionary, but got [%v]" (kindOf $rollUp)) -}}
{{- end -}}
{{- end -}}
{{- end -}}
@@ -33,6 +33,7 @@
{{- include "ix.v1.common.class.deployment" (dict "objectData" $objectData "rootCtx" $) -}}
{{- else if eq $objectData.type "StatefulSet" -}}
{{- else if eq $objectData.type "DaemonSet" -}}
{{- include "ix.v1.common.class.daemonset" (dict "objectData" $objectData "rootCtx" $) -}}
{{- else if eq $objectData.type "Job" -}}
{{- else if eq $objectData.type "CronJob" -}}
{{- end -}}