mirror of
https://github.com/bjw-s-labs/helm-charts.git
synced 2025-07-04 00:47:04 +02:00
feat(common): Release v2.1.0 (#221)
Co-authored-by: Christopher Larivière <lariviere.c@gmail.com>
This commit is contained in:
parent
272dbef383
commit
b360c9885a
18 changed files with 288 additions and 44 deletions
|
@ -6,6 +6,11 @@ using the common library.
|
|||
{{- $rootContext := .rootContext -}}
|
||||
{{- $cronjobObject := .object -}}
|
||||
|
||||
{{- $timeZone := "" -}}
|
||||
{{- if ge (int $rootContext.Capabilities.KubeVersion.Minor) 27 }}
|
||||
{{- $timeZone = dig "cronjob" "timeZone" "" $cronjobObject -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $labels := merge
|
||||
(dict "app.kubernetes.io/component" $cronjobObject.identifier)
|
||||
($cronjobObject.labels | default dict)
|
||||
|
@ -29,6 +34,9 @@ metadata:
|
|||
spec:
|
||||
concurrencyPolicy: "{{ $cronjobObject.cronjob.concurrencyPolicy }}"
|
||||
startingDeadlineSeconds: {{ $cronjobObject.cronjob.startingDeadlineSeconds }}
|
||||
{{- with $timeZone }}
|
||||
timeZone: "{{ . }}"
|
||||
{{- end }}
|
||||
schedule: "{{ $cronjobObject.cronjob.schedule }}"
|
||||
successfulJobsHistoryLimit: {{ $cronjobObject.cronjob.successfulJobsHistory }}
|
||||
failedJobsHistoryLimit: {{ $cronjobObject.cronjob.failedJobsHistory }}
|
||||
|
|
|
@ -43,6 +43,9 @@ spec:
|
|||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- if $ingressObject.defaultBackend }}
|
||||
defaultBackend: {{ $ingressObject.defaultBackend }}
|
||||
{{- else }}
|
||||
rules:
|
||||
{{- range $ingressObject.hosts }}
|
||||
- host: {{ tpl .host $rootContext | quote }}
|
||||
|
@ -56,7 +59,7 @@ spec:
|
|||
{{ $service := include "bjw-s.common.lib.service.getByIdentifier" (dict "rootContext" $rootContext "id" .service.name) | fromYaml -}}
|
||||
{{ $servicePort := 0 -}}
|
||||
|
||||
{{ if eq (dig "port" nil .service) nil -}}
|
||||
{{ if empty (dig "port" nil .service) -}}
|
||||
{{/* Default to the Service primary port if no port has been specified */ -}}
|
||||
{{ if $service -}}
|
||||
{{ $defaultServicePort := include "bjw-s.common.lib.service.primaryPort" (dict "rootContext" $rootContext "serviceObject" $service) | fromYaml -}}
|
||||
|
@ -78,4 +81,5 @@ spec:
|
|||
number: {{ $servicePort }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
|
|
@ -11,6 +11,9 @@ within the common library.
|
|||
{{- if $rootContext.Capabilities.APIVersions.Has (printf "gateway.networking.k8s.io/v1beta1/%s" $routeKind) }}
|
||||
{{- $apiVersion = "gateway.networking.k8s.io/v1beta1" -}}
|
||||
{{- end -}}
|
||||
{{- if $rootContext.Capabilities.APIVersions.Has (printf "gateway.networking.k8s.io/v1/%s" $routeKind) }}
|
||||
{{- $apiVersion = "gateway.networking.k8s.io/v1" -}}
|
||||
{{- end -}}
|
||||
{{- $labels := merge
|
||||
($routeObject.labels | default dict)
|
||||
(include "bjw-s.common.lib.metadata.allLabels" $rootContext | fromYaml)
|
||||
|
@ -46,9 +49,9 @@ spec:
|
|||
{{- end }}
|
||||
{{- if and (ne $routeKind "TCPRoute") (ne $routeKind "UDPRoute") $routeObject.hostnames }}
|
||||
hostnames:
|
||||
{{- with $routeObject.hostnames }}
|
||||
{{- toYaml . | nindent 4 }}
|
||||
{{- end }}
|
||||
{{- range $routeObject.hostnames }}
|
||||
- {{ tpl . $rootContext | quote }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
rules:
|
||||
{{- range $routeObject.rules }}
|
||||
|
|
35
charts/library/common/templates/lib/chart/_kahn.tpl
Normal file
35
charts/library/common/templates/lib/chart/_kahn.tpl
Normal file
|
@ -0,0 +1,35 @@
|
|||
{{/*
|
||||
Implementation of Kahn's algorithm based on
|
||||
https://en.wikipedia.org/wiki/Topological_sorting#Kahn's_algorithm
|
||||
|
||||
source: https://github.com/dastrobu/helm-charts/blob/main/environment-variables/templates/_kahn.tpl
|
||||
*/}}
|
||||
{{- define "bjw-s.common.lib.kahn" -}}
|
||||
{{- $graph := .graph -}}
|
||||
{{- if empty $graph -}}
|
||||
{{- $_ := set . "out" list -}}
|
||||
{{- else -}}
|
||||
{{- $S := list -}}
|
||||
|
||||
{{- range $node, $edges := $graph -}}
|
||||
{{- if empty $edges -}}
|
||||
{{- $S = append $S $node -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if empty $S -}}
|
||||
{{- fail (printf "graph is cyclic or has bad edge definitions. Remaining graph is:\n%s" ( .graph | toYaml ) ) }}
|
||||
{{- end -}}
|
||||
|
||||
{{- $n := first $S -}}
|
||||
{{- $_ := unset $graph $n -}}
|
||||
|
||||
{{- range $node, $edges := $graph -}}
|
||||
{{- $_ := set $graph $node ( without $edges $n ) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $args := dict "graph" $graph "out" list -}}
|
||||
{{- include "bjw-s.common.lib.kahn" $args -}}
|
||||
{{- $_ = set . "out" ( concat ( list $n ) $args.out ) -}}
|
||||
{{- end -}}
|
||||
{{- end }}
|
|
@ -10,11 +10,11 @@ Validate container values
|
|||
{{- fail (printf "Image required to be a dictionary with repository and tag fields. (controller %s, container %s)" $controllerObject.identifier $containerObject.identifier) }}
|
||||
{{- end -}}
|
||||
|
||||
{{- if eq (dig "image" "repository" "" $containerObject) "" -}}
|
||||
{{- if empty (dig "image" "repository" nil $containerObject) -}}
|
||||
{{- fail (printf "No image repository specified for container. (controller %s, container %s)" $controllerObject.identifier $containerObject.identifier) }}
|
||||
{{- end -}}
|
||||
|
||||
{{- if eq (dig "image" "tag" "" $containerObject) "" -}}
|
||||
{{- if empty (dig "image" "tag" nil $containerObject) -}}
|
||||
{{- fail (printf "No image tag specified for container. (controller %s, container %s)" $controllerObject.identifier $containerObject.identifier) }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
|
|
@ -7,39 +7,77 @@ Env field used by the container.
|
|||
{{- $containerObject := $ctx.containerObject -}}
|
||||
|
||||
{{- /* Default to empty list */ -}}
|
||||
{{- $env := list -}}
|
||||
{{- $envList := list -}}
|
||||
|
||||
{{- /* See if an override is desired */ -}}
|
||||
{{- if not (empty (get $containerObject "env")) -}}
|
||||
{{- with $containerObject.env -}}
|
||||
{{- range $name, $value := . -}}
|
||||
{{- if kindIs "slice" $containerObject.env -}}
|
||||
{{- /* Env is a list so we assume the order is already as desired */ -}}
|
||||
{{- range $name, $var := $containerObject.env -}}
|
||||
{{- if kindIs "int" $name -}}
|
||||
{{- $name = required "environment variables as a list of maps require a name field" $value.name -}}
|
||||
{{- $name = required "environment variables as a list of maps require a name field" $var.name -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- $envList = $containerObject.env -}}
|
||||
{{- else -}}
|
||||
{{- /* Env is a map so we must check if ordering is desired */ -}}
|
||||
{{- $graph := dict -}}
|
||||
|
||||
{{- if kindIs "map" $value -}}
|
||||
{{- if hasKey $value "value" -}}
|
||||
{{- $envValue := $value.value | toString -}}
|
||||
{{- $env = append $env (dict "name" $name "value" (tpl $envValue $rootContext)) -}}
|
||||
{{- else if hasKey $value "valueFrom" -}}
|
||||
{{- $env = append $env (dict "name" $name "valueFrom" $value.valueFrom) -}}
|
||||
{{- range $name, $var := $containerObject.env -}}
|
||||
{{- if $var -}}
|
||||
{{- if kindIs "map" $var -}}
|
||||
{{- /* Value is a map so ordering can be specified */ -}}
|
||||
{{- if empty (dig "dependsOn" nil $var) -}}
|
||||
{{- $_ := set $graph $name ( list ) -}}
|
||||
{{- else if kindIs "string" $var.dependsOn -}}
|
||||
{{- $_ := set $graph $name ( list $var.dependsOn ) -}}
|
||||
{{- else if kindIs "slice" $var.dependsOn -}}
|
||||
{{- $_ := set $graph $name $var.dependsOn -}}
|
||||
{{- end -}}
|
||||
{{- else -}}
|
||||
{{- $env = append $env (dict "name" $name "valueFrom" $value) -}}
|
||||
{{- end -}}
|
||||
{{- else -}}
|
||||
{{- if kindIs "string" $value -}}
|
||||
{{- $env = append $env (dict "name" $name "value" (tpl $value $rootContext)) -}}
|
||||
{{- else if or (kindIs "float64" $value) (kindIs "bool" $value) -}}
|
||||
{{- $env = append $env (dict "name" $name "value" ($value | toString)) -}}
|
||||
{{- else -}}
|
||||
{{- $env = append $env (dict "name" $name "value" $value) -}}
|
||||
{{- /* Value is not a map so no ordering can be specified */ -}}
|
||||
{{- $_ := set $graph $name ( list ) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $args := dict "graph" $graph "out" list -}}
|
||||
{{- include "bjw-s.common.lib.kahn" $args -}}
|
||||
|
||||
{{- range $name := $args.out -}}
|
||||
{{- $envItem := dict "name" $name -}}
|
||||
{{- $envValue := get $containerObject.env $name -}}
|
||||
|
||||
{{- if kindIs "map" $envValue -}}
|
||||
{{- $envItem := merge $envItem (omit $envValue "dependsOn") -}}
|
||||
{{- else -}}
|
||||
{{- $_ := set $envItem "value" $envValue -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $envList = append $envList $envItem -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $args = dict -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if not (empty $env) -}}
|
||||
{{- $env | toYaml -}}
|
||||
{{- if not (empty $envList) -}}
|
||||
{{- $output := list -}}
|
||||
{{- range $envList -}}
|
||||
{{- if hasKey . "value" -}}
|
||||
{{- if kindIs "string" .value -}}
|
||||
{{- $output = append $output (dict "name" .name "value" (tpl .value $rootContext)) -}}
|
||||
{{- else if or (kindIs "float64" .value) (kindIs "bool" .value) -}}
|
||||
{{- $output = append $output (dict "name" .name "value" (.value | toString)) -}}
|
||||
{{- else -}}
|
||||
{{- $output = append $output (dict "name" .name "value" .value) -}}
|
||||
{{- end -}}
|
||||
{{- else if hasKey . "valueFrom" -}}
|
||||
{{- $output = append $output (dict "name" .name "valueFrom" .valueFrom) -}}
|
||||
{{- else -}}
|
||||
{{- $output = append $output (dict "name" .name "valueFrom" (omit . "name")) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- $output | toYaml -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
|
|
@ -58,7 +58,11 @@ Probes used by the container.
|
|||
{{- end -}}
|
||||
|
||||
{{- if $probeValues.port -}}
|
||||
{{- $_ := set (index $probeDefinition $probeHeader) "port" (tpl ( $probeValues.port | toString ) $rootContext) -}}
|
||||
{{- if kindIs "float64" $probeValues.port -}}
|
||||
{{- $_ := set (index $probeDefinition $probeHeader) "port" $probeValues.port -}}
|
||||
{{- else if kindIs "string" $probeValues.port -}}
|
||||
{{- $_ := set (index $probeDefinition $probeHeader) "port" (tpl ( $probeValues.port | toString ) $rootContext) -}}
|
||||
{{- end -}}
|
||||
{{- else if $primaryServiceDefaultPort.targetPort -}}
|
||||
{{- $_ := set (index $probeDefinition $probeHeader) "port" $primaryServiceDefaultPort.targetPort -}}
|
||||
{{- else -}}
|
||||
|
|
|
@ -25,7 +25,7 @@ volumeMounts used by the container.
|
|||
{{- end -}}
|
||||
|
||||
{{- /* Collect volumeClaimTemplates */ -}}
|
||||
{{- if not (eq (dig "statefulset" "volumeClaimTemplates" nil $controllerObject) nil) -}}
|
||||
{{- if not (empty (dig "statefulset" "volumeClaimTemplates" nil $controllerObject)) -}}
|
||||
{{- range $persistenceValues := $controllerObject.statefulset.volumeClaimTemplates -}}
|
||||
{{- /* Enable persistence item by default, but allow override */ -}}
|
||||
{{- $persistenceEnabled := true -}}
|
||||
|
@ -35,10 +35,10 @@ volumeMounts used by the container.
|
|||
|
||||
{{- if $persistenceEnabled -}}
|
||||
{{- $mountValues := dict -}}
|
||||
{{- if not (eq (dig "globalMounts" nil $persistenceValues) nil) -}}
|
||||
{{- if not (empty (dig "globalMounts" nil $persistenceValues)) -}}
|
||||
{{- $_ := set $mountValues "globalMounts" $persistenceValues.globalMounts -}}
|
||||
{{- end -}}
|
||||
{{- if not (eq (dig "advancedMounts" nil $persistenceValues) nil) -}}
|
||||
{{- if not (empty (dig "advancedMounts" nil $persistenceValues)) -}}
|
||||
{{- $_ := set $mountValues "advancedMounts" (dict $controllerObject.identifier $persistenceValues.advancedMounts) -}}
|
||||
{{- end -}}
|
||||
{{- $_ := set $persistenceItemsToProcess $persistenceValues.name $mountValues -}}
|
||||
|
|
|
@ -7,7 +7,7 @@ Convert controller values to an object
|
|||
{{- $objectValues := .values -}}
|
||||
|
||||
{{- /* Default the controller type to Deployment */ -}}
|
||||
{{- if eq (dig "type" "" $objectValues) "" -}}
|
||||
{{- if empty (dig "type" nil $objectValues) -}}
|
||||
{{- $_ := set $objectValues "type" "deployment" -}}
|
||||
{{- end -}}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ Validate Ingress values
|
|||
|
||||
{{- range $ingressValues.hosts -}}
|
||||
{{- range .paths -}}
|
||||
{{- if or (eq (dig "service" "name" "" .) "") (not .service.name) -}}
|
||||
{{- if empty (dig "service" "name" nil .) -}}
|
||||
{{- fail (printf "No service name configured. (ingress: %s, path: %s)" $ingressValues.identifier .path) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue