This commit is contained in:
Stavros kois
2023-01-30 12:17:29 +02:00
parent 4dfb034194
commit 2385bf5edc
20 changed files with 266 additions and 16 deletions
@@ -49,7 +49,7 @@ tests:
helm-revision: 0
helm.sh/chart: common-test-1.0.0
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/version: v9.9.9
app.kubernetes.io/version: *appVer
g_label1: global_label1
g_label2: global_label2
label1: label1
@@ -49,7 +49,7 @@ tests:
helm-revision: 0
helm.sh/chart: common-test-1.0.0
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/version: v9.9.9
app.kubernetes.io/version: *appVer
g_label1: global_label1
g_label2: global_label2
label1: label1
@@ -49,7 +49,7 @@ tests:
helm-revision: 0
helm.sh/chart: common-test-1.0.0
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/version: v9.9.9
app.kubernetes.io/version: *appVer
g_label1: global_label1
g_label2: global_label2
label1: label1
@@ -52,7 +52,7 @@ tests:
helm-revision: 0
helm.sh/chart: common-test-1.0.0
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/version: v9.9.9
app.kubernetes.io/version: *appVer
g_label1: global_label1
g_label2: global_label2
label1: label1
@@ -0,0 +1,56 @@
suite: job metadata test
templates:
- common.yaml
chart:
appVersion: &appVer v9.9.9
tests:
- it: should pass with job 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: Job
labels:
label1: "{{ .Values.label1 }}"
label2: label2
annotations:
annotation1: "{{ .Values.annotation1 }}"
annotation2: annotation2
asserts:
- documentIndex: &jobDoc 0
isKind:
of: Job
- documentIndex: *jobDoc
equal:
path: metadata.annotations
value:
annotation1: annotation1
annotation2: annotation2
g_annotation1: global_annotation1
g_annotation2: global_annotation2
- documentIndex: *jobDoc
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: *appVer
g_label1: global_label1
g_label2: global_label2
label1: label1
label2: label2
@@ -0,0 +1,52 @@
suite: job spec test
templates:
- common.yaml
tests:
- it: should pass with controller enabled
set:
controllers:
controller-name:
enabled: true
primary: true
type: Job
asserts:
- documentIndex: &jobDoc 0
isKind:
of: Job
- documentIndex: *jobDoc
isAPIVersion:
of: batch/v1
- documentIndex: *jobDoc
isSubset:
path: spec
content:
backoffLimit: 5
completionMode: NonIndexed
completions:
parallelism: 1
ttlSecondsAfterFinished: 120
- it: should apply spec correctly
set:
controllers:
controller-name:
enabled: true
primary: true
type: Job
backoffLimit: 5
completionMode: Indexed
completions: 5
parallelism: 5
ttlSecondsAfterFinished: 100
activeDeadlineSeconds: 100
asserts:
- documentIndex: *jobDoc
isSubset:
path: spec
content:
backoffLimit: 5
completionMode: Indexed
completions: 5
parallelism: 5
ttlSecondsAfterFinished: 100
activeDeadlineSeconds: 100
@@ -0,0 +1,42 @@
suite: job validation test
templates:
- common.yaml
tests:
- it: should fail with invalid completionMode
set:
controllers:
controller-name:
enabled: true
primary: true
type: Job
completionMode: not-a-mode
asserts:
- failedTemplate:
errorMessage: Job - Expected <completionMode> to be one of [Indexed, NonIndexed], but got [not-a-mode]
- it: should fail with completionMode to Indexed and no completions
set:
controllers:
controller-name:
enabled: true
primary: true
type: Job
completionMode: Indexed
completions:
asserts:
- failedTemplate:
errorMessage: Job - Expected <completions> to be set when <completionMode> is set to [Indexed]
- it: should fail with completionMode to Indexed and no parallelism
set:
controllers:
controller-name:
enabled: true
primary: true
type: Job
completionMode: Indexed
completions: 5
parallelism:
asserts:
- failedTemplate:
errorMessage: Job - Expected <parallelism> to be set when <completionMode> is set to [Indexed]
@@ -49,7 +49,7 @@ tests:
helm-revision: 0
helm.sh/chart: common-test-1.0.0
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/version: v9.9.9
app.kubernetes.io/version: *appVer
g_label1: global_label1
g_label2: global_label2
label1: label1
@@ -49,7 +49,7 @@ tests:
helm-revision: 0
helm.sh/chart: common-test-1.0.0
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/version: v9.9.9
app.kubernetes.io/version: *appVer
g_label1: global_label1
g_label2: global_label2
label1: label1
@@ -4,9 +4,9 @@
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.
name: The name of the daemonset.
labels: The labels of the daemonset.
annotations: The annotations of the daemonset.
replicas: The number of replicas.
revisionHistoryLimit: The number of old ReplicaSets to retain to allow rollback.
strategy: The deployment strategy.
@@ -4,9 +4,9 @@
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.
name: The name of the deployment.
labels: The labels of the deployment.
annotations: The annotations of the deployment.
replicas: The number of replicas.
revisionHistoryLimit: The number of old ReplicaSets to retain to allow rollback.
strategy: The deployment strategy.
@@ -0,0 +1,38 @@
{{/* Job Class */}}
{{/* Call this template:
{{ include "ix.v1.common.class.job" (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 job.
labels: The labels of the job.
annotations: The annotations of the job.
replicas: The number of replicas.
revisionHistoryLimit: The number of old ReplicaSets to retain to allow rollback.
strategy: The job strategy.
*/}}
{{- define "ix.v1.common.class.job" -}}
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData -}}
{{- include "ix.v1.common.lib.controller.jobValidation" (dict "objectData" $objectData) }}
---
apiVersion: batch/v1
kind: Job
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.jobSpec" (dict "rootCtx" $rootCtx "objectData" $objectData) | nindent 2 }}
{{- end -}}
@@ -4,9 +4,9 @@
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.
name: The name of the statefulset.
labels: The labels of the statefulset.
annotations: The annotations of the statefulset.
replicas: The number of replicas.
revisionHistoryLimit: The number of old ReplicaSets to retain to allow rollback.
strategy: The deployment strategy.
@@ -0,0 +1,24 @@
{{/* Job Spec */}}
{{/* Call this template:
{{ include "ix.v1.common.lib.controller.jobSpec" (dict "objectData" $objectData "rootCtx" $rootCtx) -}}
rootCtx: The root context of the template. It is used to access the global context.
objectData:
backoffLimit: The number of retries before marking this job failed. Defaults to 6.
completions: The desired number of successfully finished pods the job should be run with. Defaults to 1.
parallelism: The maximum desired number of pods the job should run at any given time. Defaults to 1.
activeDeadlineSeconds: Specifies the duration in seconds relative to the startTime that the job may be active before the system tries to terminate it; value must be positive integer. If set to nil, the job is never terminated due to timeout.
ttlSecondsAfterFinished: TTLSecondsAfterFinished limits the lifetime of a Job that has finished execution (either Complete or Failed). If this field is set, ttlSecondsAfterFinished after the Job finishes, it is eligible to be automatically deleted. When the Job is being deleted, its lifecycle guarantees (e.g. finalizers) will be honored. If this field is unset, the Job won't be automatically deleted. If this field is set to zero, the Job becomes eligible to be deleted immediately after it finishes. This field is alpha-level and is only honored by servers that enable the TTLAfterFinished feature.
completionMode: CompletionMode specifies how Pod completions are tracked. It can be `NonIndexed` (default) or `Indexed`.
*/}}
{{- define "ix.v1.common.lib.controller.jobSpec" -}}
{{- $objectData := .objectData -}}
{{- $rootCtx := .rootCtx -}}
backoffLimit: {{ $objectData.backoffLimit | default 5 }}
completionMode: {{ $objectData.completionMode | default "NonIndexed" }}
completions: {{ $objectData.completions }}{{/* Can be nil too */}}
parallelism: {{ $objectData.parallelism | default 1 }}
ttlSecondsAfterFinished: {{ $objectData.ttlSecondsAfterFinished | default 120 }}
{{- with $objectData.activeDeadlineSeconds }}
activeDeadlineSeconds: {{ . }}
{{- end -}}
{{- end -}}
@@ -27,3 +27,4 @@ objectData:
{{- end -}}
{{- end -}}
{{/* TODO: Extend validation for sub-values of rollingUpdate */}}
@@ -27,3 +27,4 @@ objectData:
{{- end -}}
{{- end -}}
{{/* TODO: Extend validation for sub-values of rollingUpdate */}}
@@ -0,0 +1,33 @@
{{/* Deployment Validation */}}
{{/* Call this template:
{{ include "ix.v1.common.lib.controller.jobValidation" (dict "objectData" $objectData) -}}
rootCtx: The root context of the template. It is used to access the global context.
objectData:
completionMode: The completionMode of the object.
completions: The completions of the object.
parallelism: The parallelism of the object.
*/}}
{{- define "ix.v1.common.lib.controller.jobValidation" -}}
{{- $objectData := .objectData -}}
{{- if $objectData.completionMode -}}
{{- $completionMode := $objectData.completionMode -}}
{{- if not (mustHas $completionMode (list "Indexed" "NonIndexed")) -}}
{{- fail (printf "Job - Expected <completionMode> to be one of [Indexed, NonIndexed], but got [%v]" $completionMode) -}}
{{- end -}}
{{- if eq $completionMode "Indexed" -}}
{{- if not $objectData.completions -}}
{{- fail "Job - Expected <completions> to be set when <completionMode> is set to [Indexed]" -}}
{{- end -}}
{{- if not $objectData.parallelism -}}
{{- fail "Job - Expected <parallelism> to be set when <completionMode> is set to [Indexed]" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{/* TODO: Extend validation for other values of job */}}
@@ -27,3 +27,4 @@ objectData:
{{- end -}}
{{- end -}}
{{/* TODO: Extend validation for sub-values of rollingUpdate */}}
@@ -36,7 +36,9 @@
{{- else if eq $objectData.type "DaemonSet" -}}
{{- include "ix.v1.common.class.daemonset" (dict "objectData" $objectData "rootCtx" $) -}}
{{- else if eq $objectData.type "Job" -}}
{{- include "ix.v1.common.class.job" (dict "objectData" $objectData "rootCtx" $) -}}
{{- else if eq $objectData.type "CronJob" -}}
{{- include "ix.v1.common.class.cronJob" (dict "objectData" $objectData "rootCtx" $) -}}
{{- end -}}
{{- end -}}
+1 -1
View File
@@ -375,7 +375,7 @@ controllers:
# -- Primary controller
primary: true
# -- Controller type
type: Deployment
type: Job
# -- Controller labels
labels: {}
# -- Controller annotations