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

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