feat: Bump common library to v3.4.0 (#349)

This commit is contained in:
Bernd Schorgers 2024-08-27 14:16:37 +02:00
parent a78c21ab00
commit 86062681a9
No known key found for this signature in database
GPG key ID: BC5E2BD907F9A8EC
45 changed files with 1023 additions and 149 deletions

View file

@ -49,6 +49,9 @@ spec:
loadBalancerSourceRanges:
{{ toYaml $serviceObject.loadBalancerSourceRanges | nindent 4 }}
{{- end -}}
{{- if $serviceObject.loadBalancerClass }}
loadBalancerClass: {{ $serviceObject.loadBalancerClass }}
{{- end -}}
{{- else if eq $svcType "ExternalName" }}
type: {{ $svcType }}
{{- if $serviceObject.externalName }}

View file

@ -3,11 +3,39 @@ Convert container values to an object
*/}}
{{- define "bjw-s.common.lib.container.valuesToObject" -}}
{{- $rootContext := .rootContext -}}
{{- $controllerObject := mustDeepCopy .controllerObject -}}
{{- $containerType := .containerType -}}
{{- $identifier := .id -}}
{{- $objectValues := .values -}}
{{- $objectValues := mustDeepCopy .values -}}
{{- $defaultContainerOptionsStrategy := dig "defaultContainerOptionsStrategy" "overwrite" $controllerObject -}}
{{- $mergeDefaultContainerOptions := true -}}
{{- $_ := set $objectValues "identifier" $identifier -}}
{{- /* Allow disabling default options for initContainers */ -}}
{{- if (eq "init" $containerType) -}}
{{- $applyDefaultContainerOptionsToInitContainers := dig "applyDefaultContainerOptionsToInitContainers" true $controllerObject -}}
{{- if (not (eq $applyDefaultContainerOptionsToInitContainers true)) -}}
{{- $mergeDefaultContainerOptions = false -}}
{{- end -}}
{{- end -}}
{{- /* Merge default container options if required */ -}}
{{- if (eq true $mergeDefaultContainerOptions) -}}
{{- if eq "overwrite" $defaultContainerOptionsStrategy -}}
{{- range $key, $defaultValue := (dig "defaultContainerOptions" dict $controllerObject) }}
{{- $specificValue := dig $key nil $objectValues -}}
{{- if not (empty $specificValue) -}}
{{- $_ := set $objectValues $key $specificValue -}}
{{- else -}}
{{- $_ := set $objectValues $key $defaultValue -}}
{{- end -}}
{{- end -}}
{{- else if eq "merge" $defaultContainerOptionsStrategy -}}
{{- $objectValues = merge $objectValues (dig "defaultContainerOptions" dict $controllerObject) -}}
{{- end -}}
{{- end -}}
{{- /* Process image tags */ -}}
{{- if kindIs "map" $objectValues.image -}}
{{- $imageTag := dig "image" "tag" "" $objectValues -}}

View file

@ -4,19 +4,17 @@ Args used by the container.
{{- define "bjw-s.common.lib.container.field.args" -}}
{{- $ctx := .ctx -}}
{{- $containerObject := $ctx.containerObject -}}
{{- $argValues := get $containerObject "args" -}}
{{- /* Default to empty list */ -}}
{{- $args := list -}}
{{- /* See if an override is desired */ -}}
{{- if not (empty (get $containerObject "args")) -}}
{{- $option := get $containerObject "args" -}}
{{- if not (empty $option) -}}
{{- if kindIs "string" $option -}}
{{- $args = append $args $option -}}
{{- else -}}
{{- $args = $option -}}
{{- end -}}
{{- if not (empty $argValues) -}}
{{- if kindIs "string" $argValues -}}
{{- $args = append $args $argValues -}}
{{- else -}}
{{- $args = $argValues -}}
{{- end -}}
{{- end -}}

View file

@ -4,19 +4,17 @@ Command used by the container.
{{- define "bjw-s.common.lib.container.field.command" -}}
{{- $ctx := .ctx -}}
{{- $containerObject := $ctx.containerObject -}}
{{- $commandValues := get $containerObject "command" -}}
{{- /* Default to empty list */ -}}
{{- $command := list -}}
{{- /* See if an override is desired */ -}}
{{- if not (empty (get $containerObject "command")) -}}
{{- $option := get $containerObject "command" -}}
{{- if not (empty $option) -}}
{{- if kindIs "string" $option -}}
{{- $command = append $command $option -}}
{{- else -}}
{{- $command = $option -}}
{{- end -}}
{{- if not (empty $commandValues) -}}
{{- if kindIs "string" $commandValues -}}
{{- $command = append $command $commandValues -}}
{{- else -}}
{{- $command = $commandValues -}}
{{- end -}}
{{- end -}}

View file

@ -5,25 +5,26 @@ Env field used by the container.
{{- $ctx := .ctx -}}
{{- $rootContext := $ctx.rootContext -}}
{{- $containerObject := $ctx.containerObject -}}
{{- $envValues := get $containerObject "env" -}}
{{- /* Default to empty list */ -}}
{{- $envList := list -}}
{{- /* See if an override is desired */ -}}
{{- if not (empty (get $containerObject "env")) -}}
{{- if kindIs "slice" $containerObject.env -}}
{{- if not (empty $envValues) -}}
{{- if kindIs "slice" $envValues -}}
{{- /* Env is a list so we assume the order is already as desired */ -}}
{{- range $name, $var := $containerObject.env -}}
{{- range $name, $var := $envValues -}}
{{- if kindIs "int" $name -}}
{{- $name = required "environment variables as a list of maps require a name field" $var.name -}}
{{- end -}}
{{- end -}}
{{- $envList = $containerObject.env -}}
{{- $envList = $envValues -}}
{{- else -}}
{{- /* Env is a map so we must check if ordering is desired */ -}}
{{- $graph := dict -}}
{{- range $name, $var := $containerObject.env -}}
{{- range $name, $var := $envValues -}}
{{- if kindIs "map" $var -}}
{{- /* Value is a map so ordering can be specified */ -}}
{{- if empty (dig "dependsOn" nil $var) -}}
@ -44,7 +45,7 @@ Env field used by the container.
{{- range $name := $args.out -}}
{{- $envItem := dict "name" $name -}}
{{- $envValue := get $containerObject.env $name -}}
{{- $envValue := get $envValues $name -}}
{{- if kindIs "map" $envValue -}}
{{- $envItem := merge $envItem (omit $envValue "dependsOn") -}}

View file

@ -1,14 +1,15 @@
{{/*
Env field used by the container.
envFrom field used by the container.
*/}}
{{- define "bjw-s.common.lib.container.field.envFrom" -}}
{{- $ctx := .ctx -}}
{{- $rootContext := $ctx.rootContext -}}
{{- $containerObject := $ctx.containerObject -}}
{{- $envFromValues := get $containerObject "envFrom" -}}
{{- if not (empty (get $containerObject "envFrom")) -}}
{{- if not (empty $envFromValues) -}}
{{- $envFrom := list -}}
{{- range $containerObject.envFrom -}}
{{- range $envFromValues -}}
{{- $item := dict -}}
{{- if hasKey . "configMap" -}}

View file

@ -15,7 +15,7 @@ Returns the value for containers
{{- range $key, $containerValues := $enabledContainers -}}
{{- /* Create object from the container values */ -}}
{{- $containerObject := (include "bjw-s.common.lib.container.valuesToObject" (dict "rootContext" $rootContext "id" $key "values" $containerValues)) | fromYaml -}}
{{- $containerObject := (include "bjw-s.common.lib.container.valuesToObject" (dict "rootContext" $rootContext "controllerObject" $controllerObject "containerType" "default" "id" $key "values" $containerValues)) | fromYaml -}}
{{- /* Perform validations on the Container before rendering */ -}}
{{- include "bjw-s.common.lib.container.validate" (dict "rootContext" $ "controllerObject" $controllerObject "containerObject" $containerObject) -}}

View file

@ -21,7 +21,7 @@ Returns the value for initContainers
{{- if $containerEnabled -}}
{{- /* Create object from the container values */ -}}
{{- $containerObject := (include "bjw-s.common.lib.container.valuesToObject" (dict "rootContext" $rootContext "id" $key "values" $containerValues)) | fromYaml -}}
{{- $containerObject := (include "bjw-s.common.lib.container.valuesToObject" (dict "rootContext" $rootContext "controllerObject" $controllerObject "containerType" "init" "id" $key "values" $containerValues)) | fromYaml -}}
{{- /* Perform validations on the Container before rendering */ -}}
{{- include "bjw-s.common.lib.container.validate" (dict "rootContext" $ "controllerObject" $controllerObject "containerObject" $containerObject) -}}

View file

@ -51,7 +51,9 @@ Returns the value for volumes
{{- $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) -}}
{{- if not (eq $pvcName $identifier) -}}
{{- $pvcName = (printf "%s-%s" (include "bjw-s.common.lib.chart.names.fullname" $rootContext) $identifier) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $_ := set $volume "persistentVolumeClaim" (dict "claimName" $pvcName) -}}

View file

@ -13,6 +13,7 @@ Secondary entrypoint and primary loader for the common chart
{{- include "bjw-s.common.render.ingresses" . | nindent 0 -}}
{{- include "bjw-s.common.render.serviceMonitors" . | nindent 0 -}}
{{- include "bjw-s.common.render.routes" . | nindent 0 -}}
{{- include "bjw-s.common.render.configMaps.fromFiles" . | nindent 0 -}}
{{- include "bjw-s.common.render.configMaps" . | nindent 0 -}}
{{- include "bjw-s.common.render.secrets" . | nindent 0 -}}
{{- include "bjw-s.common.render.networkpolicies" . | nindent 0 -}}

View file

@ -24,3 +24,36 @@ Renders the configMap objects required by the chart.
{{- end -}}
{{- end -}}
{{- end -}}
{{/*
Renders configMap objects required by the chart from a folder in the repo's path.
*/}}
{{- define "bjw-s.common.render.configMaps.fromFiles" -}}
{{- $rootValues := .Values -}}
{{/* Generate a list of unique top level folders */}}
{{ $topLevelFolders := dict}}
{{- range $path, $_ := .Files.Glob (printf "%s/*/*" .Values.configMapsFromFolderBasePath) -}}
{{- $_ := set $topLevelFolders (dir $path) "" -}}
{{- end -}}
{{- $top_level_folder_list := keys $topLevelFolders | sortAlpha -}}
{{/* Iterate over the top level folders */}}
{{ range $path := $top_level_folder_list }}
{{- $filesContentNoFormat := ($.Files.Glob (printf "%s/*" $path)) -}}
{{- $filesContent := dict -}}
{{- range $file_name, $content := $filesContentNoFormat -}}
{{- $key := base $file_name -}}
{{- if contains ".escape" $key -}}
{{- $key := $key | replace ".escape" "" -}}
{{- $filesContent = merge $filesContent (dict $key (($.Files.Get $file_name) | replace "{{" "{{ `{{` }}")) -}}
{{- else -}}
{{- $filesContent = merge $filesContent (dict $key ($.Files.Get $file_name)) -}}
{{- end -}}
{{- end -}}
{{- $configMapValues := dict "enabled" true "labels" dict "annotations" dict "data" $filesContent -}}
{{- $existingConfigMaps := (get $rootValues "configMaps"| default dict) -}}
{{- $mergedConfigMaps := deepCopy $existingConfigMaps | merge (dict (base $path) $configMapValues) -}}
{{- $rootValues := merge $rootValues (dict "configMaps" $mergedConfigMaps) -}}
{{ end }}
{{ end }}