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

@ -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 -}}