This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
{{/* CronJob Validation */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.workload.cronjobValidation" (dict "objectData" $objectData) -}}
|
||||
rootCtx: The root context of the chart.
|
||||
objectData:
|
||||
completionMode: The completionMode of the object.
|
||||
completions: The completions of the object.
|
||||
parallelism: The parallelism of the object.
|
||||
*/}}
|
||||
{{- define "tc.v1.common.lib.workload.cronjobValidation" -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- if $objectData.concurrencyPolicy -}}
|
||||
{{- $concurrencyPolicy := $objectData.concurrencyPolicy -}}
|
||||
|
||||
{{- $policies := (list "Allow" "Forbid" "Replace") -}}
|
||||
{{- if not (mustHas $concurrencyPolicy $policies) -}}
|
||||
{{- fail (printf "CronJob - Expected <concurrencyPolicy> to be one of [%s], but got [%v]" (join ", " $policies) $concurrencyPolicy) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
|
||||
{{- if not $objectData.schedule -}}
|
||||
{{- fail "CronJob - Expected non-empty <schedule>" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* CronJob contains a job inside, so we validate job values too */}}
|
||||
{{- include "tc.v1.common.lib.workload.jobValidation" (dict "objectData" $objectData) -}}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,30 @@
|
||||
{{/* DaemonSet Validation */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.workload.daemonsetValidation" (dict "objectData" $objectData) -}}
|
||||
rootCtx: The root context of the chart.
|
||||
objectData:
|
||||
strategy: The strategy of the object.
|
||||
rollingUpdate: The rollingUpdate of the object.
|
||||
*/}}
|
||||
{{- define "tc.v1.common.lib.workload.daemonsetValidation" -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- if $objectData.strategy -}}
|
||||
{{- $strategy := $objectData.strategy -}}
|
||||
|
||||
{{- $strategies := (list "OnDelete" "RollingUpdate") -}}
|
||||
{{- if not (mustHas $strategy $strategies) -}}
|
||||
{{- fail (printf "DaemonSet - Expected <strategy> to be one of [%s], but got [%v]" (join ", " $strategies) $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 -}}
|
||||
@@ -0,0 +1,30 @@
|
||||
{{/* Deployment Validation */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.workload.deploymentValidation" (dict "objectData" $objectData) -}}
|
||||
rootCtx: The root context of the chart.
|
||||
objectData:
|
||||
strategy: The strategy of the object.
|
||||
rollingUpdate: The rollingUpdate of the object.
|
||||
*/}}
|
||||
{{- define "tc.v1.common.lib.workload.deploymentValidation" -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- if $objectData.strategy -}}
|
||||
{{- $strategy := $objectData.strategy -}}
|
||||
|
||||
{{- $strategies := (list "Recreate" "RollingUpdate") -}}
|
||||
{{- if not (mustHas $strategy $strategies) -}}
|
||||
{{- fail (printf "Deployment - Expected <strategy> to be one of [%s], but got [%v]" (join ", " $strategies) $strategy) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
|
||||
{{- if $objectData.rollingUpdate -}}
|
||||
{{- $rollUp := $objectData.rollingUpdate -}}
|
||||
|
||||
{{- if and $rollUp (not (kindIs "map" $rollUp)) -}}
|
||||
{{- fail (printf "Deployment - Expected <rollingUpdate> to be a dictionary, but got [%v]" (kindOf $rollUp)) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,32 @@
|
||||
{{/* Job Validation */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.workload.jobValidation" (dict "objectData" $objectData) -}}
|
||||
rootCtx: The root context of the chart.
|
||||
objectData:
|
||||
completionMode: The completionMode of the object.
|
||||
completions: The completions of the object.
|
||||
parallelism: The parallelism of the object.
|
||||
*/}}
|
||||
{{- define "tc.v1.common.lib.workload.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 -}}
|
||||
@@ -0,0 +1,30 @@
|
||||
{{/* StatefulSet Validation */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.workload.statefulsetValidation" (dict "objectData" $objectData) -}}
|
||||
rootCtx: The root context of the chart.
|
||||
objectData:
|
||||
strategy: The strategy of the object.
|
||||
rollingUpdate: The rollingUpdate of the object.
|
||||
*/}}
|
||||
{{- define "tc.v1.common.lib.workload.statefulsetValidation" -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- if $objectData.strategy -}}
|
||||
{{- $strategy := $objectData.strategy -}}
|
||||
|
||||
{{- $strategies := (list "OnDelete" "RollingUpdate") -}}
|
||||
{{- if not (mustHas $strategy $strategies) -}}
|
||||
{{- fail (printf "StatefulSet - Expected <strategy> to be one of [%s], but got [%v]" (join ", " $strategies) $strategy) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
|
||||
{{- if $objectData.rollingUpdate -}}
|
||||
{{- $rollUp := $objectData.rollingUpdate -}}
|
||||
|
||||
{{- if and $rollUp (not (kindIs "map" $rollUp)) -}}
|
||||
{{- fail (printf "StatefulSet - Expected <rollingUpdate> to be a dictionary, but got [%v]" (kindOf $rollUp)) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,43 @@
|
||||
{{/* Workload Basic Validation */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.workload.primaryValidation" $ -}}
|
||||
*/}}
|
||||
{{- define "tc.v1.common.lib.workload.primaryValidation" -}}
|
||||
|
||||
{{/* Initialize values */}}
|
||||
{{- $hasPrimary := false -}}
|
||||
{{- $hasEnabled := false -}}
|
||||
|
||||
{{/* Go over workload */}}
|
||||
{{- range $name, $workload := .Values.workload -}}
|
||||
|
||||
{{/* If workload is enabled */}}
|
||||
{{- if $workload.enabled -}}
|
||||
|
||||
{{- $types := (list "Deployment" "StatefulSet" "DaemonSet" "Job" "CronJob") -}}
|
||||
{{- if not (mustHas $workload.type $types) -}}
|
||||
{{- fail (printf "Workload - Expected <type> to be one of [%s], but got [%s]" (join ", " $types) $workload.type) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $hasEnabled = true -}}
|
||||
|
||||
{{/* And workload is primary */}}
|
||||
{{- if $workload.primary -}}
|
||||
{{/* Fail if there is already a primary workload */}}
|
||||
{{- if $hasPrimary -}}
|
||||
{{- fail "Workload - Only one workload can be primary" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $hasPrimary = true -}}
|
||||
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
|
||||
{{/* Require at one primary workload, if any enabled */}}
|
||||
{{- if and $hasEnabled (not $hasPrimary) -}}
|
||||
{{- fail "Workload - One enabled workload must be primary" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
Reference in New Issue
Block a user