feat(common): Release v2.2.0 (#223)

This commit is contained in:
Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs 2023-11-10 21:31:03 +01:00 committed by GitHub
parent 8b21e9f6c7
commit 8bfc33eb8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 244 additions and 47 deletions

View file

@ -0,0 +1,17 @@
{{/*
Returns the items in a map that have a certain key
*/}}
{{- define "bjw-s.common.lib.getMapItemsWithKey" -}}
{{- $map := .map -}}
{{- $keyToFind := .key -}}
{{- $output := dict -}}
{{- if not (empty $keyToFind) -}}
{{- range $key, $item := $map -}}
{{- if not (empty (dig $keyToFind nil $item)) -}}
{{- $_ := set $output $key $item -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $output | toYaml -}}
{{- end }}

View file

@ -6,11 +6,17 @@ Returns the value for containers
{{- $controllerObject := .ctx.controllerObject -}}
{{- /* Default to empty list */ -}}
{{- $orderedContainers := dict -}}
{{- $graph := dict -}}
{{- $containers := list -}}
{{- /* Fetch configured containers for this controller */ -}}
{{- $enabledContainers := include "bjw-s.common.lib.controller.enabledContainers" (dict "rootContext" $rootContext "controllerObject" $controllerObject) | fromYaml }}
{{- $renderedContainers := dict -}}
{{- /* TODO: Remove this logic after "order" removal in v3 */ -}}
{{- $containersWithDependsOn := include "bjw-s.common.lib.getMapItemsWithKey" (dict "map" $enabledContainers "key" "dependsOn") | fromYaml | keys -}}
{{- $useDependsOn := gt (len $containersWithDependsOn) 0 -}}
{{- 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 -}}
@ -20,13 +26,43 @@ Returns the value for containers
{{- /* Generate the Container spec */ -}}
{{- $renderedContainer := include "bjw-s.common.lib.container.spec" (dict "rootContext" $rootContext "controllerObject" $controllerObject "containerObject" $containerObject) | fromYaml -}}
{{- $_ := set $renderedContainers $key $renderedContainer -}}
{{- $containerOrder := (dig "order" 99 $containerValues) -}}
{{- $_ := set $orderedContainers (printf "%v-%s" $containerOrder $key) $renderedContainer -}}
{{- /* Determine the Container order */ -}}
{{- if $useDependsOn -}}
{{- if empty (dig "dependsOn" nil $containerValues) -}}
{{- $_ := set $graph $key ( list ) -}}
{{- else if kindIs "string" $containerValues.dependsOn -}}
{{- $_ := set $graph $key ( list $containerValues.dependsOn ) -}}
{{- else if kindIs "slice" $containerValues.dependsOn -}}
{{- $_ := set $graph $key $containerValues.dependsOn -}}
{{- end -}}
{{- else -}}
{{- /* TODO: Remove this logic after "order" removal in v3 */ -}}
{{- $containerOrder := (dig "order" 99 $containerValues) -}}
{{- $_ := set $graph $key $containerOrder -}}
{{- end -}}
{{- end -}}
{{- range $key, $containerValues := $orderedContainers -}}
{{- $containers = append $containers $containerValues -}}
{{- /* Process graph */ -}}
{{- if $useDependsOn -}}
{{- $args := dict "graph" $graph "out" list -}}
{{- include "bjw-s.common.lib.kahn" $args -}}
{{- range $name := $args.out -}}
{{- $containerItem := get $renderedContainers $name -}}
{{- $containers = append $containers $containerItem -}}
{{- end -}}
{{- else -}}
{{- /* TODO: Remove this logic after "order" removal in v3 */ -}}
{{- $orderedContainers := dict -}}
{{- range $key, $order := $graph -}}
{{- $containerItem := get $renderedContainers $key -}}
{{- $_ := set $orderedContainers (printf "%v-%s" $order $key) $containerItem -}}
{{- end -}}
{{- range $key, $containerValues := $orderedContainers -}}
{{- $containers = append $containers $containerValues -}}
{{- end -}}
{{- end -}}
{{- if not (empty $containers) -}}

View file

@ -6,10 +6,16 @@ Returns the value for initContainers
{{- $controllerObject := .ctx.controllerObject -}}
{{- /* Default to empty list */ -}}
{{- $orderedContainers := dict -}}
{{- $graph := dict -}}
{{- $containers := list -}}
{{- /* Fetch configured containers for this controller */ -}}
{{- $renderedContainers := dict -}}
{{- /* TODO: Remove this logic after "order" removal in v3 */ -}}
{{- $containersWithDependsOn := include "bjw-s.common.lib.getMapItemsWithKey" (dict "map" $controllerObject.initContainers "key" "dependsOn") | fromYaml | keys -}}
{{- $useDependsOn := gt (len $containersWithDependsOn) 0 -}}
{{- range $key, $containerValues := $controllerObject.initContainers -}}
{{- /* Enable container by default, but allow override */ -}}
{{- $containerEnabled := true -}}
@ -26,14 +32,44 @@ Returns the value for initContainers
{{- /* Generate the Container spec */ -}}
{{- $renderedContainer := include "bjw-s.common.lib.container.spec" (dict "rootContext" $rootContext "controllerObject" $controllerObject "containerObject" $containerObject) | fromYaml -}}
{{- $_ := set $renderedContainers $key $renderedContainer -}}
{{- $containerOrder := (dig "order" 99 $containerValues) -}}
{{- $_ := set $orderedContainers (printf "%v-%s" $containerOrder $key) $renderedContainer -}}
{{- /* Determine the Container order */ -}}
{{- if $useDependsOn -}}
{{- if empty (dig "dependsOn" nil $containerValues) -}}
{{- $_ := set $graph $key ( list ) -}}
{{- else if kindIs "string" $containerValues.dependsOn -}}
{{- $_ := set $graph $key ( list $containerValues.dependsOn ) -}}
{{- else if kindIs "slice" $containerValues.dependsOn -}}
{{- $_ := set $graph $key $containerValues.dependsOn -}}
{{- end -}}
{{- else -}}
{{- /* TODO: Remove this logic after "order" removal in v3 */ -}}
{{- $containerOrder := (dig "order" 99 $containerValues) -}}
{{- $_ := set $graph $key $containerOrder -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- range $key, $containerValues := $orderedContainers -}}
{{- $containers = append $containers $containerValues -}}
{{- /* Process graph */ -}}
{{- if $useDependsOn -}}
{{- $args := dict "graph" $graph "out" list -}}
{{- include "bjw-s.common.lib.kahn" $args -}}
{{- range $name := $args.out -}}
{{- $containerItem := get $renderedContainers $name -}}
{{- $containers = append $containers $containerItem -}}
{{- end -}}
{{- else -}}
{{- /* TODO: Remove this logic after "order" removal in v3 */ -}}
{{- $orderedContainers := dict -}}
{{- range $key, $order := $graph -}}
{{- $containerItem := get $renderedContainers $key -}}
{{- $_ := set $orderedContainers (printf "%v-%s" $order $key) $containerItem -}}
{{- end -}}
{{- range $key, $containerValues := $orderedContainers -}}
{{- $containers = append $containers $containerValues -}}
{{- end -}}
{{- end -}}
{{- if not (empty $containers) -}}