feat(common): Release common 4.0.0 (#398)

Co-authored-by: lab-assistant[bot] <180935599+lab-assistant[bot]@users.noreply.github.com>
This commit is contained in:
Bernd Schorgers 2025-05-16 08:40:39 +02:00
parent 1e210f43e3
commit a01a89cb13
No known key found for this signature in database
327 changed files with 11181 additions and 7330 deletions

View file

@ -22,13 +22,13 @@ metadata:
{{- with $labels }}
labels:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
{{- with $annotations }}
annotations:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
namespace: {{ $rootContext.Release.Namespace }}

View file

@ -6,13 +6,10 @@ using the common library.
{{- $rootContext := .rootContext -}}
{{- $cronjobObject := .object -}}
{{- $timeZone := "" -}}
{{- if ge (int $rootContext.Capabilities.KubeVersion.Minor) 27 }}
{{- $timeZone = dig "cronjob" "timeZone" "" $cronjobObject -}}
{{- end -}}
{{- $timeZone := dig "cronjob" "timeZone" "" $cronjobObject -}}
{{- $labels := merge
(dict "app.kubernetes.io/component" $cronjobObject.identifier)
(dict "app.kubernetes.io/controller" $cronjobObject.identifier)
($cronjobObject.labels | default dict)
(include "bjw-s.common.lib.metadata.allLabels" $rootContext | fromYaml)
-}}
@ -30,13 +27,13 @@ metadata:
{{- with $labels }}
labels:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
{{- with $annotations }}
annotations:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
namespace: {{ $rootContext.Release.Namespace }}

View file

@ -7,7 +7,7 @@ within the common library.
{{- $daemonsetObject := .object -}}
{{- $labels := merge
(dict "app.kubernetes.io/component" $daemonsetObject.identifier)
(dict "app.kubernetes.io/controller" $daemonsetObject.identifier)
($daemonsetObject.labels | default dict)
(include "bjw-s.common.lib.metadata.allLabels" $rootContext | fromYaml)
-}}
@ -23,13 +23,13 @@ metadata:
{{- with $labels }}
labels:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
{{- with $annotations }}
annotations:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
namespace: {{ $rootContext.Release.Namespace }}
@ -37,7 +37,7 @@ spec:
revisionHistoryLimit: {{ include "bjw-s.common.lib.defaultKeepNonNullValue" (dict "value" $daemonsetObject.revisionHistoryLimit "default" 3) }}
selector:
matchLabels:
app.kubernetes.io/component: {{ $daemonsetObject.identifier }}
app.kubernetes.io/controller: {{ $daemonsetObject.identifier }}
{{- include "bjw-s.common.lib.metadata.selectorLabels" $rootContext | nindent 6 }}
template:
metadata:

View file

@ -7,7 +7,7 @@ using the common library.
{{- $deploymentObject := .object -}}
{{- $labels := merge
(dict "app.kubernetes.io/component" $deploymentObject.identifier)
(dict "app.kubernetes.io/controller" $deploymentObject.identifier)
($deploymentObject.labels | default dict)
(include "bjw-s.common.lib.metadata.allLabels" $rootContext | fromYaml)
-}}
@ -23,13 +23,13 @@ metadata:
{{- with $labels }}
labels:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
{{- with $annotations }}
annotations:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
namespace: {{ $rootContext.Release.Namespace }}
@ -57,7 +57,7 @@ spec:
{{- end }}
selector:
matchLabels:
app.kubernetes.io/component: {{ $deploymentObject.identifier }}
app.kubernetes.io/controller: {{ $deploymentObject.identifier }}
{{- include "bjw-s.common.lib.metadata.selectorLabels" $rootContext | nindent 6 }}
template:
metadata:

View file

@ -23,13 +23,13 @@ metadata:
{{- with $labels }}
labels:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
{{- with $annotations }}
annotations:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
namespace: {{ $rootContext.Release.Namespace }}
@ -72,7 +72,7 @@ spec:
{{ else if .service.identifier -}}
{{ $service = (include "bjw-s.common.lib.service.getByIdentifier" (dict "rootContext" $rootContext "id" .service.identifier) | fromYaml ) -}}
{{ if not $service -}}
{{fail (printf "No service found with this identifier. (ingress: '%s', path: '%s', identifier: '%s')" $ingressObject.identifier .path .service.identifier)}}
{{fail (printf "No enabled Service found with this identifier. (ingress: '%s', path: '%s', identifier: '%s')" $ingressObject.identifier .path .service.identifier)}}
{{ end -}}
{{ $serviceName = $service.name -}}
{{ end -}}

View file

@ -7,7 +7,7 @@ within the common library.
{{- $jobObject := .object -}}
{{- $labels := merge
(dict "app.kubernetes.io/component" $jobObject.identifier)
(dict "app.kubernetes.io/controller" $jobObject.identifier)
($jobObject.labels | default dict)
(include "bjw-s.common.lib.metadata.allLabels" $rootContext | fromYaml)
-}}
@ -25,13 +25,13 @@ metadata:
{{- with $labels }}
labels:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
{{- with $annotations }}
annotations:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
namespace: {{ $rootContext.Release.Namespace }}

View file

@ -20,7 +20,7 @@ within the common library.
{{- else -}}
{{- $podSelector = dict "matchLabels" (merge
($networkPolicyObject.extraSelectorLabels | default dict)
(dict "app.kubernetes.io/component" $networkPolicyObject.controller)
(dict "app.kubernetes.io/controller" $networkPolicyObject.controller)
(include "bjw-s.common.lib.metadata.selectorLabels" $rootContext | fromYaml)
) -}}
{{- end -}}
@ -32,13 +32,13 @@ metadata:
{{- with $labels }}
labels:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
{{- with $annotations }}
annotations:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
namespace: {{ $rootContext.Release.Namespace }}

View file

@ -20,7 +20,6 @@ within the common library.
$annotations
-}}
{{- end -}}
---
kind: PersistentVolumeClaim
apiVersion: v1
@ -29,13 +28,13 @@ metadata:
{{- with $labels }}
labels:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
{{- with $annotations }}
annotations:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
namespace: {{ $rootContext.Release.Namespace }}

View file

@ -22,13 +22,13 @@ metadata:
{{- with $labels }}
labels:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
{{- with $annotations }}
annotations:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
{{- with $resourceObject.spec }}

View file

@ -25,16 +25,21 @@ kind: {{ . }}
metadata:
name: {{ $roleObject.name }}
{{- with $labels }}
labels: {{- toYaml . | nindent 4 -}}
labels:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
{{- with $annotations }}
annotations: {{- toYaml . | nindent 4 -}}
annotations:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
{{ if eq $roleObject.type "Role" -}}
{{- if eq $roleObject.type "Role" }}
namespace: {{ $rootContext.Release.Namespace }}
{{- end -}}
{{ with $rules }}
{{- end }}
{{- with $rules }}
rules: {{- tpl . $rootContext | nindent 2 }}
{{- end }}
{{- end -}}

View file

@ -18,6 +18,9 @@ This template serves as a blueprint for generating RoleBinding objects in Kubern
{{- range $subject := . -}}
{{- if hasKey . "identifier" -}}
{{- $subject := include "bjw-s.common.lib.serviceAccount.getByIdentifier" (dict "rootContext" $rootContext "id" .identifier) | fromYaml -}}
{{- if not $subject }}
{{- fail (printf "No enabled ServiceAccount found with this identifier. (rolebinding: '%s', identifier: '%s')" $roleBindingObject.identifier .identifier) -}}
{{- end -}}
{{- $subject = pick $subject "name" -}}
{{- $_ := set $subject "kind" "ServiceAccount" -}}
{{- $_ := set $subject "namespace" $rootContext.Release.Namespace -}}
@ -38,7 +41,6 @@ This template serves as a blueprint for generating RoleBinding objects in Kubern
{{- $_ := set $role "name" .name -}}
{{- $_ := set $role "type" .kind -}}
{{- end -}}
{{- end -}}
---
apiVersion: rbac.authorization.k8s.io/v1
@ -48,10 +50,16 @@ kind: {{ . }}
metadata:
name: {{ $roleBindingObject.name }}
{{- with $labels }}
labels: {{- toYaml . | nindent 4 -}}
labels:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
{{- with $annotations }}
annotations: {{- toYaml . | nindent 4 -}}
annotations:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
{{ if eq $roleBindingObject.type "RoleBinding" -}}
namespace: {{ $rootContext.Release.Namespace }}

View file

@ -50,6 +50,9 @@ spec:
{{- if .sectionName }}
sectionName: {{ .sectionName | quote }}
{{- end }}
{{- if .port }}
port: {{ .port }}
{{- end }}
{{- end }}
{{- if and (ne $routeKind "TCPRoute") (ne $routeKind "UDPRoute") $routeObject.hostnames }}
hostnames:
@ -59,35 +62,47 @@ spec:
{{- end }}
rules:
{{- range $routeObject.rules }}
- backendRefs:
{{- range .backendRefs }}
{{ $service := include "bjw-s.common.lib.service.getByIdentifier" (dict "rootContext" $rootContext "id" .name) | fromYaml -}}
{{ $servicePrimaryPort := dict -}}
{{ if $service -}}
{{ $servicePrimaryPort = include "bjw-s.common.lib.service.primaryPort" (dict "rootContext" $rootContext "serviceObject" $service) | fromYaml -}}
{{- end }}
- group: {{ .group | default "" | quote}}
kind: {{ .kind | default "Service" }}
name: {{ $service.name | default .name }}
namespace: {{ .namespace | default $rootContext.Release.Namespace }}
port: {{ .port | default $servicePrimaryPort.port }}
weight: {{ include "bjw-s.common.lib.defaultKeepNonNullValue" (dict "value" .weight "default" 1) }}
{{- end }}
{{- if or (eq $routeKind "HTTPRoute") (eq $routeKind "GRPCRoute") }}
{{- with .matches }}
matches:
{{- toYaml . | nindent 6 }}
- backendRefs:
{{- if empty .backendRefs }}
{{- printf " []" }}
{{- else }}
{{- range .backendRefs }}
{{- $service := dict }}
{{- $serviceName := "" }}
{{- $defaultServicePort := dict }}
{{- if .name }}
{{- $serviceName = tpl .name $rootContext }}
{{- else if .identifier }}
{{- $service = (include "bjw-s.common.lib.service.getByIdentifier" (dict "rootContext" $rootContext "id" .identifier) | fromYaml ) }}
{{- if not $service }}
{{- fail (printf "No enabled Service found with this identifier. (route: '%s', identifier: '%s')" $routeObject.identifier .identifier) }}
{{- end }}
{{- $serviceName = $service.name }}
{{- $defaultServicePort = include "bjw-s.common.lib.service.primaryPort" (dict "rootContext" $rootContext "serviceObject" $service) | fromYaml }}
{{- end }}
- group: {{ .group | default "" | quote}}
kind: {{ .kind | default "Service" }}
name: {{ $serviceName }}
namespace: {{ .namespace | default $rootContext.Release.Namespace }}
port: {{ .port | default $defaultServicePort.port }}
weight: {{ include "bjw-s.common.lib.defaultKeepNonNullValue" (dict "value" .weight "default" 1) }}
{{- end }}
{{- end }}
{{- if or (eq $routeKind "HTTPRoute") (eq $routeKind "GRPCRoute") }}
{{- with .matches }}
matches: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .filters }}
filters:
{{- toYaml . | nindent 6 }}
filters: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .sessionPersistence }}
sessionPersistence: {{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
{{- end }}
{{- if (eq $routeKind "HTTPRoute") }}
{{- with .timeouts }}
timeouts:
{{- toYaml . | nindent 6 }}
{{- if (eq $routeKind "HTTPRoute") }}
{{- with .timeouts }}
timeouts: {{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}

View file

@ -30,13 +30,13 @@ metadata:
{{- with $labels }}
labels:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
{{- with $annotations }}
annotations:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
namespace: {{ $rootContext.Release.Namespace }}

View file

@ -25,13 +25,13 @@ metadata:
{{- with $labels }}
labels:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
{{- with $annotations }}
annotations:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
namespace: {{ $rootContext.Release.Namespace }}
@ -114,7 +114,7 @@ spec:
{{- end -}}
{{- with (merge
($serviceObject.extraSelectorLabels | default dict)
(dict "app.kubernetes.io/component" $serviceObject.controller)
(dict "app.kubernetes.io/controller" $serviceObject.controller)
(include "bjw-s.common.lib.metadata.selectorLabels" $rootContext | fromYaml)
) }}
selector: {{- toYaml . | nindent 4 }}

View file

@ -22,16 +22,18 @@ metadata:
{{- with $labels }}
labels:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
{{- with $annotations }}
annotations:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
namespace: {{ $rootContext.Release.Namespace }}
{{- if $serviceAccountObject.staticToken }}
secrets:
- name: {{ get (include "bjw-s.common.lib.secret.getByIdentifier" (dict "rootContext" $rootContext "id" (printf "%s-sa-token" $serviceAccountObject.identifier) ) | fromYaml) "name"}}
{{- end }}
{{- end -}}

View file

@ -17,13 +17,13 @@ metadata:
{{- with $labels }}
labels:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
{{- with $annotations }}
annotations:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
namespace: {{ $rootContext.Release.Namespace }}

View file

@ -7,7 +7,7 @@ within the common library.
{{- $statefulsetObject := .object -}}
{{- $labels := merge
(dict "app.kubernetes.io/component" $statefulsetObject.identifier)
(dict "app.kubernetes.io/controller" $statefulsetObject.identifier)
($statefulsetObject.labels | default dict)
(include "bjw-s.common.lib.metadata.allLabels" $rootContext | fromYaml)
-}}
@ -23,13 +23,13 @@ metadata:
{{- with $labels }}
labels:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
{{- with $annotations }}
annotations:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
namespace: {{ $rootContext.Release.Namespace }}
@ -45,7 +45,7 @@ spec:
{{- end }}
selector:
matchLabels:
app.kubernetes.io/component: {{ $statefulsetObject.identifier }}
app.kubernetes.io/controller: {{ $statefulsetObject.identifier }}
{{- include "bjw-s.common.lib.metadata.selectorLabels" $rootContext | nindent 6 }}
serviceName: {{ include "bjw-s.common.lib.chart.names.fullname" $rootContext }}
{{- with (dig "statefulset" "persistentVolumeClaimRetentionPolicy" nil $statefulsetObject) }}

View file

@ -0,0 +1,38 @@
{{/*
Determine a recourse name based on Helm values
*/}}
{{- define "bjw-s.common.lib.determineResourceNameFromValues" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $objectValues := .values -}}
{{- $itemCount := .itemCount -}}
{{- $objectName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}}
{{- if $objectValues.forceRename -}}
{{- $objectName = tpl $objectValues.forceRename $rootContext -}}
{{- else -}}
{{- if not (empty $objectValues.prefix) -}}
{{- $renderedPrefix := (tpl $objectValues.prefix $rootContext) -}}
{{- if not (eq $objectName $renderedPrefix) -}}
{{- $objectName = printf "%s-%s" $renderedPrefix $objectName -}}
{{- end -}}
{{- end -}}
{{- if not (empty $itemCount) -}}
{{- if (gt $itemCount 1) -}}
{{- if not (hasSuffix (printf "-%s" $identifier) $objectName) -}}
{{- $objectName = printf "%s-%s" $objectName $identifier -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if not (empty $objectValues.suffix) -}}
{{- $renderedSuffix := (tpl $objectValues.suffix $rootContext) -}}
{{- if not (hasSuffix (printf "-%s" $renderedSuffix) $objectName) -}}
{{- $objectName = printf "%s-%s" $objectName $renderedSuffix -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $objectName | lower -}}
{{- end -}}

View file

@ -5,25 +5,12 @@ Convert values to an object
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $objectValues := .values -}}
{{- $itemCount := .itemCount -}}
{{- /* Determine and inject the name */ -}}
{{- $objectName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}}
{{- if $objectValues.forceRename -}}
{{- $objectName = tpl $objectValues.forceRename $rootContext -}}
{{- else if $objectValues.nameOverride -}}
{{- $override := tpl $objectValues.nameOverride $rootContext -}}
{{- if not (eq $objectName $override) -}}
{{- $objectName = printf "%s-%s" $objectName $override -}}
{{- end -}}
{{- else -}}
{{- if not (eq $objectName $identifier) -}}
{{- $objectName = printf "%s-%s" $objectName $identifier -}}
{{- end -}}
{{- end -}}
{{- $objectName := (include "bjw-s.common.lib.determineResourceNameFromValues" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" $itemCount)) -}}
{{- $_ := set $objectValues "name" $objectName -}}
{{- $_ := set $objectValues "identifier" $identifier -}}
{{- /* Return the object */ -}}
{{- $objectValues | toYaml -}}
{{- end -}}

View file

@ -0,0 +1,23 @@
{{/*
Return the enabled configMaps.
*/}}
{{- define "bjw-s.common.lib.configMap.enabledConfigmaps" -}}
{{- $rootContext := .rootContext -}}
{{- $enabledSecrets := dict -}}
{{- range $identifier, $secret := $rootContext.Values.configMaps -}}
{{- if kindIs "map" $secret -}}
{{- /* Enable Secret by default, but allow override */ -}}
{{- $secretEnabled := true -}}
{{- if hasKey $secret "enabled" -}}
{{- $secretEnabled = $secret.enabled -}}
{{- end -}}
{{- if $secretEnabled -}}
{{- $_ := set $enabledSecrets $identifier . -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $enabledSecrets | toYaml -}}
{{- end -}}

View file

@ -4,9 +4,10 @@ Return a configMap Object by its Identifier.
{{- define "bjw-s.common.lib.configMap.getByIdentifier" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $enabledConfigMaps := (include "bjw-s.common.lib.configMap.enabledConfigmaps" (dict "rootContext" $rootContext) | fromYaml ) }}
{{- $configMapValues := dig $identifier nil $rootContext.Values.configMaps -}}
{{- if not (empty $configMapValues) -}}
{{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $configMapValues) -}}
{{- if (hasKey $enabledConfigMaps $identifier) -}}
{{- $objectValues := get $enabledConfigMaps $identifier -}}
{{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" (len $enabledConfigMaps)) -}}
{{- end -}}
{{- end -}}

View file

@ -6,9 +6,10 @@ Validate configMap values
{{- $configMapValues := .object -}}
{{- $identifier := .id -}}
{{- if empty $configMapValues -}}
{{- if eq (len (without (keys $configMapValues) "name" "identifier")) 0 -}}
{{- fail (printf "There was an error loading ConfigMap: %s. If it was automatically generated from a folder verify that files are properly flagged as `binary` or `escaped`" $identifier) -}}
{{- end -}}
{{- if and (empty (get $configMapValues "data")) (empty (get $configMapValues "binaryData")) -}}
{{- fail (printf "No data or binaryData specified for configMap. (configMap: %s)" $configMapValues.identifier) }}
{{- end -}}

View file

@ -81,20 +81,22 @@ volumeMounts used by the container.
{{- /* Use the specified subPath if provided */ -}}
{{- with .subPath -}}
{{- $subPath := . -}}
{{- $_ := set $volumeMount "subPath" $subPath -}}
{{- $_ := set $volumeMount "subPath" . -}}
{{- end -}}
{{- /* Use the specified subPathExpr if provided */ -}}
{{- with .subPathExpr -}}
{{- $_ := set $volumeMount "subPathExpr" . -}}
{{- end -}}
{{- /* Use the specified readOnly setting if provided */ -}}
{{- with .readOnly -}}
{{- $readOnly := . -}}
{{- $_ := set $volumeMount "readOnly" $readOnly -}}
{{- $_ := set $volumeMount "readOnly" . -}}
{{- end -}}
{{- /* Use the specified mountPropagation setting if provided */ -}}
{{- with .mountPropagation -}}
{{- $mountPropagation := . -}}
{{- $_ := set $volumeMount "mountPropagation" $mountPropagation -}}
{{- $_ := set $volumeMount "mountPropagation" . -}}
{{- end -}}
{{- $enabledVolumeMounts = append $enabledVolumeMounts $volumeMount -}}

View file

@ -1,14 +1,19 @@
{{/*
Return a controller by its identifier.
Return a controller object by its Identifier.
*/}}
{{- define "bjw-s.common.lib.controller.getByIdentifier" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $enabledControllers := (include "bjw-s.common.lib.controller.enabledControllers" (dict "rootContext" $rootContext) | fromYaml ) }}
{{- $enabledControllers := include "bjw-s.common.lib.controller.enabledControllers" (dict "rootContext" $rootContext) | fromYaml -}}
{{- $controllerValues := get $enabledControllers $identifier -}}
{{- if (hasKey $enabledControllers $identifier) -}}
{{- $objectValues := get $enabledControllers $identifier -}}
{{- if not (empty $controllerValues) -}}
{{- include "bjw-s.common.lib.controller.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $controllerValues) -}}
{{- /* Default the controller type to Deployment */ -}}
{{- if empty (dig "type" nil $objectValues) -}}
{{- $_ := set $objectValues "type" "deployment" -}}
{{- end -}}
{{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" (len $enabledControllers)) -}}
{{- end -}}
{{- end -}}

View file

@ -1,35 +0,0 @@
{{/*
Convert controller values to an object
*/}}
{{- define "bjw-s.common.lib.controller.valuesToObject" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $objectValues := .values -}}
{{- /* Default the controller type to Deployment */ -}}
{{- if empty (dig "type" nil $objectValues) -}}
{{- $_ := set $objectValues "type" "deployment" -}}
{{- end -}}
{{- /* Determine and inject the controller name */ -}}
{{- $objectName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}}
{{- if $objectValues.nameOverride -}}
{{- $override := tpl $objectValues.nameOverride $rootContext -}}
{{- if not (eq $objectName $override) -}}
{{- $objectName = printf "%s-%s" $objectName $override -}}
{{- end -}}
{{- else -}}
{{- $enabledControllers := (include "bjw-s.common.lib.controller.enabledControllers" (dict "rootContext" $rootContext) | fromYaml ) }}
{{- if gt (len $enabledControllers) 1 -}}
{{- if not (eq $objectName $identifier) -}}
{{- $objectName = printf "%s-%s" $objectName $identifier -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $_ := set $objectValues "name" $objectName -}}
{{- $_ := set $objectValues "identifier" $identifier -}}
{{- /* Return the controller object */ -}}
{{- $objectValues | toYaml -}}
{{- end -}}

View file

@ -5,6 +5,12 @@ Convert Cronjob values to an object
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $objectValues := .values -}}
{{- $itemCount := .itemCount -}}
{{- $objectName := (include "bjw-s.common.lib.determineResourceNameFromValues" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" $itemCount)) -}}
{{- $_ := set $objectValues "name" $objectName -}}
{{- $_ := set $objectValues "identifier" $identifier -}}
{{- if not (hasKey $objectValues "pod") -}}
{{- $_ := set $objectValues "pod" dict -}}
@ -13,6 +19,5 @@ Convert Cronjob values to an object
{{- $restartPolicy := default "Never" $objectValues.pod.restartPolicy -}}
{{- $_ := set $objectValues.pod "restartPolicy" $restartPolicy -}}
{{- /* Return the CronJob object */ -}}
{{- $objectValues | toYaml -}}
{{- end -}}

View file

@ -0,0 +1,30 @@
{{/*
Return an Ingress Object by its Identifier.
*/}}
{{- define "bjw-s.common.lib.ingress.getByIdentifier" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $enabledServices := (include "bjw-s.common.lib.service.enabledServices" (dict "rootContext" $rootContext) | fromYaml ) -}}
{{- $enabledIngresses := (include "bjw-s.common.lib.ingress.enabledIngresses" (dict "rootContext" $rootContext) | fromYaml ) }}
{{- if (hasKey $enabledIngresses $identifier) -}}
{{- $objectValues := get $enabledIngresses $identifier -}}
{{- $object := include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" (len $enabledIngresses)) | fromYaml -}}
{{- /* Try to automatically determine the default Service identifier if needed and possible */ -}}
{{- if eq 1 (len $enabledServices) -}}
{{- range $object.hosts -}}
{{- range .paths -}}
{{- if not (has "service" (keys .)) -}}
{{- $_ := set . "service" (dict "identifier" ($enabledServices | keys | first)) -}}
{{- else if and (not .service.name) (not .service.identifier) -}}
{{- $_ := set .service "identifier" ($enabledServices | keys | first) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $object | toYaml -}}
{{- end -}}
{{- end -}}

View file

@ -3,5 +3,21 @@ Validate Ingress values
*/}}
{{- define "bjw-s.common.lib.ingress.validate" -}}
{{- $rootContext := .rootContext -}}
{{- $ingressValues := .object -}}
{{- $ingressObject := .object -}}
{{- $enabledServices := (include "bjw-s.common.lib.service.enabledServices" (dict "rootContext" $rootContext) | fromYaml ) -}}
{{/* Verify automatic service detection */}}
{{- if not (eq 1 (len $enabledServices)) -}}
{{- range $ingressObject.hosts -}}
{{- $host := . -}}
{{- range $host.paths -}}
{{- $path := . -}}
{{- if or (not (has "service" (keys .))) (and (not $path.service.name) (not $path.service.identifier)) -}}
{{- fail (printf "Either service.name or service.identifier is required because automatic Service detection is not possible. (ingress: %s, host: %s, path: %s)" $ingressObject.identifier $host.host $path.path ) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}

View file

@ -1,30 +0,0 @@
{{/*
Convert ingress values to an object
*/}}
{{- define "bjw-s.common.lib.ingress.valuesToObject" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $objectValues := .values -}}
{{- /* Determine and inject the ingress name */ -}}
{{- $objectName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}}
{{- if $objectValues.nameOverride -}}
{{- $override := tpl $objectValues.nameOverride $rootContext -}}
{{- if not (eq $objectName $override) -}}
{{- $objectName = printf "%s-%s" $objectName $override -}}
{{- end -}}
{{- else -}}
{{- $enabledIngresses := (include "bjw-s.common.lib.ingress.enabledIngresses" (dict "rootContext" $rootContext) | fromYaml ) }}
{{- if gt (len $enabledIngresses) 1 -}}
{{- if not (eq $objectName $identifier) -}}
{{- $objectName = printf "%s-%s" $objectName $identifier -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $_ := set $objectValues "name" $objectName -}}
{{- $_ := set $objectValues "identifier" $identifier -}}
{{- /* Return the ingress object */ -}}
{{- $objectValues | toYaml -}}
{{- end -}}

View file

@ -1,7 +1,7 @@
{{/*
Return the enabled NetworkPolicies.
*/}}
{{- define "bjw-s.common.lib.networkPolicy.enabledNetworkPolicies" -}}
{{- define "bjw-s.common.lib.networkpolicy.enabledNetworkPolicies" -}}
{{- $rootContext := .rootContext -}}
{{- $enabledNetworkPolicies := dict -}}

View file

@ -0,0 +1,13 @@
{{/*
Return a NetworkPolicy object by its Identifier.
*/}}
{{- define "bjw-s.common.lib.networkpolicy.getByIdentifier" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $enabledNetworkPolicies := (include "bjw-s.common.lib.networkpolicy.enabledNetworkPolicies" (dict "rootContext" $rootContext) | fromYaml ) }}
{{- if (hasKey $enabledNetworkPolicies $identifier) -}}
{{- $objectValues := get $enabledNetworkPolicies $identifier -}}
{{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" (len $enabledNetworkPolicies)) -}}
{{- end -}}
{{- end -}}

View file

@ -1,30 +0,0 @@
{{/*
Convert networkPolicy values to an object
*/}}
{{- define "bjw-s.common.lib.networkpolicy.valuesToObject" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $objectValues := .values -}}
{{- /* Determine and inject the networkPolicy name */ -}}
{{- $objectName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}}
{{- if $objectValues.nameOverride -}}
{{- $override := tpl $objectValues.nameOverride $rootContext -}}
{{- if not (eq $objectName $override) -}}
{{- $objectName = printf "%s-%s" $objectName $override -}}
{{- end -}}
{{- else -}}
{{- $enabledNetworkPolicies := (include "bjw-s.common.lib.networkPolicy.enabledNetworkPolicies" (dict "rootContext" $rootContext) | fromYaml ) }}
{{- if gt (len $enabledNetworkPolicies) 1 -}}
{{- if not (eq $objectName $identifier) -}}
{{- $objectName = printf "%s-%s" $objectName $identifier -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $_ := set $objectValues "name" $objectName -}}
{{- $_ := set $objectValues "identifier" $identifier -}}
{{- /* Return the networkPolicy object */ -}}
{{- $objectValues | toYaml -}}
{{- end -}}

View file

@ -6,9 +6,10 @@ Returns the value for the specified field
{{- $controllerObject := .ctx.controllerObject -}}
{{- $option := .option -}}
{{- $default := default "" .default -}}
{{- $value := $default -}}
{{- $defaultPodOptionsStrategy := dig "defaultPodOptionsStrategy" "overwrite" $rootContext.Values -}}
{{- /* Set to the default if it is set */ -}}
{{- $defaultOption := dig $option nil (default dict $rootContext.Values.defaultPodOptions) -}}
{{- if kindIs "bool" $defaultOption -}}
@ -19,8 +20,15 @@ Returns the value for the specified field
{{- /* See if a pod-specific override is needed */ -}}
{{- $podOption := dig $option nil (default dict $controllerObject.pod) -}}
{{- if kindIs "bool" $podOption -}}
{{- $value = $podOption -}}
{{- else if kindIs "map" $podOption -}}
{{- if eq "merge" $defaultPodOptionsStrategy -}}
{{- $value = merge $podOption $value -}}
{{- else if eq "overwrite" $defaultPodOptionsStrategy -}}
{{- $value = $podOption -}}
{{- end -}}
{{- else if not (empty $podOption) -}}
{{- $value = $podOption -}}
{{- end -}}

View file

@ -48,6 +48,11 @@ imagePullSecrets: {{ . | nindent 2 }}
{{- with (include "bjw-s.common.lib.pod.getOption" (dict "ctx" $ctx "option" "terminationGracePeriodSeconds")) }}
terminationGracePeriodSeconds: {{ . | trim }}
{{- end -}}
{{- if ge ($rootContext.Capabilities.KubeVersion.Minor | int) 32 }}
{{- with (include "bjw-s.common.lib.pod.getOption" (dict "ctx" $ctx "option" "resources")) }}
resources: {{ . | nindent 2 }}
{{- end -}}
{{- end -}}
{{- with (include "bjw-s.common.lib.pod.getOption" (dict "ctx" $ctx "option" "restartPolicy")) }}
restartPolicy: {{ . | trim }}
{{- end -}}

View file

@ -4,24 +4,20 @@ Returns the value for serviceAccountName
{{- define "bjw-s.common.lib.pod.field.serviceAccountName" -}}
{{- $rootContext := .ctx.rootContext -}}
{{- $controllerObject := .ctx.controllerObject -}}
{{- $serviceAccountName := "default" -}}
{{- if $rootContext.Values.enforceServiceAccountCreation -}}
{{- if (get (include "bjw-s.common.lib.serviceAccount.getByIdentifier" (dict "rootContext" $rootContext "id" "default") | fromYaml) "create") -}}
{{- $serviceAccountName = get (include "bjw-s.common.lib.serviceAccount.getByIdentifier" (dict "rootContext" $rootContext "id" "default") | fromYaml) "name" -}}
{{- end -}}
{{- else -}}
{{- $serviceAccountName = get (include "bjw-s.common.lib.serviceAccount.getByIdentifier" (dict "rootContext" $rootContext "id" "default") | fromYaml) "name" -}}
{{- end -}}
{{- with $controllerObject.serviceAccount -}}
{{- if hasKey . "identifier" -}}
{{- $serviceAccountName = get (include "bjw-s.common.lib.serviceAccount.getByIdentifier" (dict "rootContext" $rootContext "id" .identifier) | fromYaml) "name" -}}
{{- $subject := (include "bjw-s.common.lib.serviceAccount.getByIdentifier" (dict "rootContext" $rootContext "id" .identifier) | fromYaml) -}}
{{- if not $subject }}
{{- fail (printf "No enabled ServiceAccount found with this identifier. (controller: '%s', identifier: '%s')" $controllerObject.identifier .identifier) -}}
{{- end -}}
{{- $serviceAccountName = get $subject "name" -}}
{{- else if hasKey . "name" -}}
{{- $serviceAccountName = .name -}}
{{- end -}}
{{- end -}}
{{- $serviceAccountName -}}
{{- end -}}

View file

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

View file

@ -7,7 +7,7 @@ Returns the value for labels
{{- /* Default labels */ -}}
{{- $labels := merge
(dict "app.kubernetes.io/component" $controllerObject.identifier)
(dict "app.kubernetes.io/controller" $controllerObject.identifier)
-}}
{{- /* Include global labels if specified */ -}}

View file

@ -0,0 +1,23 @@
{{/*
Return the enabled PVCs.
*/}}
{{- define "bjw-s.common.lib.pvc.enabledPVCs" -}}
{{- $rootContext := .rootContext -}}
{{- $enabledPVCs := dict -}}
{{- range $identifier, $persistenceItem := $rootContext.Values.persistence -}}
{{- if kindIs "map" $persistenceItem -}}
{{- /* Enable PVC by default, but allow override */ -}}
{{- $pvcEnabled := true -}}
{{- if hasKey $persistenceItem "enabled" -}}
{{- $pvcEnabled = $persistenceItem.enabled -}}
{{- end -}}
{{- if and $pvcEnabled (eq (default "persistentVolumeClaim" $persistenceItem.type) "persistentVolumeClaim") (not $persistenceItem.existingClaim) -}}
{{- $_ := set $enabledPVCs $identifier . -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $enabledPVCs | toYaml -}}
{{- end -}}

View file

@ -0,0 +1,23 @@
{{/*
Return the enabled roles.
*/}}
{{- define "bjw-s.common.lib.rbac.role.enabledRoles" -}}
{{- $rootContext := .rootContext -}}
{{- $enabledRoles := dict -}}
{{- range $name, $role := $rootContext.Values.rbac.roles -}}
{{- if kindIs "map" $role -}}
{{- /* Enable Role by default, but allow override */ -}}
{{- $roleEnabled := true -}}
{{- if hasKey $role "enabled" -}}
{{- $roleEnabled = $role.enabled -}}
{{- end -}}
{{- if $roleEnabled -}}
{{- $_ := set $enabledRoles $name . -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $enabledRoles | toYaml -}}
{{- end -}}

View file

@ -0,0 +1,13 @@
{{/*
Return a PVC object by its Identifier.
*/}}
{{- define "bjw-s.common.lib.pvc.getByIdentifier" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $enabledPVCs := (include "bjw-s.common.lib.pvc.enabledPVCs" (dict "rootContext" $rootContext) | fromYaml ) }}
{{- if (hasKey $enabledPVCs $identifier) -}}
{{- $objectValues := get $enabledPVCs $identifier -}}
{{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" (len $enabledPVCs)) -}}
{{- end -}}
{{- end -}}

View file

@ -1,7 +0,0 @@
{{/*
Validate PVC values
*/}}
{{- define "bjw-s.common.lib.pvc.validate" -}}
{{- $rootContext := .rootContext -}}
{{- $pvcObject := .object -}}
{{- end -}}

View file

@ -1,26 +0,0 @@
{{/*
Convert PVC values to an object
*/}}
{{- define "bjw-s.common.lib.pvc.valuesToObject" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $objectValues := .values -}}
{{- /* Determine and inject the PVC name */ -}}
{{- $objectName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}}
{{- if $objectValues.nameOverride -}}
{{- if ne $objectValues.nameOverride "-" -}}
{{- $objectName = printf "%s-%s" $objectName $objectValues.nameOverride -}}
{{- end -}}
{{- else -}}
{{- if not (eq $objectName $identifier) -}}
{{- $objectName = printf "%s-%s" $objectName $identifier -}}
{{- end -}}
{{- end -}}
{{- $_ := set $objectValues "name" $objectName -}}
{{- $_ := set $objectValues "identifier" $identifier -}}
{{- /* Return the PVC object */ -}}
{{- $objectValues | toYaml -}}
{{- end -}}

View file

@ -0,0 +1,23 @@
{{/*
Return the enabled raw resources.
*/}}
{{- define "bjw-s.common.lib.rawResource.enabledRawResources" -}}
{{- $rootContext := .rootContext -}}
{{- $enabledRawResources := dict -}}
{{- range $name, $resource := $rootContext.Values.rawResources -}}
{{- if kindIs "map" $resource -}}
{{- /* Enable Raw Resource by default, but allow override */ -}}
{{- $resourceEnabled := true -}}
{{- if hasKey $resource "enabled" -}}
{{- $resourceEnabled = $resource.enabled -}}
{{- end -}}
{{- if $resourceEnabled -}}
{{- $_ := set $enabledRawResources $name . -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $enabledRawResources | toYaml -}}
{{- end -}}

View file

@ -0,0 +1,13 @@
{{/*
Return a RawResource Object by its Identifier.
*/}}
{{- define "bjw-s.common.lib.rawResource.getByIdentifier" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $enabledRawResources := (include "bjw-s.common.lib.rawResource.enabledRawResources" (dict "rootContext" $rootContext) | fromYaml ) }}
{{- if (hasKey $enabledRawResources $identifier) -}}
{{- $objectValues := get $enabledRawResources $identifier -}}
{{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" (len $enabledRawResources)) -}}
{{- end -}}
{{- end -}}

View file

@ -1,7 +0,0 @@
{{/*
Validate raw resource values
*/}}
{{- define "bjw-s.common.lib.rawResource.validate" -}}
{{- $rootContext := .rootContext -}}
{{- $resourceObject := .object -}}
{{- end -}}

View file

@ -0,0 +1,23 @@
{{/*
Return the enabled roles.
*/}}
{{- define "bjw-s.common.lib.rbac.role.enabledRoles" -}}
{{- $rootContext := .rootContext -}}
{{- $enabledRoles := dict -}}
{{- range $name, $role := $rootContext.Values.rbac.roles -}}
{{- if kindIs "map" $role -}}
{{- /* Enable Role by default, but allow override */ -}}
{{- $roleEnabled := true -}}
{{- if hasKey $role "enabled" -}}
{{- $roleEnabled = $role.enabled -}}
{{- end -}}
{{- if $roleEnabled -}}
{{- $_ := set $enabledRoles $name . -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $enabledRoles | toYaml -}}
{{- end -}}

View file

@ -4,9 +4,10 @@ Return a Role Object by its Identifier.
{{- define "bjw-s.common.lib.rbac.role.getByIdentifier" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $enabledRoles := (include "bjw-s.common.lib.rbac.role.enabledRoles" (dict "rootContext" $rootContext) | fromYaml ) }}
{{- $roleValues := dig $identifier nil $rootContext.Values.rbac.roles -}}
{{- if not (empty $roleValues) -}}
{{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $roleValues) -}}
{{- if (hasKey $enabledRoles $identifier) -}}
{{- $objectValues := get $enabledRoles $identifier -}}
{{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" (len $enabledRoles)) -}}
{{- end -}}
{{- end -}}

View file

@ -4,15 +4,9 @@ Validate Role values
{{- define "bjw-s.common.lib.rbac.role.validate" -}}
{{- $rootContext := .rootContext -}}
{{- $roleValues := .object -}}
{{- $type := required "The role needs to have an explicitly declared type" $roleValues.type -}}
{{- $typeList := list "Role" "ClusterRole" -}}
{{- $rules := $roleValues.rules -}}
{{- if not (mustHas $type $typeList) -}}
{{- fail (printf "\nYou selected: `%s`. Type must be one of:\n%s\n" $type ($typeList|toYaml)) -}}
{{- end -}}
{{- if not $rules -}}
{{- fail "Rules can't be empty" -}}
{{- end -}}
{{- end -}}

View file

@ -0,0 +1,23 @@
{{/*
Return the enabled RoleBindings.
*/}}
{{- define "bjw-s.common.lib.rbac.roleBinding.enabledRoleBindings" -}}
{{- $rootContext := .rootContext -}}
{{- $enabledRoleBindings := dict -}}
{{- range $name, $role := $rootContext.Values.rbac.bindings -}}
{{- if kindIs "map" $role -}}
{{- /* Enable Role by default, but allow override */ -}}
{{- $roleEnabled := true -}}
{{- if hasKey $role "enabled" -}}
{{- $roleEnabled = $role.enabled -}}
{{- end -}}
{{- if $roleEnabled -}}
{{- $_ := set $enabledRoleBindings $name . -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $enabledRoleBindings | toYaml -}}
{{- end -}}

View file

@ -4,9 +4,10 @@ Return a RoleBinding Object by its Identifier.
{{- define "bjw-s.common.lib.rbac.roleBinding.getByIdentifier" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $enabledRoleBindings := (include "bjw-s.common.lib.rbac.roleBinding.enabledRoleBindings" (dict "rootContext" $rootContext) | fromYaml ) }}
{{- $roleBindingValues := dig $identifier nil $rootContext.Values.rbac.bindings -}}
{{- if not (empty $roleBindingValues) -}}
{{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $roleBindingValues) -}}
{{- if (hasKey $enabledRoleBindings $identifier) -}}
{{- $objectValues := get $enabledRoleBindings $identifier -}}
{{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" (len $enabledRoleBindings)) -}}
{{- end -}}
{{- end -}}

View file

@ -1,32 +0,0 @@
{{/*
Validate RoleBinding values
*/}}
{{- define "bjw-s.common.lib.rbac.roleBinding.validate" -}}
{{- $rootContext := .rootContext -}}
{{- $roleBindingValues := .object -}}
{{- $type := required "The binding needs to have an explicitly declared type" $roleBindingValues.type -}}
{{- $typeList := list "RoleBinding" "ClusterRoleBinding" -}}
{{- $subjects := $roleBindingValues.subjects -}}
{{- $roleRef := required "A roleRef is required" $roleBindingValues.roleRef -}}
{{- if not (mustHas $type $typeList) -}}
{{- fail (printf "\nYou selected: `%s`. Type must be one of:\n%s\n" $type ($typeList|toYaml)) -}}
{{- end -}}
{{- if not (hasKey $roleRef "identifier") -}}
{{- $name := required "If not using identifier roleRef must have a `name` key" $roleRef.name -}}
{{- $name := required "If not using identifier roleRef must have a `kind` key" $roleRef.kind -}}
{{- end -}}
{{- range $subject := $subjects -}}
{{- if not (hasKey . "identifier") -}}
{{- if not (hasKey . "name") -}}
{{- $name := required "If not using identifier a subject must have a `name` key" .name -}}
{{- else if not (hasKey . "namespace") -}}
{{- $namespace := required "If not using identifier a subject must have a `namespace` key" .namespace -}}
{{- else if not (hasKey . "kind") -}}
{{- $kind := required "If not using identifier a subject must have a `kind` key" .kind -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}

View file

@ -0,0 +1,13 @@
{{/*
Return a Route object by its Identifier.
*/}}
{{- define "bjw-s.common.lib.route.getByIdentifier" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $enabledRoutes := (include "bjw-s.common.lib.route.enabledRoutes" (dict "rootContext" $rootContext) | fromYaml ) }}
{{- if (hasKey $enabledRoutes $identifier) -}}
{{- $objectValues := get $enabledRoutes $identifier -}}
{{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" (len $enabledRoutes)) -}}
{{- end -}}
{{- end -}}

View file

@ -1,30 +0,0 @@
{{/*
Convert Route values to an object
*/}}
{{- define "bjw-s.common.lib.route.valuesToObject" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $objectValues := .values -}}
{{- /* Determine and inject the Route name */ -}}
{{- $objectName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}}
{{- if $objectValues.nameOverride -}}
{{- $override := tpl $objectValues.nameOverride $rootContext -}}
{{- if not (eq $objectName $override) -}}
{{- $objectName = printf "%s-%s" $objectName $override -}}
{{- end -}}
{{- else -}}
{{- $enabledRoutes := (include "bjw-s.common.lib.route.enabledRoutes" (dict "rootContext" $rootContext) | fromYaml ) }}
{{- if and (not $objectValues.primary) (gt (len $enabledRoutes) 1) -}}
{{- if not (eq $objectName $identifier) -}}
{{- $objectName = printf "%s-%s" $objectName $identifier -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $_ := set $objectValues "name" $objectName -}}
{{- $_ := set $objectValues "identifier" $identifier -}}
{{- /* Return the Route object */ -}}
{{- $objectValues | toYaml -}}
{{- end -}}

View file

@ -0,0 +1,23 @@
{{/*
Return the enabled secrets.
*/}}
{{- define "bjw-s.common.lib.secret.enabledSecrets" -}}
{{- $rootContext := .rootContext -}}
{{- $enabledSecrets := dict -}}
{{- range $identifier, $secret := $rootContext.Values.secrets -}}
{{- if kindIs "map" $secret -}}
{{- /* Enable Secret by default, but allow override */ -}}
{{- $secretEnabled := true -}}
{{- if hasKey $secret "enabled" -}}
{{- $secretEnabled = $secret.enabled -}}
{{- end -}}
{{- if $secretEnabled -}}
{{- $_ := set $enabledSecrets $identifier . -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $enabledSecrets | toYaml -}}
{{- end -}}

View file

@ -4,9 +4,10 @@ Return a secret Object by its Identifier.
{{- define "bjw-s.common.lib.secret.getByIdentifier" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $enabledSecrets := (include "bjw-s.common.lib.secret.enabledSecrets" (dict "rootContext" $rootContext) | fromYaml ) }}
{{- $secretValues := dig $identifier nil $rootContext.Values.secrets -}}
{{- if not (empty $secretValues) -}}
{{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $secretValues) -}}
{{- if (hasKey $enabledSecrets $identifier) -}}
{{- $objectValues := get $enabledSecrets $identifier -}}
{{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" (len $enabledSecrets)) -}}
{{- end -}}
{{- end -}}

View file

@ -1,7 +0,0 @@
{{/*
Validate Secret values
*/}}
{{- define "bjw-s.common.lib.secret.validate" -}}
{{- $rootContext := .rootContext -}}
{{- $secretValues := .object -}}
{{- end -}}

View file

@ -14,6 +14,8 @@ Return the enabled services.
{{- end -}}
{{- if $serviceEnabled -}}
{{- $_ := set $enabledServices $name . -}}
{{- end -}}
{{- end -}}

View file

@ -4,10 +4,19 @@ Return a service Object by its Identifier.
{{- define "bjw-s.common.lib.service.getByIdentifier" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $enabledServices := (include "bjw-s.common.lib.service.enabledServices" (dict "rootContext" $rootContext) | fromYaml ) }}
{{- $enabledControllers := (include "bjw-s.common.lib.controller.enabledControllers" (dict "rootContext" $rootContext) | fromYaml ) -}}
{{- range $name, $serviceValues := $rootContext.Values.service -}}
{{- if eq $name $identifier -}}
{{- include "bjw-s.common.lib.service.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $serviceValues) -}}
{{- if (hasKey $enabledServices $identifier) -}}
{{- $objectValues := get $enabledServices $identifier -}}
{{- $object := include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" (len $enabledServices)) | fromYaml -}}
{{- if eq 1 (len $enabledControllers) -}}
{{- if (empty (dig "controller" nil $object)) -}}
{{- $_ := set $object "controller" ($enabledControllers | keys | first) -}}
{{- end -}}
{{- end -}}
{{- $object | toYaml -}}
{{- end -}}
{{- end -}}

View file

@ -5,7 +5,7 @@ Return the primary service object for a controller
{{- $rootContext := .rootContext -}}
{{- $controllerIdentifier := .controllerIdentifier -}}
{{- $identifier := "" -}}
{{- $serviceIdentifier := "" -}}
{{- $result := dict -}}
{{- /* Loop over all enabled services */ -}}
@ -13,27 +13,29 @@ Return the primary service object for a controller
{{- if $enabledServices -}}
{{- /* We are only interested in services for the specified controller */ -}}
{{- $enabledServicesForController := dict -}}
{{- range $name, $service := $enabledServices -}}
{{- if eq $service.controller $controllerIdentifier -}}
{{- $_ := set $enabledServicesForController $name $service -}}
{{- range $identifier, $serviceObject := $enabledServices -}}
{{- if eq $serviceObject.controller $controllerIdentifier -}}
{{- $_ := set $enabledServicesForController $identifier $serviceObject -}}
{{- end -}}
{{- end -}}
{{- range $name, $service := $enabledServicesForController -}}
{{- range $identifier, $serviceObject := $enabledServicesForController -}}
{{- /* Determine the Service that has been marked as primary */ -}}
{{- if $service.primary -}}
{{- $identifier = $name -}}
{{- $result = $service -}}
{{- if $serviceObject.primary -}}
{{- $serviceIdentifier = $identifier -}}
{{- $result = $serviceObject -}}
{{- end -}}
{{- /* Return the first Service (alphabetically) if none has been explicitly marked as primary */ -}}
{{- if not $result -}}
{{- $firstServiceKey := keys $enabledServicesForController | sortAlpha | first -}}
{{- $result = get $enabledServicesForController $firstServiceKey -}}
{{- $identifier = $result.identifier -}}
{{- $serviceIdentifier = $identifier -}}
{{- end -}}
{{- end -}}
{{- include "bjw-s.common.lib.service.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $result) -}}
{{- if not (empty $serviceIdentifier) -}}
{{- include "bjw-s.common.lib.service.getByIdentifier" (dict "rootContext" $rootContext "id" $serviceIdentifier) -}}
{{- end -}}
{{- end -}}
{{- end -}}

View file

@ -5,6 +5,15 @@ Validate Service values
{{- $rootContext := .rootContext -}}
{{- $serviceObject := .object -}}
{{- $enabledControllers := (include "bjw-s.common.lib.controller.enabledControllers" (dict "rootContext" $rootContext) | fromYaml ) -}}
{{/* Verify automatic controller detection */}}
{{- if not (eq 1 (len $enabledControllers)) -}}
{{- if or (not (has "controller" (keys $serviceObject))) (empty (get $serviceObject "controller")) -}}
{{- fail (printf "controller field is required because automatic controller detection is not possible. (service: %s)" $serviceObject.identifier ) -}}
{{- end -}}
{{- end -}}
{{- if empty (get $serviceObject "controller") -}}
{{- fail (printf "controller field is required for Service. (service: %s)" $serviceObject.identifier) -}}
{{- end -}}
@ -29,13 +38,13 @@ Validate Service values
{{- $enabledPorts := include "bjw-s.common.lib.service.enabledPorts" (dict "rootContext" $rootContext "serviceObject" $serviceObject) | fromYaml }}
{{- /* Validate at least one port is enabled */ -}}
{{- if not $enabledPorts -}}
{{- fail (printf "no ports are enabled for Service with key \"%s\"" $serviceObject.identifier) -}}
{{- fail (printf "No ports are enabled for Service with this identifier. (service: '%s')" $serviceObject.identifier) -}}
{{- end -}}
{{- range $name, $port := $enabledPorts -}}
{{- /* Validate a port number is configured */ -}}
{{- if not $port.port -}}
{{- fail (printf "no port number is configured for port \"%s\" under Service with key \"%s\"" $name $serviceObject.identifier) -}}
{{- fail (printf "No port number is configured for this port. (port: '%s', service: '%s')" $name $serviceObject.identifier) -}}
{{- end -}}
{{- end -}}
{{- end -}}

View file

@ -1,30 +0,0 @@
{{/*
Convert Service values to an object
*/}}
{{- define "bjw-s.common.lib.service.valuesToObject" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $objectValues := .values -}}
{{- /* Determine and inject the Service name */ -}}
{{- $objectName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}}
{{- if $objectValues.nameOverride -}}
{{- $override := tpl $objectValues.nameOverride $rootContext -}}
{{- if not (eq $objectName $override) -}}
{{- $objectName = printf "%s-%s" $objectName $override -}}
{{- end -}}
{{- else -}}
{{- $enabledServices := (include "bjw-s.common.lib.service.enabledServices" (dict "rootContext" $rootContext) | fromYaml ) }}
{{- if and (not $objectValues.primary) (gt (len $enabledServices) 1) -}}
{{- if not (eq $objectName $identifier) -}}
{{- $objectName = printf "%s-%s" $objectName $identifier -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $_ := set $objectValues "name" $objectName -}}
{{- $_ := set $objectValues "identifier" $identifier -}}
{{- /* Return the Service object */ -}}
{{- $objectValues | toYaml -}}
{{- end -}}

View file

@ -0,0 +1,23 @@
{{/*
Return the enabled serviceAccounts.
*/}}
{{- define "bjw-s.common.lib.serviceAccount.enabledServiceAccounts" -}}
{{- $rootContext := .rootContext -}}
{{- $enabledServiceAccounts := dict -}}
{{- range $identifier, $serviceAccount := $rootContext.Values.serviceAccount -}}
{{- if kindIs "map" $serviceAccount -}}
{{- /* Enable Service by default, but allow override */ -}}
{{- $serviceAccountEnabled := true -}}
{{- if hasKey $serviceAccount "enabled" -}}
{{- $serviceAccountEnabled = $serviceAccount.enabled -}}
{{- end -}}
{{- if $serviceAccountEnabled -}}
{{- $_ := set $enabledServiceAccounts $identifier . -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $enabledServiceAccounts | toYaml -}}
{{- end -}}

View file

@ -4,18 +4,10 @@ Return a ServiceAccount Object by its Identifier.
{{- define "bjw-s.common.lib.serviceAccount.getByIdentifier" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- if eq $identifier "default" -}}
{{- $serviceAccount := deepCopy $rootContext.Values.serviceAccount -}}
{{- if and (eq ($serviceAccount.name) "") (not $serviceAccount.create ) -}}
{{- $_ := set $serviceAccount "name" "default" -}}
{{- end -}}
{{- include "bjw-s.common.lib.serviceAccount.valuesToObject" (dict "rootContext" $rootContext "id" "default" "values" $serviceAccount) -}}
{{- else -}}
{{- $serviceAccountValues := dig "extraServiceAccounts" $identifier nil $rootContext.Values.serviceAccount -}}
{{- if not (empty $serviceAccountValues) -}}
{{- include "bjw-s.common.lib.serviceAccount.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $serviceAccountValues) -}}
{{- else -}}
{{- fail (printf "No ServiceAccount configured with identifier: %s" $identifier) -}}
{{- end -}}
{{- $enabledServiceAccounts := (include "bjw-s.common.lib.serviceAccount.enabledServiceAccounts" (dict "rootContext" $rootContext) | fromYaml ) }}
{{- if (hasKey $enabledServiceAccounts $identifier) -}}
{{- $objectValues := get $enabledServiceAccounts $identifier -}}
{{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" (len $enabledServiceAccounts)) -}}
{{- end -}}
{{- end -}}

View file

@ -1,25 +0,0 @@
{{/*
Convert ServiceAccount values to an object
*/}}
{{- define "bjw-s.common.lib.serviceAccount.valuesToObject" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $objectValues := .values -}}
{{- /* Determine and inject the serviceAccount name */ -}}
{{- $defaultServiceAccountName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}}
{{- $objectName := $defaultServiceAccountName -}}
{{- with $objectValues.name -}}
{{- $objectName = . -}}
{{- end -}}
{{- if and (ne $identifier "default") (not $objectValues.name) -}}
{{- $objectName = printf "%s-%s" $defaultServiceAccountName $identifier -}}
{{- end -}}
{{- $_ := set $objectValues "name" $objectName -}}
{{- $_ := set $objectValues "identifier" $identifier -}}
{{- /* Return the serviceAccount object */ -}}
{{- $objectValues | toYaml -}}
{{- end -}}

View file

@ -1,20 +1,20 @@
{{/*
Return the enabled ServiceMonitors.
Return the enabled serviceMonitors.
*/}}
{{- define "bjw-s.common.lib.serviceMonitor.enabledServiceMonitors" -}}
{{- $rootContext := .rootContext -}}
{{- $enabledServiceMonitors := dict -}}
{{- range $name, $serviceMonitor := $rootContext.Values.serviceMonitor -}}
{{- range $identifier, $serviceMonitor := $rootContext.Values.serviceMonitor -}}
{{- if kindIs "map" $serviceMonitor -}}
{{- /* Enable by default, but allow override */ -}}
{{- /* Enable Service by default, but allow override */ -}}
{{- $serviceMonitorEnabled := true -}}
{{- if hasKey $serviceMonitor "enabled" -}}
{{- $serviceMonitorEnabled = $serviceMonitor.enabled -}}
{{- end -}}
{{- if $serviceMonitorEnabled -}}
{{- $_ := set $enabledServiceMonitors $name . -}}
{{- $_ := set $enabledServiceMonitors $identifier . -}}
{{- end -}}
{{- end -}}
{{- end -}}

View file

@ -0,0 +1,13 @@
{{/*
Return a ServiceMonitor Object by its Identifier.
*/}}
{{- define "bjw-s.common.lib.serviceMonitor.getByIdentifier" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $enabledServiceMonitors := (include "bjw-s.common.lib.serviceMonitor.enabledServiceMonitors" (dict "rootContext" $rootContext) | fromYaml ) }}
{{- if (hasKey $enabledServiceMonitors $identifier) -}}
{{- $objectValues := get $enabledServiceMonitors $identifier -}}
{{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" (len $enabledServiceMonitors)) -}}
{{- end -}}
{{- end -}}

View file

@ -1,30 +0,0 @@
{{/*
Convert ServiceMonitor values to an object
*/}}
{{- define "bjw-s.common.lib.serviceMonitor.valuesToObject" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $objectValues := .values -}}
{{- /* Determine and inject the ServiceMonitor name */ -}}
{{- $objectName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}}
{{- if $objectValues.nameOverride -}}
{{- $override := tpl $objectValues.nameOverride $rootContext -}}
{{- if not (eq $objectName $override) -}}
{{- $objectName = printf "%s-%s" $objectName $override -}}
{{- end -}}
{{- else -}}
{{- $enabledServiceMonitors := (include "bjw-s.common.lib.serviceMonitor.enabledServiceMonitors" (dict "rootContext" $rootContext) | fromYaml ) }}
{{- if gt (len $enabledServiceMonitors) 1 -}}
{{- if not (eq $objectName $identifier) -}}
{{- $objectName = printf "%s-%s" $objectName $identifier -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $_ := set $objectValues "name" $objectName -}}
{{- $_ := set $objectValues "identifier" $identifier -}}
{{- /* Return the ServiceMonitor object */ -}}
{{- $objectValues | toYaml -}}
{{- end -}}

View file

@ -5,10 +5,15 @@ Convert StatefulSet values to an object
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $objectValues := .values -}}
{{- $itemCount := .itemCount -}}
{{- $objectName := (include "bjw-s.common.lib.determineResourceNameFromValues" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" $itemCount)) -}}
{{- $_ := set $objectValues "name" $objectName -}}
{{- $_ := set $objectValues "identifier" $identifier -}}
{{- $strategy := default "RollingUpdate" $objectValues.strategy -}}
{{- $_ := set $objectValues "strategy" $strategy -}}
{{- /* Return the StatefulSet object */ -}}
{{- $objectValues | toYaml -}}
{{- end -}}

View file

@ -2,21 +2,23 @@
Secondary entrypoint and primary loader for the common chart
*/}}
{{- define "bjw-s.common.loader.generate" -}}
{{- $rootContext := $ -}}
{{- /* Run global chart validations */ -}}
{{- include "bjw-s.common.lib.chart.validate" . -}}
{{- include "bjw-s.common.lib.chart.validate" $rootContext -}}
{{- /* Build the templates */ -}}
{{- include "bjw-s.common.render.pvcs" . | nindent 0 -}}
{{- include "bjw-s.common.render.serviceAccount" . | nindent 0 -}}
{{- include "bjw-s.common.render.configMaps.fromFolder" . | nindent 0 -}}
{{- include "bjw-s.common.render.configMaps" . | nindent 0 -}}
{{- include "bjw-s.common.render.controllers" . | nindent 0 -}}
{{- include "bjw-s.common.render.services" . | nindent 0 -}}
{{- 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.secrets" . | nindent 0 -}}
{{- include "bjw-s.common.render.networkpolicies" . | nindent 0 -}}
{{- include "bjw-s.common.render.rawResources" . | nindent 0 -}}
{{- include "bjw-s.common.render.rbac" . | nindent 0 -}}
{{- include "bjw-s.common.render.pvcs" $rootContext | nindent 0 -}}
{{- include "bjw-s.common.render.serviceAccount" $rootContext | nindent 0 -}}
{{- include "bjw-s.common.render.configMaps.fromFolder" $rootContext | nindent 0 -}}
{{- include "bjw-s.common.render.configMaps" $rootContext | nindent 0 -}}
{{- include "bjw-s.common.render.controllers" $rootContext | nindent 0 -}}
{{- include "bjw-s.common.render.services" $rootContext | nindent 0 -}}
{{- include "bjw-s.common.render.ingresses" $rootContext | nindent 0 -}}
{{- include "bjw-s.common.render.serviceMonitors" $rootContext | nindent 0 -}}
{{- include "bjw-s.common.render.routes" $rootContext | nindent 0 -}}
{{- include "bjw-s.common.render.secrets" $rootContext | nindent 0 -}}
{{- include "bjw-s.common.render.networkpolicies" $rootContext | nindent 0 -}}
{{- include "bjw-s.common.render.rawResources" $rootContext | nindent 0 -}}
{{- include "bjw-s.common.render.rbac" $rootContext | nindent 0 -}}
{{- end -}}

View file

@ -4,25 +4,18 @@ Renders the configMap objects required by the chart.
{{- define "bjw-s.common.render.configMaps" -}}
{{- $rootContext := $ -}}
{{- /* Generate named configMaps as required */ -}}
{{- range $key, $configMap := .Values.configMaps }}
{{- /* Enable configMap by default, but allow override */ -}}
{{- $configMapEnabled := true -}}
{{- if hasKey $configMap "enabled" -}}
{{- $configMapEnabled = $configMap.enabled -}}
{{- end -}}
{{- /* Generate configMaps as required */ -}}
{{- $enabledConfigMaps := (include "bjw-s.common.lib.configMap.enabledConfigmaps" (dict "rootContext" $rootContext) | fromYaml ) -}}
{{- if $configMapEnabled -}}
{{- $configMapValues := (mustDeepCopy $configMap) -}}
{{- range $identifier := keys $enabledConfigMaps -}}
{{- /* Generate object from the raw configMap values */ -}}
{{- $configMapObject := (include "bjw-s.common.lib.configMap.getByIdentifier" (dict "rootContext" $rootContext "id" $identifier) | fromYaml) -}}
{{- /* Create object from the raw configMap values */ -}}
{{- $configMapObject := (include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $key "values" $configMapValues)) | fromYaml -}}
{{- /* Perform validations on the configMap before rendering */ -}}
{{- include "bjw-s.common.lib.configMap.validate" (dict "rootContext" $ "object" $configMapObject "id" $key) -}}
{{- /* Perform validations on the configMap before rendering */ -}}
{{- include "bjw-s.common.lib.configMap.validate" (dict "rootContext" $rootContext "object" $configMapObject "id" $identifier) -}}
{{/* Include the configMap class */}}
{{- include "bjw-s.common.class.configMap" (dict "rootContext" $ "object" $configMapObject) | nindent 0 -}}
{{- end -}}
{{- include "bjw-s.common.class.configMap" (dict "rootContext" $rootContext "object" $configMapObject) | nindent 0 -}}
{{- end -}}
{{- end -}}
@ -30,23 +23,26 @@ Renders the configMap objects required by the chart.
Renders configMap objects required by the chart from a folder in the repo's path.
*/}}
{{- define "bjw-s.common.render.configMaps.fromFolder" -}}
{{- $rootContext := $ -}}
{{- $valuesCopy := .Values -}}
{{- $configMapsFromFolder := .Values.configMapsFromFolder | default dict -}}
{{- $valuesCopy := $rootContext.Values -}}
{{- $configMapsFromFolder := $rootContext.Values.configMapsFromFolder | default dict -}}
{{- $configMapsFromFolderEnabled := dig "enabled" false $configMapsFromFolder -}}
{{- if $configMapsFromFolderEnabled -}}
{{- /* Perform validations before rendering */ -}}
{{- include "bjw-s.common.lib.configMap.fromFolder.validate" (dict "rootContext" $ "basePath" $configMapsFromFolder.basePath) -}}
{{- $basePath := $configMapsFromFolder.basePath -}}
{{/* Generate a list of unique top level folders */}}
{{ $topLevelFolders := dict}}
{{- $basePath := $configMapsFromFolder.basePath -}}
{{- $topLevelFolders := dict -}}
{{- range $path, $_ := .Files.Glob (printf "%s/*/*" $basePath) -}}
{{- $_ := set $topLevelFolders (dir $path) "" -}}
{{- end -}}
{{- $top_level_folder_list := keys $topLevelFolders | sortAlpha -}}
{{/* Iterate over the top level folders */}}
{{ range $path := $top_level_folder_list }}
{{- /* Iterate over the top level folders */ -}}
{{- range $path := $top_level_folder_list -}}
{{- $folder := base $path -}}
{{- $configMapData := dict -}}
{{- $configMapBinaryData := dict -}}
@ -70,16 +66,16 @@ Renders configMap objects required by the chart from a folder in the repo's path
{{- $configMapData = merge $configMapData (dict $file $fileContent) -}}
{{- end -}}
{{- end -}}
{{ end }}
{{- end -}}
{{- $configMapValues := dict "enabled" true "forceRename" $configMapForceRename "labels" $configMapLabels "annotations" $configMapAnnotations "data" $configMapData "binaryData" $configMapBinaryData -}}
{{- $configMapObject := (include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $ "id" $folder "values" $configMapValues)) | fromYaml -}}
{{/* Append it to .Values.configMaps so it can be created by "bjw-s.common.render.configMaps" and fetched by identifier */}}
{{- $existingConfigMaps := (get $valuesCopy "configMaps"| default dict) -}}
{{- $mergedConfigMaps := deepCopy $existingConfigMaps | merge (dict (base $path) $configMapValues) -}}
{{- $valuesCopy := merge $valuesCopy (dict "configMaps" $mergedConfigMaps) -}}
{{ end }}
{{ end }}
{{- $configMapObject := (include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $folder "values" $configMapValues) | fromYaml) -}}
{{ end }}
{{- /* Append it to .Values.configMaps so it can be created by "bjw-s.common.render.configMaps" and fetched by identifier */ -}}
{{- $existingConfigMaps := (get $valuesCopy "configMaps" | default dict) -}}
{{- $mergedConfigMaps := deepCopy $existingConfigMaps | merge (dict $folder $configMapObject) -}}
{{- $valuesCopy := merge $valuesCopy (dict "configMaps" $mergedConfigMaps) -}}
{{- end -}}
{{- end -}}
{{- end -}}

View file

@ -5,43 +5,38 @@ Renders the controller objects required by the chart.
{{- $rootContext := $ -}}
{{- /* Generate named controller objects as required */ -}}
{{- range $key, $controller := .Values.controllers -}}
{{- /* Enable controller by default, but allow override */ -}}
{{- $controllerEnabled := true -}}
{{- if hasKey $controller "enabled" -}}
{{- $controllerEnabled = $controller.enabled -}}
{{- end -}}
{{- $enabledControllers := (include "bjw-s.common.lib.controller.enabledControllers" (dict "rootContext" $rootContext) | fromYaml ) -}}
{{- range $identifier := keys $enabledControllers -}}
{{- /* Create object from the raw controller values */ -}}
{{- $controllerObject := (include "bjw-s.common.lib.controller.getByIdentifier" (dict "rootContext" $rootContext "id" $identifier) | fromYaml) -}}
{{- if $controllerEnabled -}}
{{- $controllerValues := $controller -}}
{{- /* Perform validations on the controller before rendering */ -}}
{{- include "bjw-s.common.lib.controller.validate" (dict "rootContext" $rootContext "object" $controllerObject) -}}
{{- /* Create object from the raw controller values */ -}}
{{- $controllerObject := (include "bjw-s.common.lib.controller.valuesToObject" (dict "rootContext" $rootContext "id" $key "values" $controllerValues)) | fromYaml -}}
{{- if eq $controllerObject.type "deployment" -}}
{{- $deploymentObject := (include "bjw-s.common.lib.deployment.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $controllerObject "itemCount" (len $enabledControllers))) | fromYaml -}}
{{- include "bjw-s.common.lib.deployment.validate" (dict "rootContext" $rootContext "object" $deploymentObject) -}}
{{- include "bjw-s.common.class.deployment" (dict "rootContext" $rootContext "object" $deploymentObject) | nindent 0 -}}
{{- /* Perform validations on the controller before rendering */ -}}
{{- include "bjw-s.common.lib.controller.validate" (dict "rootContext" $rootContext "object" $controllerObject) -}}
{{- else if eq $controllerObject.type "cronjob" -}}
{{- $cronjobObject := (include "bjw-s.common.lib.cronjob.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $controllerObject "itemCount" (len $enabledControllers))) | fromYaml -}}
{{- include "bjw-s.common.lib.cronjob.validate" (dict "rootContext" $rootContext "object" $cronjobObject) -}}
{{- include "bjw-s.common.class.cronjob" (dict "rootContext" $rootContext "object" $cronjobObject) | nindent 0 -}}
{{- if eq $controllerObject.type "deployment" -}}
{{- $deploymentObject := (include "bjw-s.common.lib.deployment.valuesToObject" (dict "rootContext" $rootContext "id" $key "values" $controllerObject)) | fromYaml -}}
{{- include "bjw-s.common.lib.deployment.validate" (dict "rootContext" $rootContext "object" $deploymentObject) -}}
{{- include "bjw-s.common.class.deployment" (dict "rootContext" $rootContext "object" $deploymentObject) | nindent 0 -}}
{{- else if eq $controllerObject.type "cronjob" -}}
{{- $cronjobObject := (include "bjw-s.common.lib.cronjob.valuesToObject" (dict "rootContext" $rootContext "id" $key "values" $controllerObject)) | fromYaml -}}
{{- include "bjw-s.common.lib.cronjob.validate" (dict "rootContext" $rootContext "object" $cronjobObject) -}}
{{- include "bjw-s.common.class.cronjob" (dict "rootContext" $rootContext "object" $cronjobObject) | nindent 0 -}}
{{- else if eq $controllerObject.type "daemonset" -}}
{{- $daemonsetObject := (include "bjw-s.common.lib.daemonset.valuesToObject" (dict "rootContext" $rootContext "id" $key "values" $controllerObject)) | fromYaml -}}
{{- include "bjw-s.common.lib.daemonset.validate" (dict "rootContext" $rootContext "object" $daemonsetObject) -}}
{{- include "bjw-s.common.class.daemonset" (dict "rootContext" $rootContext "object" $daemonsetObject) | nindent 0 -}}
{{- else if eq $controllerObject.type "statefulset" -}}
{{- $statefulsetObject := (include "bjw-s.common.lib.statefulset.valuesToObject" (dict "rootContext" $rootContext "id" $key "values" $controllerObject)) | fromYaml -}}
{{- include "bjw-s.common.lib.statefulset.validate" (dict "rootContext" $rootContext "object" $statefulsetObject) -}}
{{- include "bjw-s.common.class.statefulset" (dict "rootContext" $rootContext "object" $statefulsetObject) | nindent 0 -}}
{{- else if eq $controllerObject.type "job" -}}
{{- $jobObject := (include "bjw-s.common.lib.job.valuesToObject" (dict "rootContext" $rootContext "id" $key "values" $controllerObject)) | fromYaml -}}
{{- include "bjw-s.common.lib.job.validate" (dict "rootContext" $rootContext "object" $jobObject) -}}
{{- include "bjw-s.common.class.job" (dict "rootContext" $rootContext "object" $jobObject) | nindent 0 -}}
{{- end -}}
{{- else if eq $controllerObject.type "daemonset" -}}
{{- $daemonsetObject := (include "bjw-s.common.lib.daemonset.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $controllerObject "itemCount" (len $enabledControllers))) | fromYaml -}}
{{- include "bjw-s.common.lib.daemonset.validate" (dict "rootContext" $rootContext "object" $daemonsetObject) -}}
{{- include "bjw-s.common.class.daemonset" (dict "rootContext" $rootContext "object" $daemonsetObject) | nindent 0 -}}
{{- else if eq $controllerObject.type "statefulset" -}}
{{- $statefulsetObject := (include "bjw-s.common.lib.statefulset.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $controllerObject "itemCount" (len $enabledControllers))) | fromYaml -}}
{{- include "bjw-s.common.lib.statefulset.validate" (dict "rootContext" $rootContext "object" $statefulsetObject) -}}
{{- include "bjw-s.common.class.statefulset" (dict "rootContext" $rootContext "object" $statefulsetObject) | nindent 0 -}}
{{- else if eq $controllerObject.type "job" -}}
{{- $jobObject := (include "bjw-s.common.lib.job.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $controllerObject "itemCount" (len $enabledControllers))) | fromYaml -}}
{{- include "bjw-s.common.lib.job.validate" (dict "rootContext" $rootContext "object" $jobObject) -}}
{{- include "bjw-s.common.class.job" (dict "rootContext" $rootContext "object" $jobObject) | nindent 0 -}}
{{- end -}}
{{- end -}}
{{- end -}}

View file

@ -2,25 +2,18 @@
Renders the Ingress objects required by the chart.
*/}}
{{- define "bjw-s.common.render.ingresses" -}}
{{- /* Generate named Ingresses as required */ -}}
{{- range $key, $ingress := .Values.ingress }}
{{- /* Enable Ingress by default, but allow override */ -}}
{{- $ingressEnabled := true -}}
{{- if hasKey $ingress "enabled" -}}
{{- $ingressEnabled = $ingress.enabled -}}
{{- end -}}
{{- $rootContext := $ -}}
{{- if $ingressEnabled -}}
{{- $ingressValues := (mustDeepCopy $ingress) -}}
{{- /* Generate Ingresses as required */ -}}
{{- $enabledIngresses := (include "bjw-s.common.lib.ingress.enabledIngresses" (dict "rootContext" $rootContext) | fromYaml ) -}}
{{- range $identifier := keys $enabledIngresses -}}
{{- /* Generate object from the raw persistence values */ -}}
{{- $ingressObject := (include "bjw-s.common.lib.ingress.getByIdentifier" (dict "rootContext" $rootContext "id" $identifier) | fromYaml) -}}
{{- /* Create object from the raw ingress values */ -}}
{{- $ingressObject := (include "bjw-s.common.lib.ingress.valuesToObject" (dict "rootContext" $ "id" $key "values" $ingressValues)) | fromYaml -}}
{{- /* Perform validations on the Ingress before rendering */ -}}
{{- include "bjw-s.common.lib.ingress.validate" (dict "rootContext" $rootContext "object" $ingressObject) -}}
{{- /* Perform validations on the ingress before rendering */ -}}
{{- include "bjw-s.common.lib.ingress.validate" (dict "rootContext" $ "object" $ingressObject) -}}
{{/* Include the ingress class */}}
{{- include "bjw-s.common.class.ingress" (dict "rootContext" $ "object" $ingressObject) | nindent 0 -}}
{{- end -}}
{{- /* Include the ingress class */ -}}
{{- include "bjw-s.common.class.ingress" (dict "rootContext" $ "object" $ingressObject) | nindent 0 -}}
{{- end -}}
{{- end -}}

View file

@ -2,25 +2,18 @@
Renders the networkPolicy objects required by the chart.
*/}}
{{- define "bjw-s.common.render.networkpolicies" -}}
{{- /* Generate named networkPolicy as required */ -}}
{{- range $key, $networkPolicy := .Values.networkpolicies }}
{{- /* Enable networkPolicy by default, but allow override */ -}}
{{- $networkPolicyEnabled := true -}}
{{- if hasKey $networkPolicy "enabled" -}}
{{- $networkPolicyEnabled = $networkPolicy.enabled -}}
{{- end -}}
{{- $rootContext := $ -}}
{{- if $networkPolicyEnabled -}}
{{- $networkPolicyValues := (mustDeepCopy $networkPolicy) -}}
{{- /* Generate networkPolicy as required */ -}}
{{- $enabledNetworkPolicies := (include "bjw-s.common.lib.networkpolicy.enabledNetworkPolicies" (dict "rootContext" $rootContext) | fromYaml ) -}}
{{- range $identifier := keys $enabledNetworkPolicies -}}
{{- /* Generate object from the raw persistence values */ -}}
{{- $networkPolicyObject := (include "bjw-s.common.lib.networkpolicy.getByIdentifier" (dict "rootContext" $rootContext "id" $identifier) | fromYaml) -}}
{{- /* Create object from the raw networkPolicy values */ -}}
{{- $networkPolicyObject := (include "bjw-s.common.lib.networkpolicy.valuesToObject" (dict "rootContext" $ "id" $key "values" $networkPolicyValues)) | fromYaml -}}
{{- /* Perform validations on the networkPolicy before rendering */ -}}
{{- include "bjw-s.common.lib.networkpolicy.validate" (dict "rootContext" $ "object" $networkPolicyObject) -}}
{{- /* Perform validations on the networkPolicy before rendering */ -}}
{{- include "bjw-s.common.lib.networkpolicy.validate" (dict "rootContext" $ "object" $networkPolicyObject) -}}
{{/* Include the networkPolicy class */}}
{{- include "bjw-s.common.class.networkpolicy" (dict "rootContext" $ "object" $networkPolicyObject) | nindent 0 -}}
{{- end -}}
{{- /* Include the networkPolicy class */ -}}
{{- include "bjw-s.common.class.networkpolicy" (dict "rootContext" $ "object" $networkPolicyObject) | nindent 0 -}}
{{- end -}}
{{- end -}}

View file

@ -1,26 +1,16 @@
{{/*
Renders the Persistent Volume Claim objects required by the chart.
Renders the Persistent Volume Claim objects required by the chart
*/}}
{{- define "bjw-s.common.render.pvcs" -}}
{{- $rootContext := $ -}}
{{- /* Generate pvc as required */ -}}
{{- range $key, $pvc := .Values.persistence -}}
{{- /* Enable PVC by default, but allow override */ -}}
{{- $pvcEnabled := true -}}
{{- if hasKey $pvc "enabled" -}}
{{- $pvcEnabled = $pvc.enabled -}}
{{- end -}}
{{- $enabledPVCs := (include "bjw-s.common.lib.pvc.enabledPVCs" (dict "rootContext" $rootContext) | fromYaml ) -}}
{{- range $identifier := keys $enabledPVCs -}}
{{- /* Generate object from the raw persistence values */ -}}
{{- $pvcObject := (include "bjw-s.common.lib.pvc.getByIdentifier" (dict "rootContext" $rootContext "id" $identifier) | fromYaml) -}}
{{- if and $pvcEnabled (eq (default "persistentVolumeClaim" $pvc.type) "persistentVolumeClaim") (not $pvc.existingClaim) -}}
{{- $pvcValues := (mustDeepCopy $pvc) -}}
{{- /* Create object from the raw PVC values */ -}}
{{- $pvcObject := (include "bjw-s.common.lib.pvc.valuesToObject" (dict "rootContext" $ "id" $key "values" $pvcValues)) | fromYaml -}}
{{- /* Perform validations on the PVC before rendering */ -}}
{{- include "bjw-s.common.lib.pvc.validate" (dict "rootContext" $ "object" $pvcValues) -}}
{{- /* Include the PVC class */ -}}
{{- include "bjw-s.common.class.pvc" (dict "rootContext" $ "object" $pvcValues) | nindent 0 -}}
{{- end -}}
{{- /* Include the PVC class */ -}}
{{- include "bjw-s.common.class.pvc" (dict "rootContext" $rootContext "object" $pvcObject) | nindent 0 -}}
{{- end -}}
{{- end -}}

View file

@ -5,24 +5,12 @@ Renders other arbirtrary objects required by the chart.
{{- $rootContext := $ -}}
{{- /* Generate raw resources as required */ -}}
{{- range $key, $resource := .Values.rawResources -}}
{{- /* Enable by default, but allow override */ -}}
{{- $resourceEnabled := true -}}
{{- if hasKey $resource "enabled" -}}
{{- $resourceEnabled = $resource.enabled -}}
{{- end -}}
{{- $enabledRawResources := (include "bjw-s.common.lib.rawResource.enabledRawResources" (dict "rootContext" $rootContext) | fromYaml ) -}}
{{- range $identifier := keys $enabledRawResources -}}
{{- /* Generate object from the raw resource values */ -}}
{{- $rawResourceObject := (include "bjw-s.common.lib.rawResource.getByIdentifier" (dict "rootContext" $rootContext "id" $identifier) | fromYaml) -}}
{{- if $resourceEnabled -}}
{{- $resourceValues := (mustDeepCopy $resource) -}}
{{- /* Create object from the raw resource values */ -}}
{{- $resourceObject := (include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $key "values" $resourceValues)) | fromYaml -}}
{{- /* Perform validations on the resource before rendering */ -}}
{{- include "bjw-s.common.lib.rawResource.validate" (dict "rootContext" $ "object" $resourceValues) -}}
{{- /* Include the raw resource class */ -}}
{{- include "bjw-s.common.class.rawResource" (dict "rootContext" $ "object" $resourceValues) | nindent 0 -}}
{{- end -}}
{{- /* Include the raw resource class */ -}}
{{- include "bjw-s.common.class.rawResource" (dict "rootContext" $rootContext "object" $rawResourceObject) | nindent 0 -}}
{{- end -}}
{{- end -}}

View file

@ -4,9 +4,7 @@ Renders RBAC objects required by the chart.
{{- define "bjw-s.common.render.rbac" -}}
{{- $rootContext := . -}}
{{- include "bjw-s.common.render.rbac.roles" (dict "rootContext" $rootContext) -}}
{{- include "bjw-s.common.render.rbac.roleBindings" (dict "rootContext" $rootContext) -}}
{{ end }}
{{/*
@ -14,27 +12,16 @@ Renders RBAC Role objects required by the chart.
*/}}
{{- define "bjw-s.common.render.rbac.roles" -}}
{{- $rootContext := .rootContext -}}
{{- /* Generate named Roles as required */ -}}
{{- range $key, $role := $rootContext.Values.rbac.roles }}
{{- /* Enable role by default, but allow override */ -}}
{{- $roleEnabled := true -}}
{{- if hasKey $role "enabled" -}}
{{- $roleEnabled = $role.enabled -}}
{{- end -}}
{{- $enabledRoles := (include "bjw-s.common.lib.rbac.role.enabledRoles" (dict "rootContext" $rootContext) | fromYaml ) -}}
{{- range $identifier := keys $enabledRoles -}}
{{- /* Generate object from the raw role values */ -}}
{{- $roleObject := (include "bjw-s.common.lib.rbac.role.getByIdentifier" (dict "rootContext" $rootContext "id" $identifier) | fromYaml) -}}
{{- if $roleEnabled -}}
{{- $roleValues := (mustDeepCopy $role) -}}
{{- /* Perform validations on the role before rendering */ -}}
{{- include "bjw-s.common.lib.rbac.role.validate" (dict "rootContext" $rootContext "object" $roleObject) -}}
{{- /* Create object from the raw role values */ -}}
{{- $roleObject := (include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $key "values" $roleValues)) | fromYaml -}}
{{- /* Perform validations on the role before rendering */ -}}
{{- include "bjw-s.common.lib.rbac.role.validate" (dict "rootContext" $rootContext "object" $roleObject) -}}
{{/* Include the role class */}}
{{- include "bjw-s.common.class.rbac.Role" (dict "rootContext" $rootContext "object" $roleObject) | nindent 0 -}}
{{- end -}}
{{/* Include the role class */}}
{{- include "bjw-s.common.class.rbac.Role" (dict "rootContext" $rootContext "object" $roleObject) | nindent 0 -}}
{{- end -}}
{{- end -}}
@ -43,25 +30,12 @@ Renders RBAC RoleBinding objects required by the chart.
*/}}
{{- define "bjw-s.common.render.rbac.roleBindings" -}}
{{- $rootContext := .rootContext -}}
{{- range $key, $roleBinding := $rootContext.Values.rbac.bindings }}
{{- /* Enable RoleBinding by default, but allow override */ -}}
{{- $roleBindingEnabled := true -}}
{{- if hasKey $roleBinding "enabled" -}}
{{- $roleBindingEnabled = $roleBinding.enabled -}}
{{- end -}}
{{- $enabledRoleBindings := (include "bjw-s.common.lib.rbac.roleBinding.enabledRoleBindings" (dict "rootContext" $rootContext) | fromYaml ) -}}
{{- range $identifier := keys $enabledRoleBindings -}}
{{- /* Generate object from the raw role values */ -}}
{{- $roleBindingObject := (include "bjw-s.common.lib.rbac.roleBinding.getByIdentifier" (dict "rootContext" $rootContext "id" $identifier) | fromYaml) -}}
{{- if $roleBindingEnabled -}}
{{- $roleBindingValues := (mustDeepCopy $roleBinding) -}}
{{- /* Create object from the raw RoleBinding values */ -}}
{{- $roleBindingObject := (include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $key "values" $roleBindingValues)) | fromYaml -}}
{{- /* Perform validations on the RoleBinding before rendering */ -}}
{{- include "bjw-s.common.lib.rbac.roleBinding.validate" (dict "rootContext" $rootContext "object" $roleBindingObject) -}}
{{/* Include the RoleBinding class */}}
{{- include "bjw-s.common.class.rbac.roleBinding" (dict "rootContext" $rootContext "object" $roleBindingObject) | nindent 0 -}}
{{- end -}}
{{/* Include the RoleBinding class */}}
{{- include "bjw-s.common.class.rbac.roleBinding" (dict "rootContext" $rootContext "object" $roleBindingObject) | nindent 0 -}}
{{- end -}}
{{- end -}}

View file

@ -2,18 +2,18 @@
Renders the Route objects required by the chart
*/}}
{{- define "bjw-s.common.render.routes" -}}
{{- /* Generate named routes as required */ -}}
{{- $enabledRoutes := (include "bjw-s.common.lib.route.enabledRoutes" (dict "rootContext" $) | fromYaml ) -}}
{{- range $key, $route := $enabledRoutes -}}
{{- $routeValues := (mustDeepCopy $route) -}}
{{- $rootContext := $ -}}
{{- /* Create object from the raw Route values */ -}}
{{- $routeObject := (include "bjw-s.common.lib.route.valuesToObject" (dict "rootContext" $ "id" $key "values" $routeValues)) | fromYaml -}}
{{- /* Generate named routes as required */ -}}
{{- $enabledRoutes := (include "bjw-s.common.lib.route.enabledRoutes" (dict "rootContext" $rootContext) | fromYaml ) -}}
{{- range $identifier := keys $enabledRoutes -}}
{{- /* Generate object from the raw route values */ -}}
{{- $routeObject := (include "bjw-s.common.lib.route.getByIdentifier" (dict "rootContext" $rootContext "id" $identifier) | fromYaml) -}}
{{- /* Perform validations on the Route before rendering */ -}}
{{- include "bjw-s.common.lib.route.validate" (dict "rootContext" $ "object" $routeObject) -}}
{{- include "bjw-s.common.lib.route.validate" (dict "rootContext" $rootContext "object" $routeObject) -}}
{{- /* Include the Route class */ -}}
{{- include "bjw-s.common.class.route" (dict "rootContext" $ "object" $routeObject) | nindent 0 -}}
{{- include "bjw-s.common.class.route" (dict "rootContext" $rootContext "object" $routeObject) | nindent 0 -}}
{{- end -}}
{{- end -}}

View file

@ -5,24 +5,13 @@ Renders the Secret objects required by the chart.
{{- $rootContext := $ -}}
{{- /* Generate named Secrets as required */ -}}
{{- range $key, $secret := .Values.secrets }}
{{- /* Enable Secret by default, but allow override */ -}}
{{- $secretEnabled := true -}}
{{- if hasKey $secret "enabled" -}}
{{- $secretEnabled = $secret.enabled -}}
{{- end -}}
{{- $enabledSecrets := (include "bjw-s.common.lib.secret.enabledSecrets" (dict "rootContext" $rootContext) | fromYaml ) -}}
{{- if $secretEnabled -}}
{{- $secretValues := (mustDeepCopy $secret) -}}
{{- range $identifier := keys $enabledSecrets -}}
{{- /* Generate object from the raw secret values */ -}}
{{- $secretObject := (include "bjw-s.common.lib.secret.getByIdentifier" (dict "rootContext" $rootContext "id" $identifier) | fromYaml) -}}
{{- /* Create object from the raw Secret values */ -}}
{{- $secretObject := (include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $key "values" $secretValues)) | fromYaml -}}
{{- /* Perform validations on the Secret before rendering */ -}}
{{- include "bjw-s.common.lib.secret.validate" (dict "rootContext" $ "object" $secretObject) -}}
{{/* Include the Secret class */}}
{{- include "bjw-s.common.class.secret" (dict "rootContext" $ "object" $secretObject) | nindent 0 -}}
{{- end -}}
{{- /* Include the Secret class */ -}}
{{- include "bjw-s.common.class.secret" (dict "rootContext" $rootContext "object" $secretObject) | nindent 0 -}}
{{- end -}}
{{- end -}}

View file

@ -1,26 +1,19 @@
{{/*
Renders the serviceMonitor objects required by the chart.
Renders the serviceMonitor object required by the chart.
*/}}
{{- define "bjw-s.common.render.serviceMonitors" -}}
{{- $rootContext := $ -}}
{{- /* Generate named serviceMonitors as required */ -}}
{{- range $key, $serviceMonitor := .Values.serviceMonitor -}}
{{- /* Enable ServiceMonitor by default, but allow override */ -}}
{{- $serviceMonitorEnabled := true -}}
{{- if hasKey $serviceMonitor "enabled" -}}
{{- $serviceMonitorEnabled = $serviceMonitor.enabled -}}
{{- end -}}
{{- $enabledServiceMonitors := (include "bjw-s.common.lib.serviceMonitor.enabledServiceMonitors" (dict "rootContext" $rootContext) | fromYaml ) -}}
{{- range $identifier := keys $enabledServiceMonitors -}}
{{- /* Generate object from the raw serviceMonitor values */ -}}
{{- $serviceMonitorObject := (include "bjw-s.common.lib.serviceMonitor.getByIdentifier" (dict "rootContext" $rootContext "id" $identifier) | fromYaml) -}}
{{- if $serviceMonitorEnabled -}}
{{- $serviceMonitorValues := (mustDeepCopy $serviceMonitor) -}}
{{- /* Perform validations on the ServiceMonitor before rendering */ -}}
{{- include "bjw-s.common.lib.serviceMonitor.validate" (dict "rootContext" $rootContext "object" $serviceMonitorObject) -}}
{{- /* Create object from the raw ServiceMonitor values */ -}}
{{- $serviceMonitorObject := (include "bjw-s.common.lib.serviceMonitor.valuesToObject" (dict "rootContext" $ "id" $key "values" $serviceMonitorValues)) | fromYaml -}}
{{- /* Perform validations on the serviceMonitor before rendering */ -}}
{{- include "bjw-s.common.lib.serviceMonitor.validate" (dict "rootContext" $ "object" $serviceMonitorObject) -}}
{{/* Include the serviceMonitor class */}}
{{- include "bjw-s.common.class.serviceMonitor" (dict "rootContext" $ "object" $serviceMonitorObject) | nindent 0 -}}
{{- end -}}
{{- /* Include the ServiceMonitor class */ -}}
{{- include "bjw-s.common.class.serviceMonitor" (dict "rootContext" $rootContext "object" $serviceMonitorObject) | nindent 0 -}}
{{- end -}}
{{- end -}}

View file

@ -2,48 +2,23 @@
Renders the serviceAccount object required by the chart.
*/}}
{{- define "bjw-s.common.render.serviceAccount" -}}
{{- if .Values.serviceAccount.create -}}
{{- $serviceAccountValues := (mustDeepCopy .Values.serviceAccount) -}}
{{- $rootContext := $ -}}
{{- /* Create object from the raw ServiceAccount values */ -}}
{{- $serviceAccountObject := (include "bjw-s.common.lib.serviceAccount.valuesToObject" (dict "rootContext" $ "id" "default" "values" $serviceAccountValues)) | fromYaml -}}
{{- /* Generate named serviceAccounts as required */ -}}
{{- $enabledServiceAccounts := (include "bjw-s.common.lib.serviceAccount.enabledServiceAccounts" (dict "rootContext" $rootContext) | fromYaml ) -}}
{{- range $identifier := keys $enabledServiceAccounts -}}
{{- /* Generate object from the raw serviceAccount values */ -}}
{{- $serviceAccountObject := (include "bjw-s.common.lib.serviceAccount.getByIdentifier" (dict "rootContext" $rootContext "id" $identifier) | fromYaml) -}}
{{- /* Perform validations on the ServiceAccount before rendering */ -}}
{{- include "bjw-s.common.lib.serviceAccount.validate" (dict "rootContext" $ "object" $serviceAccountObject) -}}
{{- include "bjw-s.common.lib.serviceAccount.validate" (dict "rootContext" $rootContext "object" $serviceAccountObject) -}}
{{- /* Create a service account secret */ -}}
{{- $_ := set .Values.secrets (printf "%s-sa-token" $serviceAccountObject.identifier) (dict "enabled" true "annotations" (dict "kubernetes.io/service-account.name" $serviceAccountObject.name) "type" "kubernetes.io/service-account-token") -}}
{{/* Include the serviceAccount class */}}
{{- include "bjw-s.common.class.serviceAccount" (dict "rootContext" $ "object" $serviceAccountObject) | nindent 0 -}}
{{- end -}}
{{- /* Generate named serviceAccount objects as required */ -}}
{{- with .Values.serviceAccount.extraServiceAccounts -}}
{{- range $key, $serviceAccount := . -}}
{{- $serviceAccountEnabled := true -}}
{{- if hasKey $serviceAccount "create" -}}
{{- $serviceAccountEnabled = $serviceAccount.create -}}
{{- end -}}
{{- if $serviceAccountEnabled -}}
{{- $serviceAccountValues := $serviceAccount -}}
{{- /* Create object from the raw ServiceAccount values */ -}}
{{- $serviceAccountObject := (include "bjw-s.common.lib.serviceAccount.valuesToObject" (dict "rootContext" $ "id" $key "values" $serviceAccountValues)) | fromYaml -}}
{{- /* Perform validations on the ServiceAccount before rendering */ -}}
{{- include "bjw-s.common.lib.serviceAccount.validate" (dict "rootContext" $ "object" $serviceAccountObject) -}}
{{- /* Create a service account secret */ -}}
{{- $_ := set $.Values.secrets (printf "%s-sa-token" $serviceAccountObject.identifier) (dict "enabled" true "annotations" (dict "kubernetes.io/service-account.name" $serviceAccountObject.name) "type" "kubernetes.io/service-account-token") -}}
{{/* Include the serviceAccount class */}}
{{- include "bjw-s.common.class.serviceAccount" (dict "rootContext" $ "object" $serviceAccountObject) | nindent 0 -}}
{{- end -}}
{{- if $serviceAccountObject.staticToken -}}
{{- $_ := set $rootContext.Values.secrets (printf "%s-sa-token" $serviceAccountObject.identifier) (dict "suffix" (printf "%s-sa-token" $serviceAccountObject.identifier) "annotations" (dict "kubernetes.io/service-account.name" $serviceAccountObject.name) "type" "kubernetes.io/service-account-token") -}}
{{- end -}}
{{- end -}}
{{- /* Include the ServiceAccount class */ -}}
{{- include "bjw-s.common.class.serviceAccount" (dict "rootContext" $rootContext "object" $serviceAccountObject) | nindent 0 -}}
{{- end -}}
{{- end -}}

View file

@ -2,18 +2,18 @@
Renders the Service objects required by the chart.
*/}}
{{- define "bjw-s.common.render.services" -}}
{{- /* Generate named Services as required */ -}}
{{- $enabledServices := (include "bjw-s.common.lib.service.enabledServices" (dict "rootContext" $) | fromYaml ) -}}
{{- range $key, $svc := $enabledServices -}}
{{- $serviceValues := (mustDeepCopy $svc) -}}
{{- $rootContext := $ -}}
{{- /* Create object from the raw Service values */ -}}
{{- $serviceObject := (include "bjw-s.common.lib.service.valuesToObject" (dict "rootContext" $ "id" $key "values" $serviceValues)) | fromYaml -}}
{{- /* Generate named Services as required */ -}}
{{- $enabledServices := (include "bjw-s.common.lib.service.enabledServices" (dict "rootContext" $rootContext) | fromYaml ) -}}
{{- range $identifier := keys $enabledServices -}}
{{- /* Generate object from the raw service values */ -}}
{{- $serviceObject := (include "bjw-s.common.lib.service.getByIdentifier" (dict "rootContext" $rootContext "id" $identifier) | fromYaml) -}}
{{- /* Perform validations on the Service before rendering */ -}}
{{- include "bjw-s.common.lib.service.validate" (dict "rootContext" $ "object" $serviceObject) -}}
{{- include "bjw-s.common.lib.service.validate" (dict "rootContext" $rootContext "object" $serviceObject) -}}
{{- /* Include the Service class */ -}}
{{- include "bjw-s.common.class.service" (dict "rootContext" $ "object" $serviceObject) | nindent 0 -}}
{{- include "bjw-s.common.class.service" (dict "rootContext" $rootContext "object" $serviceObject) | nindent 0 -}}
{{- end -}}
{{- end -}}