feat(common): Release v2.5.0 (#258)

Co-authored-by: Maurits <75321636+maurits-funda@users.noreply.github.com>
Co-authored-by: Noam Lerner <bugok@users.noreply.github.com>
This commit is contained in:
Bernd Schorgers 2024-01-16 21:28:41 +01:00 committed by GitHub
parent 1582fe27c4
commit a548690b00
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 670 additions and 56 deletions

View file

@ -32,6 +32,9 @@ metadata:
annotations: {{- toYaml . | nindent 4 -}}
{{- end }}
spec:
{{- with $cronjobObject.cronjob.suspend }}
suspend: {{ ternary "true" "false" . }}
{{- end }}
concurrencyPolicy: "{{ $cronjobObject.cronjob.concurrencyPolicy }}"
startingDeadlineSeconds: {{ $cronjobObject.cronjob.startingDeadlineSeconds }}
{{- with $timeZone }}

View file

@ -0,0 +1,46 @@
{{/*
This template serves as the blueprint for the job objects that are created
within the common library.
*/}}
{{- define "bjw-s.common.class.job" -}}
{{- $rootContext := .rootContext -}}
{{- $jobObject := .object -}}
{{- $labels := merge
(dict "app.kubernetes.io/component" $jobObject.identifier)
($jobObject.labels | default dict)
(include "bjw-s.common.lib.metadata.allLabels" $rootContext | fromYaml)
-}}
{{- $annotations := merge
($jobObject.annotations | default dict)
(include "bjw-s.common.lib.metadata.globalAnnotations" $rootContext | fromYaml)
-}}
---
apiVersion: batch/v1
kind: Job
metadata:
name: {{ $jobObject.name }}
{{- with $labels }}
labels: {{- toYaml . | nindent 4 -}}
{{- end }}
{{- with $annotations }}
annotations: {{- toYaml . | nindent 4 -}}
{{- end }}
spec:
{{- with $jobObject.job.suspend }}
suspend: {{ ternary "true" "false" . }}
{{- end }}
{{- with $jobObject.job.ttlSecondsAfterFinished }}
ttlSecondsAfterFinished: {{ . }}
{{- end }}
backoffLimit: {{ $jobObject.job.backoffLimit }}
template:
metadata:
{{- with (include "bjw-s.common.lib.pod.metadata.annotations" (dict "rootContext" $rootContext "controllerObject" $jobObject)) }}
annotations: {{ . | nindent 8 }}
{{- end -}}
{{- with (include "bjw-s.common.lib.pod.metadata.labels" (dict "rootContext" $rootContext "controllerObject" $jobObject)) }}
labels: {{ . | nindent 8 }}
{{- end }}
spec: {{ include "bjw-s.common.lib.pod.spec" (dict "rootContext" $rootContext "controllerObject" $jobObject) | nindent 6 }}
{{- end -}}

View file

@ -30,4 +30,8 @@ spec:
{{- include "bjw-s.common.lib.metadata.selectorLabels" $rootContext | nindent 6 }}
{{- end }}
endpoints: {{- toYaml $serviceMonitorObject.endpoints | nindent 4 }}
{{- if not (empty $serviceMonitorObject.targetLabels )}}
targetLabels:
{{- toYaml $serviceMonitorObject.targetLabels | nindent 4 }}
{{- end }}
{{- end }}

View file

@ -0,0 +1,12 @@
{{/*
Return a configMap Object by its Identifier.
*/}}
{{- define "bjw-s.common.lib.configMap.getByIdentifier" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $configMapValues := dig $identifier nil $rootContext.Values.configMaps -}}
{{- if not (empty $configMapValues) -}}
{{- include "bjw-s.common.lib.configMap.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $configMapValues) -}}
{{- end -}}
{{- end -}}

View file

@ -36,8 +36,8 @@ terminationMessagePolicy: {{ . | trim }}
{{- with (include "bjw-s.common.lib.container.field.env" (dict "ctx" $ctx) | trim) }}
env: {{ . | trim | nindent 2 }}
{{- end -}}
{{- with $containerObject.envFrom }}
envFrom: {{ toYaml . | trim | nindent 2 }}
{{- with (include "bjw-s.common.lib.container.field.envFrom" (dict "ctx" $ctx) | trim) }}
envFrom: {{ . | trim | nindent 2 }}
{{- end -}}
{{- with $containerObject.ports }}
ports: {{ toYaml . | trim | nindent 2 }}

View file

@ -0,0 +1,58 @@
{{/*
Env field used by the container.
*/}}
{{- define "bjw-s.common.lib.container.field.envFrom" -}}
{{- $ctx := .ctx -}}
{{- $rootContext := $ctx.rootContext -}}
{{- $containerObject := $ctx.containerObject -}}
{{- if not (empty (get $containerObject "envFrom")) -}}
{{- $envFrom := list -}}
{{- range $containerObject.envFrom -}}
{{- $item := dict -}}
{{- if hasKey . "configMap" -}}
{{- $configMap := include "bjw-s.common.lib.configMap.getByIdentifier" (dict "rootContext" $rootContext "id" .configMap) | fromYaml -}}
{{- $configMapName := default (tpl .configMap $rootContext) $configMap.name -}}
{{- $_ := set $item "configMapRef" (dict "name" $configMapName) -}}
{{- else if hasKey . "configMapRef" -}}
{{- if not (empty (dig "identifier" nil .configMapRef)) -}}
{{- $configMap := include "bjw-s.common.lib.configMap.getByIdentifier" (dict "rootContext" $rootContext "id" .configMapRef.identifier) | fromYaml -}}
{{- if empty $configMap -}}
{{- fail (printf "No configMap configured with identifier '%s'" .configMapRef.identifier) -}}
{{- end -}}
{{- $_ := set $item "configMapRef" (dict "name" $configMap.name) -}}
{{- else -}}
{{- $_ := set $item "configMapRef" (dict "name" (tpl .configMapRef.name $rootContext)) -}}
{{- end -}}
{{- else if hasKey . "secret" -}}
{{- $secret := include "bjw-s.common.lib.secret.getByIdentifier" (dict "rootContext" $rootContext "id" .secret) | fromYaml -}}
{{- $secretName := default (tpl .secret $rootContext) $secret.name -}}
{{- $_ := set $item "secretRef" (dict "name" $secretName) -}}
{{- else if hasKey . "secretRef" -}}
{{- if not (empty (dig "identifier" nil .secretRef)) -}}
{{- $secret := include "bjw-s.common.lib.secret.getByIdentifier" (dict "rootContext" $rootContext "id" .secretRef.identifier) | fromYaml -}}
{{- if empty $secret -}}
{{- fail (printf "No secret configured with identifier '%s'" .secretRef.identifier) -}}
{{- end -}}
{{- $_ := set $item "secretRef" (dict "name" $secret.name) -}}
{{- else -}}
{{- $_ := set $item "secretRef" (dict "name" (tpl .secretRef.name $rootContext)) -}}
{{- end -}}
{{- end -}}
{{- if not (empty (dig "prefix" nil .)) -}}
{{- $_ := set $item "prefix" .prefix -}}
{{- end -}}
{{- if not (empty $item) -}}
{{- $envFrom = append $envFrom $item -}}
{{- end -}}
{{- end -}}
{{- $envFrom | toYaml -}}
{{- end -}}
{{- end -}}

View file

@ -91,6 +91,12 @@ volumeMounts used by the container.
{{- $_ := set $volumeMount "readOnly" $readOnly -}}
{{- end -}}
{{- /* Use the specified mountPropagation setting if provided */ -}}
{{- with .mountPropagation -}}
{{- $mountPropagation := . -}}
{{- $_ := set $volumeMount "mountPropagation" $mountPropagation -}}
{{- end -}}
{{- $enabledVolumeMounts = append $enabledVolumeMounts $volumeMount -}}
{{- end -}}

View file

@ -5,7 +5,7 @@ Validate controller values
{{- $rootContext := .rootContext -}}
{{- $controllerValues := .object -}}
{{- $allowedControllerTypes := list "deployment" "daemonset" "statefulset" "cronjob" -}}
{{- $allowedControllerTypes := list "deployment" "daemonset" "statefulset" "cronjob" "job" -}}
{{- if not (has $controllerValues.type $allowedControllerTypes) -}}
{{- fail (printf "Not a valid controller.type (%s)" $controllerValues.type) -}}
{{- end -}}

View file

@ -0,0 +1,12 @@
{{/*
Validate job values
*/}}
{{- define "bjw-s.common.lib.job.validate" -}}
{{- $rootContext := .rootContext -}}
{{- $jobValues := .object -}}
{{- $allowedRestartPolicy := list "Never" "OnFailure" -}}
{{- if not (has $jobValues.pod.restartPolicy $allowedRestartPolicy) -}}
{{- fail (printf "Not a valid restart policy for Job (controller: %s, strategy: %s)" $jobValues.identifier $jobValues.pod.restartPolicy) -}}
{{- end -}}
{{- end -}}

View file

@ -0,0 +1,14 @@
{{/*
Convert job values to an object
*/}}
{{- define "bjw-s.common.lib.job.valuesToObject" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $objectValues := .values -}}
{{- $restartPolicy := default "Never" $objectValues.pod.restartPolicy -}}
{{- $_ := set $objectValues.pod "restartPolicy" $restartPolicy -}}
{{- /* Return the Job object */ -}}
{{- $objectValues | toYaml -}}
{{- end -}}

View file

@ -0,0 +1,12 @@
{{/*
Return a secret Object by its Identifier.
*/}}
{{- define "bjw-s.common.lib.secret.getByIdentifier" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $secretValues := dig $identifier nil $rootContext.Values.secrets -}}
{{- if not (empty $secretValues) -}}
{{- include "bjw-s.common.lib.secret.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $secretValues) -}}
{{- end -}}
{{- end -}}

View file

@ -35,6 +35,10 @@ Renders the controller objects required by the chart.
{{- $statefulsetObject := (include "bjw-s.common.lib.statefulset.valuesToObject" (dict "rootContext" $ "id" $key "values" $controllerObject)) | fromYaml -}}
{{- include "bjw-s.common.lib.statefulset.validate" (dict "rootContext" $ "object" $statefulsetObject) -}}
{{- include "bjw-s.common.class.statefulset" (dict "rootContext" $ "object" $statefulsetObject) | nindent 0 -}}
{{- else if eq $controllerObject.type "job" -}}
{{- $jobObject := (include "bjw-s.common.lib.job.valuesToObject" (dict "rootContext" $ "id" $key "values" $controllerObject)) | fromYaml -}}
{{- include "bjw-s.common.lib.job.validate" (dict "rootContext" $ "object" $jobObject) -}}
{{- include "bjw-s.common.class.job" (dict "rootContext" $ "object" $jobObject) | nindent 0 -}}
{{- end -}}
{{- end -}}
{{- end -}}

View file

@ -4,7 +4,13 @@ Renders the Persistent Volume Claim objects required by the chart.
{{- define "bjw-s.common.render.pvcs" -}}
{{- /* Generate pvc as required */ -}}
{{- range $key, $pvc := .Values.persistence -}}
{{- if and $pvc.enabled (eq (default "persistentVolumeClaim" $pvc.type) "persistentVolumeClaim") (not $pvc.existingClaim) -}}
{{- /* Enable PVC by default, but allow override */ -}}
{{- $pvcEnabled := true -}}
{{- if hasKey $pvc "enabled" -}}
{{- $pvcEnabled = $pvc.enabled -}}
{{- end -}}
{{- if and $pvcEnabled (eq (default "persistentVolumeClaim" $pvc.type) "persistentVolumeClaim") (not $pvc.existingClaim) -}}
{{- $pvcValues := (mustDeepCopy $pvc) -}}
{{- /* Create object from the raw PVC values */ -}}