new way of doin
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
root
2023-11-16 19:42:02 +10:00
parent 77ec717184
commit 1eaf295724
341 changed files with 19416 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
{{/* CronJob Spec */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.workload.cronjobSpec" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
rootCtx: The root context of the chart.
objectData:
schedule: The schedule in Cron format, see https://en.wikipedia.org/wiki/Cron.
concurrencyPolicy: Allow, Forbid, or Replace. Defaults to Allow.
failedJobsHistoryLimit: The number of failed finished jobs to retain. Defaults to 1.
successfulJobsHistoryLimit: The number of successful finished jobs to retain. Defaults to 3.
startingDeadlineSeconds: Optional deadline in seconds for starting the job if it misses scheduled time for any reason. Defaults to nil.
timezone: The timezone name. Defaults to .Values.TZ
+jobSpec data
*/}}
{{- define "tc.v1.common.lib.workload.cronjobSpec" -}}
{{- $objectData := .objectData -}}
{{- $rootCtx := .rootCtx -}}
{{- $suspend := $objectData.suspend | default false -}}
{{- if (include "tc.v1.common.lib.util.stopAll" $rootCtx) -}}
{{- $suspend = true -}}
{{- end }}
timeZone: {{ (tpl ($objectData.timezone | default $rootCtx.Values.TZ) $rootCtx) | quote }}
schedule: {{ (tpl $objectData.schedule $rootCtx) | quote }}
concurrencyPolicy: {{ $objectData.concurrencyPolicy | default "Forbid" }}
failedJobsHistoryLimit: {{ $objectData.failedJobsHistoryLimit | default 1 }}
successfulJobsHistoryLimit: {{ $objectData.successfulJobsHistoryLimit | default 3 }}
startingDeadlineSeconds: {{ $objectData.startingDeadlineSeconds | default 600 }}
suspend: {{ $suspend }}
jobTemplate:
spec:
{{- include "tc.v1.common.lib.workload.jobSpec" (dict "rootCtx" $rootCtx "objectData" $objectData) | indent 4 }}
{{- end -}}

View File

@@ -0,0 +1,27 @@
{{/* DaemonSet Spec */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.workload.daemonsetSpec" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
rootCtx: The root context of the chart.
objectData:
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 "tc.v1.common.lib.workload.daemonsetSpec" -}}
{{- $objectData := .objectData -}}
{{- $rootCtx := .rootCtx -}}
{{- $strategy := $objectData.strategy | default "RollingUpdate" }}
revisionHistoryLimit: {{ $objectData.revisionHistoryLimit | default 3 }}
updateStrategy:
type: {{ $strategy }}
{{- if and (eq $objectData.strategy "RollingUpdate") $objectData.rollingUpdate -}}
{{ if (or (hasKey $objectData.rollingUpdate "maxUnavailable") (hasKey $objectData.rollingUpdate "maxSurge")) }}
rollingUpdate:
{{- if hasKey $objectData.rollingUpdate "maxUnavailable" }}
maxUnavailable: {{ $objectData.rollingUpdate.maxUnavailable }}
{{- end -}}
{{- if hasKey $objectData.rollingUpdate "maxSurge" }}
maxSurge: {{ $objectData.rollingUpdate.maxSurge }}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}

View File

@@ -0,0 +1,36 @@
{{/* Deployment Spec */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.workload.deploymentSpec" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
rootCtx: The root context of the chart.
objectData:
replicas: The number of replicas.
revisionHistoryLimit: The number of old ReplicaSets to retain to allow rollback.
strategy: The deployment strategy to use to replace existing pods with new ones.
*/}}
{{- define "tc.v1.common.lib.workload.deploymentSpec" -}}
{{- $objectData := .objectData -}}
{{- $rootCtx := .rootCtx -}}
{{- $strategy := $objectData.strategy | default "Recreate" -}}
{{- $replicas := 1 -}}
{{- if hasKey $objectData "replicas" -}}
{{- $replicas = $objectData.replicas -}}
{{- end -}}
{{- if (include "tc.v1.common.lib.util.stopAll" $rootCtx) -}}
{{- $replicas = 0 -}}
{{- end }}
replicas: {{ $replicas }}
revisionHistoryLimit: {{ $objectData.revisionHistoryLimit | default 3 }}
strategy:
type: {{ $strategy }}
{{- if and (eq $objectData.strategy "RollingUpdate") $objectData.rollingUpdate -}}
{{ if (or (hasKey $objectData.rollingUpdate "maxUnavailable") (hasKey $objectData.rollingUpdate "maxSurge")) }}
rollingUpdate:
{{- if hasKey $objectData.rollingUpdate "maxUnavailable" }}
maxUnavailable: {{ $objectData.rollingUpdate.maxUnavailable }}
{{- end -}}
{{- if hasKey $objectData.rollingUpdate "maxSurge" }}
maxSurge: {{ $objectData.rollingUpdate.maxSurge }}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}

View File

@@ -0,0 +1,31 @@
{{/* Job Spec */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.workload.jobSpec" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
rootCtx: The root context of the chart.
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 "tc.v1.common.lib.workload.jobSpec" -}}
{{- $objectData := .objectData -}}
{{- $rootCtx := .rootCtx -}}
{{- $parallelism := 1 -}}
{{- if hasKey $objectData "parallelism" -}}
{{- $parallelism = $objectData.parallelism -}}
{{- end -}}
{{- if (include "tc.v1.common.lib.util.stopAll" $rootCtx) -}}
{{- $parallelism = 0 -}}
{{- end }}
backoffLimit: {{ $objectData.backoffLimit | default 5 }}
completionMode: {{ $objectData.completionMode | default "NonIndexed" }}
completions: {{ $objectData.completions | default nil }}
parallelism: {{ $parallelism }}
ttlSecondsAfterFinished: {{ $objectData.ttlSecondsAfterFinished | default 120 }}
{{- with $objectData.activeDeadlineSeconds }}
activeDeadlineSeconds: {{ . }}
{{- end -}}
{{- end -}}

View File

@@ -0,0 +1,65 @@
{{/* Pod Spec */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.workload.pod" (dict "rootCtx" $ "objectData" $objectData) }}
rootCtx: The root context of the chart.
objectData: The object data to be used to render the Pod.
*/}}
{{- define "tc.v1.common.lib.workload.pod" -}}
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData }}
serviceAccountName: {{ include "tc.v1.common.lib.pod.serviceAccountName" (dict "rootCtx" $rootCtx "objectData" $objectData) }}
automountServiceAccountToken: {{ include "tc.v1.common.lib.pod.automountServiceAccountToken" (dict "rootCtx" $rootCtx "objectData" $objectData) }}
runtimeClassName: {{ include "tc.v1.common.lib.pod.runtimeClassName" (dict "rootCtx" $rootCtx "objectData" $objectData) }}
{{- with (include "tc.v1.common.lib.pod.imagePullSecret" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim) }}
imagePullSecrets:
{{- . | nindent 2 }}
{{- end }}
hostNetwork: {{ include "tc.v1.common.lib.pod.hostNetwork" (dict "rootCtx" $rootCtx "objectData" $objectData) }}
hostPID: {{ include "tc.v1.common.lib.pod.hostPID" (dict "rootCtx" $rootCtx "objectData" $objectData) }}
shareProcessNamespace: {{ include "tc.v1.common.lib.pod.shareProcessNamespace" (dict "rootCtx" $rootCtx "objectData" $objectData) }}
enableServiceLinks: {{ include "tc.v1.common.lib.pod.enableServiceLinks" (dict "rootCtx" $rootCtx "objectData" $objectData) }}
restartPolicy: {{ include "tc.v1.common.lib.pod.restartPolicy" (dict "rootCtx" $rootCtx "objectData" $objectData) }}
{{- with (include "tc.v1.common.lib.pod.schedulerName" (dict "rootCtx" $rootCtx "objectData" $objectData)) }}
schedulerName: {{ . }}
{{- end -}}
{{- with (include "tc.v1.common.lib.pod.priorityClassName" (dict "rootCtx" $rootCtx "objectData" $objectData)) }}
priorityClassName: {{ . }}
{{- end -}}
{{- with (include "tc.v1.common.lib.pod.nodeSelector" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim) }}
nodeSelector:
{{- . | nindent 2 }}
{{- end -}}
{{- with (include "tc.v1.common.lib.pod.topologySpreadConstraints" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim) }}
topologySpreadConstraints:
{{- . | nindent 2 }}
{{- end -}}
{{- with (include "tc.v1.common.lib.pod.hostAliases" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim) }}
hostAliases:
{{- . | nindent 2 }}
{{- end -}}
{{- with (include "tc.v1.common.lib.pod.hostname" (dict "rootCtx" $rootCtx "objectData" $objectData)) }}
hostname: {{ . }}
{{- end -}}
{{- include "tc.v1.common.lib.pod.dns" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
{{- with (include "tc.v1.common.lib.pod.terminationGracePeriodSeconds" (dict "rootCtx" $rootCtx "objectData" $objectData)) }}
terminationGracePeriodSeconds: {{ . }}
{{- end -}}
{{- with (include "tc.v1.common.lib.pod.tolerations" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim) }}
tolerations:
{{- . | nindent 2 }}
{{- end }}
securityContext:
{{- include "tc.v1.common.lib.pod.securityContext" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 2 }}
{{- if $objectData.podSpec.containers }}
containers:
{{- include "tc.v1.common.lib.pod.containerSpawner" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 2 -}}
{{- end -}}
{{- if $objectData.podSpec.initContainers }}
initContainers:
{{- include "tc.v1.common.lib.pod.initContainerSpawner" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 2 -}}
{{- end -}}
{{- with (include "tc.v1.common.lib.pod.volumes" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim) }}
volumes:
{{- . | nindent 2 }}
{{- end -}}
{{- end -}}

View File

@@ -0,0 +1,37 @@
{{/* StatefulSet Spec */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.workload.statefulsetSpec" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
rootCtx: The root context of the chart.
objectData:
replicas: The number of replicas.
revisionHistoryLimit: The number of old ReplicaSets to retain to allow rollback.
strategy: The statefulset strategy to use to replace existing pods with new ones.
*/}}
{{- define "tc.v1.common.lib.workload.statefulsetSpec" -}}
{{- $objectData := .objectData -}}
{{- $rootCtx := .rootCtx -}}
{{- $strategy := $objectData.strategy | default "RollingUpdate" -}}
{{- $replicas := 1 -}}
{{- if hasKey $objectData "replicas" -}}
{{- $replicas = $objectData.replicas -}}
{{- end -}}
{{- if (include "tc.v1.common.lib.util.stopAll" $rootCtx) -}}
{{- $replicas = 0 -}}
{{- end }}
replicas: {{ $replicas }}
revisionHistoryLimit: {{ $objectData.revisionHistoryLimit | default 3 }}
serviceName: {{ $objectData.name }}
updateStrategy:
type: {{ $strategy }}
{{- if and (eq $objectData.strategy "RollingUpdate") $objectData.rollingUpdate -}}
{{- if (or (hasKey $objectData.rollingUpdate "maxUnavailable") (hasKey $objectData.rollingUpdate "partition")) }}
rollingUpdate:
{{- if hasKey $objectData.rollingUpdate "maxUnavailable" }}
maxUnavailable: {{ $objectData.rollingUpdate.maxUnavailable }}
{{- end -}}
{{- if hasKey $objectData.rollingUpdate "partition" }}
partition: {{ $objectData.rollingUpdate.partition }}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}

View File

@@ -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 -}}

View File

@@ -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 -}}

View File

@@ -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 -}}

View File

@@ -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 -}}

View File

@@ -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 -}}

View File

@@ -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 -}}