feat(common): Release version 2.0.0-beta.1 (#173)

This commit is contained in:
Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs 2023-09-13 11:24:23 +02:00 committed by GitHub
parent 19767d668c
commit 7b6ee00be6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
189 changed files with 3110 additions and 3023 deletions

View file

@ -0,0 +1,34 @@
{{- /*
Returns the value for the specified field
*/ -}}
{{- define "bjw-s.common.lib.pod.getOption" -}}
{{- $rootContext := .ctx.rootContext -}}
{{- $controllerObject := .ctx.controllerObject -}}
{{- $option := .option -}}
{{- $value := "" -}}
{{- /* Set to the default if it is set */ -}}
{{- $defaultOption := get $rootContext.Values.defaultPodOptions $option -}}
{{- if kindIs "bool" $defaultOption -}}
{{- $value = $defaultOption -}}
{{- else if not (empty $defaultOption) -}}
{{- $value = $defaultOption -}}
{{- end -}}
{{- /* See if a pod-specific override is needed */ -}}
{{- if hasKey $controllerObject "pod" -}}
{{- $podOption := get $controllerObject.pod $option -}}
{{- if kindIs "bool" $podOption -}}
{{- $value = $podOption -}}
{{- else if not (empty $podOption) -}}
{{- $value = $podOption -}}
{{- end -}}
{{- end -}}
{{- if kindIs "bool" $value -}}
{{- $value | toYaml -}}
{{- else if not (empty $value) -}}
{{- $value | toYaml -}}
{{- end -}}
{{- end -}}

View file

@ -0,0 +1,67 @@
{{- /*
The pod definition included in the controller.
*/ -}}
{{- define "bjw-s.common.lib.pod.spec" -}}
{{- $rootContext := .rootContext -}}
{{- $controllerObject := .controllerObject -}}
{{- $ctx := dict "rootContext" $rootContext "controllerObject" $controllerObject -}}
enableServiceLinks: {{ $controllerObject.pod.enableServiceLinks }}
serviceAccountName: {{ include "bjw-s.common.lib.pod.field.serviceAccountName" (dict "ctx" $ctx) | trim }}
automountServiceAccountToken: {{ $controllerObject.pod.automountServiceAccountToken }}
{{- with ($controllerObject.pod.priorityClassName) }}
priorityClassName: {{ . | trim }}
{{- end -}}
{{- with ($controllerObject.pod.runtimeClassName) }}
runtimeClassName: {{ . | trim }}
{{- end -}}
{{- with ($controllerObject.pod.schedulerName) }}
schedulerName: {{ . | trim }}
{{- end -}}
{{- with ($controllerObject.pod.securityContext) }}
securityContext: {{ . | trim | nindent 2 }}
{{- end -}}
{{- with ($controllerObject.pod.hostname) }}
hostname: {{ . | trim }}
{{- end }}
hostIPC: {{ $controllerObject.pod.hostIPC }}
hostNetwork: {{ $controllerObject.pod.hostNetwork }}
hostPID: {{ $controllerObject.pod.hostPID }}
dnsPolicy: {{ include "bjw-s.common.lib.pod.field.dnsPolicy" (dict "ctx" $ctx) | trim }}
{{- with $controllerObject.pod.dnsConfig }}
dnsConfig: {{ . | trim | nindent 2 }}
{{- end -}}
{{- with $controllerObject.pod.hostAliases }}
hostAliases: {{ . | trim | nindent 2 }}
{{- end -}}
{{- with $controllerObject.pod.imagePullSecrets }}
imagePullSecrets: {{ . | trim | nindent 2 }}
{{- end -}}
{{- with $controllerObject.pod.terminationGracePeriodSeconds }}
terminationGracePeriodSeconds: {{ . | trim }}
{{- end -}}
{{- with $controllerObject.pod.restartPolicy }}
restartPolicy: {{ . | trim }}
{{- end -}}
{{- with $controllerObject.pod.nodeSelector }}
nodeSelector: {{ . | trim | nindent 2 }}
{{- end -}}
{{- with $controllerObject.pod.affinity }}
affinity: {{ . | trim | nindent 2 }}
{{- end -}}
{{- with $controllerObject.pod.topologySpreadConstraints }}
topologySpreadConstraints: {{ . | trim | nindent 2 }}
{{- end -}}
{{- with $controllerObject.pod.tolerations }}
tolerations: {{ . | trim | nindent 2 }}
{{- end }}
{{- with (include "bjw-s.common.lib.pod.field.initContainers" (dict "ctx" $ctx) | trim) }}
initContainers: {{ . | nindent 2 }}
{{- end -}}
{{- with (include "bjw-s.common.lib.pod.field.containers" (dict "ctx" $ctx) | trim) }}
containers: {{ . | nindent 2 }}
{{- end -}}
{{- with (include "bjw-s.common.lib.pod.field.volumes" (dict "ctx" $ctx) | trim) }}
volumes: {{ . | nindent 2 }}
{{- end -}}
{{- end -}}

View file

@ -0,0 +1,28 @@
{{- /*
Returns the value for containers
*/ -}}
{{- define "bjw-s.common.lib.pod.field.containers" -}}
{{- $rootContext := .ctx.rootContext -}}
{{- $controllerObject := .ctx.controllerObject -}}
{{- /* Default to empty list */ -}}
{{- $containers := list -}}
{{- /* Fetch configured containers for this controller */ -}}
{{- $enabledContainers := include "bjw-s.common.lib.controller.enabledContainers" (dict "rootContext" $rootContext "controllerObject" $controllerObject) | fromYaml }}
{{- range $key, $containerValues := $enabledContainers -}}
{{- /* Create object from the container values */ -}}
{{- $containerObject := (include "bjw-s.common.lib.container.valuesToObject" (dict "rootContext" $ "id" $key "values" $containerValues)) | fromYaml -}}
{{- /* Perform validations on the Container before rendering */ -}}
{{- include "bjw-s.common.lib.container.validate" (dict "rootContext" $ "object" $containerObject) -}}
{{- /* Generate the Container spec */ -}}
{{- $renderedContainer := include "bjw-s.common.lib.container.spec" (dict "rootContext" $rootContext "controllerObject" $controllerObject "containerObject" $containerObject) | fromYaml -}}
{{- $containers = append $containers $renderedContainer -}}
{{- end -}}
{{- if not (empty $containers) -}}
{{- $containers | toYaml -}}
{{- end -}}
{{- end -}}

View file

@ -0,0 +1,25 @@
{{- /*
Returns the value for dnsPolicy
*/ -}}
{{- define "bjw-s.common.lib.pod.field.dnsPolicy" -}}
{{- $ctx := .ctx -}}
{{- $controllerObject := $ctx.controllerObject -}}
{{- /* Default to "ClusterFirst" */ -}}
{{- $dnsPolicy := "ClusterFirst" -}}
{{- /* Get hostNetwork value "" */ -}}
{{- $hostNetwork:= get $controllerObject.pod "hostNetwork" -}}
{{- if $hostNetwork -}}
{{- $dnsPolicy = "ClusterFirstWithHostNet" -}}
{{- end -}}
{{- /* See if an override is desired */ -}}
{{- $override := get $controllerObject.pod "dnsPolicy" -}}
{{- if not (empty $override) -}}
{{- $dnsPolicy = $override -}}
{{- end -}}
{{- $dnsPolicy -}}
{{- end -}}

View file

@ -0,0 +1,27 @@
{{- /*
Returns the value for initContainers
*/ -}}
{{- define "bjw-s.common.lib.pod.field.initContainers" -}}
{{- $rootContext := .ctx.rootContext -}}
{{- $controllerObject := .ctx.controllerObject -}}
{{- /* Default to empty list */ -}}
{{- $containers := list -}}
{{- /* Fetch configured containers for this controller */ -}}
{{- range $key, $containerValues := $controllerObject.initContainers -}}
{{- /* Create object from the container values */ -}}
{{- $containerObject := (include "bjw-s.common.lib.container.valuesToObject" (dict "rootContext" $ "id" $key "values" $containerValues)) | fromYaml -}}
{{- /* Perform validations on the Container before rendering */ -}}
{{- include "bjw-s.common.lib.container.validate" (dict "rootContext" $ "object" $containerObject) -}}
{{- /* Generate the Container spec */ -}}
{{- $renderedContainer := include "bjw-s.common.lib.container.spec" (dict "rootContext" $rootContext "containerObject" $containerObject) | fromYaml -}}
{{- $containers = append $containers $renderedContainer -}}
{{- end -}}
{{- if not (empty $containers) -}}
{{- $containers | toYaml -}}
{{- end -}}
{{- end -}}

View file

@ -0,0 +1,18 @@
{{- /*
Returns the value for serviceAccountName
*/ -}}
{{- define "bjw-s.common.lib.pod.field.serviceAccountName" -}}
{{- $rootContext := .ctx.rootContext -}}
{{- /* Default to "default" */ -}}
{{- $name := "default" -}}
{{- /* See if an override is needed */ -}}
{{- if $rootContext.Values.serviceAccount.create -}}
{{- $serviceAccountValues := (mustDeepCopy $rootContext.Values.serviceAccount) -}}
{{- $serviceAccountObject := (include "bjw-s.common.lib.serviceAccount.valuesToObject" (dict "rootContext" $rootContext "id" "default" "values" $serviceAccountValues)) | fromYaml -}}
{{- $name = $serviceAccountObject.name -}}
{{- end -}}
{{- $name -}}
{{- end -}}

View file

@ -0,0 +1,118 @@
{{- /*
Returns the value for volumes
*/ -}}
{{- define "bjw-s.common.lib.pod.field.volumes" -}}
{{- $rootContext := .ctx.rootContext -}}
{{- $controllerObject := .ctx.controllerObject -}}
{{- /* Default to empty list */ -}}
{{- $persistenceItemsToProcess := dict -}}
{{- $volumes := list -}}
{{- /* Loop over persistence values */ -}}
{{- range $identifier, $persistenceValues := $rootContext.Values.persistence -}}
{{- /* Enable persistence item by default, but allow override */ -}}
{{- $persistenceEnabled := true -}}
{{- if hasKey $persistenceValues "enabled" -}}
{{- $persistenceEnabled = $persistenceValues.enabled -}}
{{- end -}}
{{- if $persistenceEnabled -}}
{{- $advancedMounts := dig "advancedMounts" $controllerObject.identifier list $persistenceValues -}}
{{- if $advancedMounts -}}
{{- $_ := set $persistenceItemsToProcess $identifier $persistenceValues -}}
{{- else -}}
{{- $_ := set $persistenceItemsToProcess $identifier $persistenceValues -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- /* Loop over persistence items */ -}}
{{- range $identifier, $persistenceValues := $persistenceItemsToProcess -}}
{{- $volume := dict "name" $identifier -}}
{{- /* PVC persistence type */ -}}
{{- if eq (default "persistentVolumeClaim" $persistenceValues.type) "persistentVolumeClaim" -}}
{{- $pvcName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}}
{{- if $persistenceValues.existingClaim -}}
{{- /* Always prefer an existingClaim if that is set */ -}}
{{- $pvcName = $persistenceValues.existingClaim -}}
{{- else -}}
{{- /* Otherwise refer to the PVC name */ -}}
{{- if $persistenceValues.nameOverride -}}
{{- if not (eq $persistenceValues.nameOverride "-") -}}
{{- $pvcName = (printf "%s-%s" (include "bjw-s.common.lib.chart.names.fullname" $rootContext) $persistenceValues.nameOverride) -}}
{{- end -}}
{{- else -}}
{{- $pvcName = (printf "%s-%s" (include "bjw-s.common.lib.chart.names.fullname" $rootContext) $identifier) -}}
{{- end -}}
{{- end -}}
{{- $_ := set $volume "persistentVolumeClaim" (dict "claimName" $pvcName) -}}
{{- /* configMap persistence type */ -}}
{{- else if eq $persistenceValues.type "configMap" -}}
{{- $objectName := (required (printf "name not set for persistence item %s" $identifier) $persistenceValues.name) -}}
{{- $objectName = tpl $objectName $rootContext -}}
{{- $_ := set $volume "configMap" dict -}}
{{- $_ := set $volume.configMap "name" $objectName -}}
{{- with $persistenceValues.defaultMode -}}
{{- $_ := set $volume.configMap "defaultMode" . -}}
{{- end -}}
{{- with $persistenceValues.items -}}
{{- $_ := set $volume.configMap "items" . -}}
{{- end -}}
{{- /* Secret persistence type */ -}}
{{- else if eq $persistenceValues.type "secret" -}}
{{- $objectName := (required (printf "name not set for persistence item %s" $identifier) $persistenceValues.name) -}}
{{- $objectName = tpl $objectName $rootContext -}}
{{- $_ := set $volume "secret" dict -}}
{{- $_ := set $volume.secret "secretName" $objectName -}}
{{- with $persistenceValues.defaultMode -}}
{{- $_ := set $volume.secret "defaultMode" . -}}
{{- end -}}
{{- with $persistenceValues.items -}}
{{- $_ := set $volume.secret "items" . -}}
{{- end -}}
{{- /* emptyDir persistence type */ -}}
{{- else if eq $persistenceValues.type "emptyDir" -}}
{{- $_ := set $volume "emptyDir" dict -}}
{{- with $persistenceValues.medium -}}
{{- $_ := set $volume.emptyDir "medium" . -}}
{{- end -}}
{{- with $persistenceValues.sizeLimit -}}
{{- $_ := set $volume.emptyDir "sizeLimit" . -}}
{{- end -}}
{{- /* hostPath persistence type */ -}}
{{- else if eq $persistenceValues.type "hostPath" -}}
{{- $_ := set $volume "hostPath" dict -}}
{{- $_ := set $volume.hostPath "path" (required "hostPath not set" $persistenceValues.hostPath) -}}
{{- with $persistenceValues.hostPathType }}
{{- $_ := set $volume.hostPath "type" . -}}
{{- end -}}
{{- /* hostPath persistence type */ -}}
{{- else if eq $persistenceValues.type "nfs" -}}
{{- $_ := set $volume "nfs" dict -}}
{{- $_ := set $volume.nfs "server" (required "server not set" $persistenceValues.server) -}}
{{- $_ := set $volume.nfs "path" (required "path not set" $persistenceValues.path) -}}
{{- /* custom persistence type */ -}}
{{- else if eq $persistenceValues.type "custom" -}}
{{- $volume = $persistenceValues.volumeSpec -}}
{{- $_ := set $volume "name" $identifier -}}
{{- /* Fail otherwise */ -}}
{{- else -}}
{{- fail (printf "Not a valid persistence.type (%s)" $persistenceValues.type) -}}
{{- end -}}
{{- $volumes = append $volumes $volume -}}
{{- end -}}
{{- if not (empty $volumes) -}}
{{- $volumes | toYaml -}}
{{- end -}}
{{- end -}}

View file

@ -0,0 +1,56 @@
{{- /*
Returns the value for annotations
*/ -}}
{{- define "bjw-s.common.lib.pod.metadata.annotations" -}}
{{- $rootContext := .rootContext -}}
{{- $controllerObject := .controllerObject -}}
{{- /* Default annotations */ -}}
{{- $annotations := dict -}}
{{- /* Set to the default if it is set */ -}}
{{- $defaultOption := get $rootContext.Values.defaultPodOptions "annotations" -}}
{{- if not (empty $defaultOption) -}}
{{- $annotations = merge $defaultOption $annotations -}}
{{- end -}}
{{- /* See if a pod-specific override is set */ -}}
{{- if hasKey $controllerObject "pod" -}}
{{- $podOption := get $controllerObject.pod "annotations" -}}
{{- if not (empty $podOption) -}}
{{- $annotations = merge $podOption $annotations -}}
{{- end -}}
{{- end -}}
{{- /* Add configMaps checksum */ -}}
{{- $configMapsFound := dict -}}
{{- range $name, $configmap := $rootContext.Values.configMaps -}}
{{- if $configmap.enabled -}}
{{- $_ := set $configMapsFound $name (toYaml $configmap.data | sha256sum) -}}
{{- end -}}
{{- end -}}
{{- if $configMapsFound -}}
{{- $annotations = merge
(dict "checksum/configMaps" (toYaml $configMapsFound | sha256sum))
$annotations
-}}
{{- end -}}
{{- /* Add Secrets checksum */ -}}
{{- $secretsFound := dict -}}
{{- range $name, $secret := $rootContext.Values.secrets -}}
{{- if $secret.enabled -}}
{{- $_ := set $secretsFound $name (toYaml $secret.stringData | sha256sum) -}}
{{- end -}}
{{- end -}}
{{- if $secretsFound -}}
{{- $annotations = merge
(dict "checksum/secrets" (toYaml $secretsFound | sha256sum))
$annotations
-}}
{{- end -}}
{{- if not (empty $annotations) -}}
{{- $annotations | toYaml -}}
{{- end -}}
{{- end -}}

View file

@ -0,0 +1,36 @@
{{- /*
Returns the value for labels
*/ -}}
{{- define "bjw-s.common.lib.pod.metadata.labels" -}}
{{- $rootContext := .rootContext -}}
{{- $controllerObject := .controllerObject -}}
{{- /* Default labels */ -}}
{{- $labels := merge
(dict "app.kubernetes.io/component" $controllerObject.identifier)
-}}
{{- /* Fetch the Pod selectorLabels */ -}}
{{- $selectorLabels := include "bjw-s.common.lib.metadata.selectorLabels" $rootContext | fromYaml -}}
{{- if not (empty $selectorLabels) -}}
{{- $labels = merge $selectorLabels $labels -}}
{{- end -}}
{{- /* Set to the default if it is set */ -}}
{{- $defaultOption := get $rootContext.Values.defaultPodOptions "labels" -}}
{{- if not (empty $defaultOption) -}}
{{- $labels = merge $defaultOption $labels -}}
{{- end -}}
{{- /* See if a pod-specific override is set */ -}}
{{- if hasKey $controllerObject "pod" -}}
{{- $podOption := get $controllerObject.pod "labels" -}}
{{- if not (empty $podOption) -}}
{{- $labels = merge $podOption $labels -}}
{{- end -}}
{{- end -}}
{{- if not (empty $labels) -}}
{{- $labels | toYaml -}}
{{- end -}}
{{- end -}}