feat(common): Release version 2.0.0-beta.1 (#173)

This commit is contained in:
Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs 2023-09-13 11:24:23 +02:00 committed by GitHub
parent 19767d668c
commit 7b6ee00be6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
189 changed files with 3110 additions and 3023 deletions

View file

@ -1,10 +1,9 @@
{{/* Expand the name of the chart */}}
{{- define "bjw-s.common.lib.chart.names.name" -}}
{{- $globalNameOverride := "" -}}
{{- if hasKey .Values "global" -}}
{{- $globalNameOverride = (default $globalNameOverride .Values.global.nameOverride) -}}
{{- end -}}
{{- default .Chart.Name (default .Values.nameOverride $globalNameOverride) | trunc 63 | trimSuffix "-" -}}
{{- $globalNameOverride := get .Values.global "nameOverride" -}}
{{- $nameOverride := get .Values "nameOverride" -}}
{{- $name := $globalNameOverride | default $nameOverride | default .Chart.Name -}}
{{- $name | toString | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/*
@ -14,12 +13,11 @@ If release name contains chart name it will be used as a full name.
*/}}
{{- define "bjw-s.common.lib.chart.names.fullname" -}}
{{- $name := include "bjw-s.common.lib.chart.names.name" . -}}
{{- $globalFullNameOverride := "" -}}
{{- if hasKey .Values "global" -}}
{{- $globalFullNameOverride = (default $globalFullNameOverride .Values.global.fullnameOverride) -}}
{{- end -}}
{{- if or .Values.fullnameOverride $globalFullNameOverride -}}
{{- $name = default .Values.fullnameOverride $globalFullNameOverride -}}
{{- $globalFullNameOverride := get .Values.global "fullnameOverride" -}}
{{- $fullNameOverride := get .Values "fullnameOverride" -}}
{{- if or $fullNameOverride $globalFullNameOverride -}}
{{- $name = ($globalFullNameOverride | default $fullNameOverride) -}}
{{- else -}}
{{- if contains $name .Release.Name -}}
{{- $name = .Release.Name -}}
@ -27,19 +25,11 @@ If release name contains chart name it will be used as a full name.
{{- $name = printf "%s-%s" .Release.Name $name -}}
{{- end -}}
{{- end -}}
{{- trunc 63 $name | trimSuffix "-" -}}
{{- $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/* Create chart name and version as used by the chart label */}}
{{- define "bjw-s.common.lib.chart.names.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/* Create the name of the ServiceAccount to use */}}
{{- define "bjw-s.common.lib.chart.names.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{- default (include "bjw-s.common.lib.chart.names.fullname" .) .Values.serviceAccount.name -}}
{{- else -}}
{{- default "default" .Values.serviceAccount.name -}}
{{- end -}}
{{- end -}}

View file

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

View file

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

View file

@ -1,15 +0,0 @@
{{/*
Image used by the main container.
*/}}
{{- define "bjw-s.common.lib.container.image" -}}
{{- $imageRepo := .Values.image.repository -}}
{{- $imageTag := default .Chart.AppVersion .Values.image.tag -}}
{{- if kindIs "float64" .Values.image.tag -}}
{{- $imageTag = .Values.image.tag | toString -}}
{{- end -}}
{{- if and $imageRepo $imageTag -}}
{{- printf "%s:%s" $imageRepo $imageTag -}}
{{- end -}}
{{- end -}}

View file

@ -1,43 +0,0 @@
{{/*
Environment variables used by containers.
*/}}
{{- define "bjw-s.common.lib.container.envVars" -}}
{{- $values := .Values.env -}}
{{- if hasKey . "ObjectValues" -}}
{{- with .ObjectValues.envVars -}}
{{- $values = . -}}
{{- end -}}
{{- end -}}
{{- with $values -}}
{{- $result := list -}}
{{- range $k, $v := . -}}
{{- $name := $k -}}
{{- $value := $v -}}
{{- if kindIs "int" $name -}}
{{- $name = required "environment variables as a list of maps require a name field" $value.name -}}
{{- end -}}
{{- if kindIs "map" $value -}}
{{- if hasKey $value "value" -}}
{{- $envValue := $value.value | toString -}}
{{- $result = append $result (dict "name" $name "value" (tpl $envValue $)) -}}
{{- else if hasKey $value "valueFrom" -}}
{{- $result = append $result (dict "name" $name "valueFrom" $value.valueFrom) -}}
{{- else -}}
{{- $result = append $result (dict "name" $name "valueFrom" $value) -}}
{{- end -}}
{{- end -}}
{{- if not (kindIs "map" $value) -}}
{{- if kindIs "string" $value -}}
{{- $result = append $result (dict "name" $name "value" (tpl $value $)) -}}
{{- else if or (kindIs "float64" $value) (kindIs "bool" $value) -}}
{{- $result = append $result (dict "name" $name "value" ($value | toString)) -}}
{{- else -}}
{{- $result = append $result (dict "name" $name "value" $value) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- toYaml (dict "env" $result) | nindent 0 -}}
{{- end -}}
{{- end -}}

View file

@ -1,41 +0,0 @@
{{/*
Ports included by the controller.
*/}}
{{- define "bjw-s.common.lib.container.ports" -}}
{{- $ports := list -}}
{{- range $servicename, $service := .Values.service -}}
{{- $serviceEnabled := true -}}
{{- if hasKey $service "enabled" -}}
{{- $serviceEnabled = $service.enabled -}}
{{- end -}}
{{- if $serviceEnabled -}}
{{- $enabledPorts := include "bjw-s.common.lib.service.enabledPorts" (dict "serviceName" $servicename "values" $service) | fromYaml }}
{{- range $portname, $port := ($enabledPorts | default dict) -}}
{{- $_ := set $port "name" $portname -}}
{{- $ports = mustAppend $ports $port -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{/* export/render the list of ports */}}
{{- if $ports -}}
{{- range $_ := $ports }}
{{- if default true .enabled | }}
- name: {{ .name }}
{{- if and .targetPort (kindIs "string" .targetPort) }}
{{- fail (printf "Our charts do not support named ports for targetPort. (port name %s, targetPort %s)" .name .targetPort) }}
{{- end }}
containerPort: {{ .targetPort | default .port }}
{{- if .protocol }}
{{- if or ( eq .protocol "HTTP" ) ( eq .protocol "HTTPS" ) ( eq .protocol "TCP" ) }}
protocol: TCP
{{- else }}
protocol: {{ .protocol }}
{{- end }}
{{- else }}
protocol: TCP
{{- end }}
{{- end}}
{{- end -}}
{{- end -}}
{{- end -}}

View file

@ -1,67 +0,0 @@
{{/*
Probes selection logic.
*/}}
{{- define "bjw-s.common.lib.container.probes" -}}
{{- $primaryService := get .Values.service (include "bjw-s.common.lib.service.primary" .) -}}
{{- $primaryPort := "" -}}
{{- if $primaryService -}}
{{- $primaryPort = get $primaryService.ports (include "bjw-s.common.lib.service.primaryPort" (dict "serviceName" (include "bjw-s.common.lib.service.primary" .) "values" $primaryService)) -}}
{{- end -}}
{{- range $probeName, $probe := .Values.probes -}}
{{- if $probe.enabled -}}
{{- $probeOutput := "" -}}
{{- if $probe.custom -}}
{{- if $probe.spec -}}
{{- $probeOutput = $probe.spec | toYaml -}}
{{- end -}}
{{- else -}}
{{- if $primaryPort -}}
{{- $probeType := "" -}}
{{- if eq $probe.type "AUTO" -}}
{{- $probeType = $primaryPort.protocol -}}
{{- else -}}
{{- $probeType = $probe.type | default "TCP" -}}
{{- end -}}
{{- $probeDefinition := dict
"initialDelaySeconds" $probe.spec.initialDelaySeconds
"failureThreshold" $probe.spec.failureThreshold
"timeoutSeconds" $probe.spec.timeoutSeconds
"periodSeconds" $probe.spec.periodSeconds
-}}
{{- $probeHeader := "" -}}
{{- if or ( eq $probeType "HTTPS" ) ( eq $probeType "HTTP" ) -}}
{{- $probeHeader = "httpGet" -}}
{{- $_ := set $probeDefinition $probeHeader (
dict
"path" $probe.path
"scheme" $probeType
)
-}}
{{- else }}
{{- $probeHeader = "tcpSocket" -}}
{{- $_ := set $probeDefinition $probeHeader dict -}}
{{- end -}}
{{- if $probe.port }}
{{- $_ := set (index $probeDefinition $probeHeader) "port" (tpl ( $probe.port | toString ) $) -}}
{{- else if $primaryPort.targetPort }}
{{- $_ := set (index $probeDefinition $probeHeader) "port" $primaryPort.targetPort -}}
{{- else }}
{{- $_ := set (index $probeDefinition $probeHeader) "port" ($primaryPort.port | toString | atoi ) -}}
{{- end }}
{{- $probeOutput = $probeDefinition | toYaml | trim -}}
{{- end -}}
{{- end -}}
{{- if $probeOutput -}}
{{- printf "%sProbe:" $probeName | nindent 0 -}}
{{- $probeOutput | nindent 2 -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}

View file

@ -0,0 +1,51 @@
{{- /*
The container definition included in the Pod.
*/ -}}
{{- define "bjw-s.common.lib.container.spec" -}}
{{- $rootContext := .rootContext -}}
{{- $controllerObject := .controllerObject -}}
{{- $containerObject := .containerObject -}}
{{- $ctx := dict "rootContext" $rootContext "controllerObject" $controllerObject "containerObject" $containerObject -}}
name: {{ include "bjw-s.common.lib.container.field.name" (dict "ctx" $ctx) | trim }}
image: {{ include "bjw-s.common.lib.container.field.image" (dict "ctx" $ctx) | trim }}
{{- with $containerObject.image.pullPolicy }}
imagePullPolicy: {{ . | trim }}
{{- end -}}
{{- with (include "bjw-s.common.lib.container.field.command" (dict "ctx" $ctx) | trim) }}
command: {{ . | trim | nindent 2 }}
{{- end -}}
{{- with (include "bjw-s.common.lib.container.field.args" (dict "ctx" $ctx) | trim) }}
args: {{ . | trim | nindent 2 }}
{{- end -}}
{{- with $containerObject.securityContext }}
securityContext: {{ toYaml . | trim | nindent 2 }}
{{- end -}}
{{- with $containerObject.lifecycle }}
lifecycle: {{ toYaml . | trim | nindent 2 }}
{{- end -}}
{{- with $containerObject.terminationMessagePath }}
terminationMessagePath: {{ . | trim }}
{{- end -}}
{{- with $containerObject.terminationMessagePolicy }}
terminationMessagePolicy: {{ . | trim }}
{{- end -}}
{{- with (include "bjw-s.common.lib.container.field.env" (dict "ctx" $ctx) | trim) }}
env: {{ . | trim | nindent 2 }}
{{- end -}}
{{- with $containerObject.envFrom }}
envFrom: {{ toYaml . | trim | nindent 2 }}
{{- end -}}
{{- with $containerObject.ports }}
ports: {{ toYaml . | trim | nindent 2 }}
{{- end -}}
{{- with (include "bjw-s.common.lib.container.field.probes" (dict "ctx" $ctx) | trim) }}
{{- . | trim | nindent 0 -}}
{{- end -}}
{{- with $containerObject.resources }}
resources: {{ toYaml . | trim | nindent 2 }}
{{- end -}}
{{- with (include "bjw-s.common.lib.container.field.volumeMounts" (dict "ctx" $ctx) | trim) }}
volumeMounts: {{ . | trim | nindent 2 }}
{{- end -}}
{{- end -}}

View file

@ -0,0 +1,11 @@
{{/*
Validate container values
*/}}
{{- define "bjw-s.common.lib.container.validate" -}}
{{- $rootContext := .rootContext -}}
{{- $containerValues := .object -}}
{{- if eq (dig "image" "repository" "" $containerValues) "" -}}
{{- fail (printf "No image repository specified for container. (controller: %s, container: %s)" $containerValues.controller $containerValues.identifier) }}
{{- end -}}
{{- end -}}

View file

@ -0,0 +1,13 @@
{{/*
Convert container values to an object
*/}}
{{- define "bjw-s.common.lib.container.valuesToObject" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $objectValues := .values -}}
{{- $_ := set $objectValues "identifier" $identifier -}}
{{- /* Return the container object */ -}}
{{- $objectValues | toYaml -}}
{{- end -}}

View file

@ -1,3 +1,5 @@
{{- /* TODO: Remove this file */ -}}
{{/* Volumes included by the controller */}}
{{- define "bjw-s.common.lib.container.volumeMounts" -}}
{{- range $persistenceIndex, $persistenceItem := .Values.persistence }}

View file

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

View file

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

View file

@ -0,0 +1,45 @@
{{/*
Env field used by the container.
*/}}
{{- define "bjw-s.common.lib.container.field.env" -}}
{{- $ctx := .ctx -}}
{{- $rootContext := $ctx.rootContext -}}
{{- $containerObject := $ctx.containerObject -}}
{{- /* Default to empty list */ -}}
{{- $env := list -}}
{{- /* See if an override is desired */ -}}
{{- if not (empty (get $containerObject "env")) -}}
{{- with $containerObject.env -}}
{{- range $name, $value := . -}}
{{- if kindIs "int" $name -}}
{{- $name = required "environment variables as a list of maps require a name field" $value.name -}}
{{- end -}}
{{- if kindIs "map" $value -}}
{{- if hasKey $value "value" -}}
{{- $envValue := $value.value | toString -}}
{{- $env = append $env (dict "name" $name "value" (tpl $envValue $rootContext)) -}}
{{- else if hasKey $value "valueFrom" -}}
{{- $env = append $env (dict "name" $name "valueFrom" $value.valueFrom) -}}
{{- else -}}
{{- $env = append $env (dict "name" $name "valueFrom" $value) -}}
{{- end -}}
{{- else -}}
{{- if kindIs "string" $value -}}
{{- $env = append $env (dict "name" $name "value" (tpl $value $rootContext)) -}}
{{- else if or (kindIs "float64" $value) (kindIs "bool" $value) -}}
{{- $env = append $env (dict "name" $name "value" ($value | toString)) -}}
{{- else -}}
{{- $env = append $env (dict "name" $name "value" $value) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if not (empty $env) -}}
{{- $env | toYaml -}}
{{- end -}}
{{- end -}}

View file

@ -0,0 +1,19 @@
{{/*
Image used by the container.
*/}}
{{- define "bjw-s.common.lib.container.field.image" -}}
{{- $ctx := .ctx -}}
{{- $rootContext := $ctx.rootContext -}}
{{- $containerObject := $ctx.containerObject -}}
{{- $imageRepo := $containerObject.image.repository -}}
{{- $imageTag := default $rootContext.Chart.AppVersion $containerObject.image.tag -}}
{{- if kindIs "float64" $imageTag -}}
{{- $imageTag = $imageTag | toString -}}
{{- end -}}
{{- if and $imageRepo $imageTag -}}
{{- printf "%s:%s" $imageRepo $imageTag -}}
{{- end -}}
{{- end -}}

View file

@ -0,0 +1,24 @@
{{/*
Name used by the container.
*/}}
{{- define "bjw-s.common.lib.container.field.name" -}}
{{- $ctx := .ctx -}}
{{- $rootContext := $ctx.rootContext -}}
{{- $containerObject := $ctx.containerObject -}}
{{- /* Default to container identifier */ -}}
{{- $name := $containerObject.identifier -}}
{{- /* See if an override is desired */ -}}
{{- if hasKey $containerObject "nameOverride" -}}
{{- $option := get $containerObject "nameOverride" -}}
{{- if not (empty $option) -}}
{{- $name = $option -}}
{{- end -}}
{{- end -}}
{{- /* Parse any templates */ -}}
{{- $name = tpl $name $rootContext -}}
{{- $name | toYaml -}}
{{- end -}}

View file

@ -0,0 +1,79 @@
{{/*
Probes used by the container.
*/}}
{{- define "bjw-s.common.lib.container.field.probes" -}}
{{- $ctx := .ctx -}}
{{- $rootContext := $ctx.rootContext -}}
{{- $controllerObject := $ctx.controllerObject -}}
{{- $containerObject := $ctx.containerObject -}}
{{- /* Default to empty dict */ -}}
{{- $enabledProbes := dict -}}
{{- range $probeName, $probeValues := $containerObject.probes -}}
{{- /* Disable probe by default, but allow override */ -}}
{{- $probeEnabled := false -}}
{{- if hasKey $probeValues "enabled" -}}
{{- $probeEnabled = $probeValues.enabled -}}
{{- end -}}
{{- if $probeEnabled -}}
{{- $probeDefinition := dict -}}
{{- if $probeValues.custom -}}
{{- $parsedProbeSpec := tpl ($probeValues.spec | toYaml) $rootContext -}}
{{- $probeDefinition = $parsedProbeSpec | fromYaml -}}
{{- else -}}
{{- $primaryService := include "bjw-s.common.lib.service.primaryForController" (dict "rootContext" $rootContext "controllerIdentifier" $controllerObject.identifier) | fromYaml -}}
{{- $primaryServiceDefaultPort := dict -}}
{{- if $primaryService -}}
{{- $primaryServiceDefaultPort = include "bjw-s.common.lib.service.primaryPort" (dict "rootContext" $rootContext "serviceObject" $primaryService) | fromYaml -}}
{{- end -}}
{{- if $primaryServiceDefaultPort -}}
{{- $probeType := "" -}}
{{- if eq $probeValues.type "AUTO" -}}
{{- $probeType = $primaryServiceDefaultPort.protocol -}}
{{- else -}}
{{- $probeType = $probeValues.type | default "TCP" -}}
{{- end -}}
{{- $_ := set $probeDefinition "initialDelaySeconds" $probeValues.spec.initialDelaySeconds -}}
{{- $_ := set $probeDefinition "failureThreshold" $probeValues.spec.failureThreshold -}}
{{- $_ := set $probeDefinition "timeoutSeconds" $probeValues.spec.timeoutSeconds -}}
{{- $_ := set $probeDefinition "periodSeconds" $probeValues.spec.periodSeconds -}}
{{- $probeHeader := "" -}}
{{- if or ( eq $probeType "HTTPS" ) ( eq $probeType "HTTP" ) -}}
{{- $probeHeader = "httpGet" -}}
{{- $_ := set $probeDefinition $probeHeader (
dict
"path" $probeValues.path
"scheme" $probeType
)
-}}
{{- else }}
{{- $probeHeader = "tcpSocket" -}}
{{- $_ := set $probeDefinition $probeHeader dict -}}
{{- end -}}
{{- if $probeValues.port -}}
{{- $_ := set (index $probeDefinition $probeHeader) "port" (tpl ( $probeValues.port | toString ) $rootContext) -}}
{{- else if $primaryServiceDefaultPort.targetPort -}}
{{- $_ := set (index $probeDefinition $probeHeader) "port" $primaryServiceDefaultPort.targetPort -}}
{{- else -}}
{{- $_ := set (index $probeDefinition $probeHeader) "port" ($primaryServiceDefaultPort.port | toString | atoi ) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if $probeDefinition -}}
{{- $_ := set $enabledProbes (printf "%sProbe" $probeName) $probeDefinition -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- with $enabledProbes -}}
{{- . | toYaml -}}
{{- end -}}
{{- end -}}

View file

@ -0,0 +1,77 @@
{{/*
volumeMounts used by the container.
*/}}
{{- define "bjw-s.common.lib.container.field.volumeMounts" -}}
{{- $ctx := .ctx -}}
{{- $rootContext := $ctx.rootContext -}}
{{- $controllerObject := $ctx.controllerObject -}}
{{- $containerObject := $ctx.containerObject -}}
{{- /* Default to empty dict */ -}}
{{- $persistenceItemsToProcess := dict -}}
{{- $enabledVolumeMounts := list -}}
{{- range $identifier, $persistenceValues := $rootContext.Values.persistence -}}
{{- /* Enable persistence item by default, but allow override */ -}}
{{- $persistenceEnabled := true -}}
{{- if hasKey $persistenceValues "enabled" -}}
{{- $persistenceEnabled = $persistenceValues.enabled -}}
{{- end -}}
{{- if $persistenceEnabled -}}
{{- /* Set some default values */ -}}
{{- /* Set the default mountPath to /<name_of_the_peristence_item> */ -}}
{{- $mountPath := (printf "/%v" $identifier) -}}
{{- if eq "hostPath" (default "pvc" $persistenceValues.type) -}}
{{- $mountPath = $persistenceValues.hostPath -}}
{{- end -}}
{{- /* Process configured mounts */ -}}
{{- if or .globalMounts .advancedMounts -}}
{{- $mounts := list -}}
{{- if hasKey . "globalMounts" -}}
{{- $mounts = .globalMounts -}}
{{- else if hasKey . "advancedMounts" -}}
{{- $mounts = dig $controllerObject.identifier $containerObject.identifier list .advancedMounts -}}
{{- end -}}
{{- range $mounts -}}
{{- $volumeMount := dict -}}
{{- $_ := set $volumeMount "name" $identifier -}}
{{- /* Use the specified mountPath if provided */ -}}
{{- with .path -}}
{{- $mountPath = . -}}
{{- end -}}
{{- $_ := set $volumeMount "mountPath" $mountPath -}}
{{- /* Use the specified subPath if provided */ -}}
{{- with .subPath -}}
{{- $subPath := . -}}
{{- $_ := set $volumeMount "subPath" $subPath -}}
{{- end -}}
{{- /* Use the specified readOnly setting if provided */ -}}
{{- with .readOnly -}}
{{- $readOnly := . -}}
{{- $_ := set $volumeMount "readOnly" $readOnly -}}
{{- end -}}
{{- $enabledVolumeMounts = append $enabledVolumeMounts $volumeMount -}}
{{- end -}}
{{- /* Mount to default path if no mounts are configured */ -}}
{{- else -}}
{{- $volumeMount := dict -}}
{{- $_ := set $volumeMount "name" $identifier -}}
{{- $_ := set $volumeMount "mountPath" $mountPath -}}
{{- $enabledVolumeMounts = append $enabledVolumeMounts $volumeMount -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- with $enabledVolumeMounts -}}
{{- . | toYaml -}}
{{- end -}}
{{- end -}}

View file

@ -0,0 +1,24 @@
{{/*
Return the enabled containers for a controller.
*/}}
{{- define "bjw-s.common.lib.controller.enabledContainers" -}}
{{- $rootContext := .rootContext -}}
{{- $controllerObject := .controllerObject -}}
{{- $enabledContainers := dict -}}
{{- range $name, $container := $controllerObject.containers -}}
{{- if kindIs "map" $container -}}
{{- /* Enable container by default, but allow override */ -}}
{{- $containerEnabled := true -}}
{{- if hasKey $container "enabled" -}}
{{- $containerEnabled = $container.enabled -}}
{{- end -}}
{{- if $containerEnabled -}}
{{- $_ := set $enabledContainers $name . -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $enabledContainers | toYaml -}}
{{- end -}}

View file

@ -1,58 +0,0 @@
{{- /* The main container included in the controller */ -}}
{{- define "bjw-s.common.lib.controller.mainContainer" -}}
- name: {{ include "bjw-s.common.lib.chart.names.fullname" . }}
image: {{ include "bjw-s.common.lib.container.image" . }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with .Values.command }}
command:
{{- if kindIs "string" . }}
- {{ . | quote }}
{{- else }}
{{ toYaml . | nindent 4 }}
{{- end }}
{{- end }}
{{- with .Values.args }}
args:
{{- if kindIs "string" . }}
- {{ . | quote }}
{{- else }}
{{ toYaml . | nindent 4 }}
{{- end }}
{{- end }}
{{- with .Values.securityContext }}
securityContext:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.lifecycle }}
lifecycle:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.termination.messagePath }}
terminationMessagePath: {{ . }}
{{- end }}
{{- with .Values.termination.messagePolicy }}
terminationMessagePolicy: {{ . }}
{{- end }}
{{- with .Values.env }}
env:
{{- get (fromYaml (include "bjw-s.common.lib.container.envVars" $)) "env" | toYaml | nindent 4 -}}
{{- end }}
{{- with .Values.envFrom }}
envFrom:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with (include "bjw-s.common.lib.container.ports" . | trim) }}
ports:
{{- nindent 4 . }}
{{- end }}
{{- with (include "bjw-s.common.lib.container.volumeMounts" . | trim) }}
volumeMounts:
{{- nindent 4 . }}
{{- end }}
{{- include "bjw-s.common.lib.container.probes" . | trim | nindent 2 }}
{{- with .Values.resources }}
resources:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end -}}

View file

@ -1,114 +0,0 @@
{{- /*
The pod definition included in the controller.
*/ -}}
{{- define "bjw-s.common.lib.controller.pod" -}}
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 2 }}
{{- end }}
serviceAccountName: {{ include "bjw-s.common.lib.chart.names.serviceAccountName" . }}
automountServiceAccountToken: {{ .Values.automountServiceAccountToken }}
{{- with .Values.podSecurityContext }}
securityContext:
{{- toYaml . | nindent 2 }}
{{- end }}
{{- with .Values.priorityClassName }}
priorityClassName: {{ . }}
{{- end }}
{{- with .Values.runtimeClassName }}
runtimeClassName: {{ . }}
{{- end }}
{{- with .Values.schedulerName }}
schedulerName: {{ . }}
{{- end }}
{{- with .Values.hostIPC }}
hostIPC: {{ . }}
{{- end }}
{{- with .Values.hostNetwork }}
hostNetwork: {{ . }}
{{- end }}
{{- with .Values.hostPID }}
hostPID: {{ . }}
{{- end }}
{{- with .Values.hostname }}
hostname: {{ . }}
{{- end }}
{{- if .Values.dnsPolicy }}
dnsPolicy: {{ .Values.dnsPolicy }}
{{- else if .Values.hostNetwork }}
dnsPolicy: ClusterFirstWithHostNet
{{- else }}
dnsPolicy: ClusterFirst
{{- end }}
{{- with .Values.dnsConfig }}
dnsConfig:
{{- toYaml . | nindent 2 }}
{{- end }}
enableServiceLinks: {{ .Values.enableServiceLinks }}
{{- with .Values.termination.gracePeriodSeconds }}
terminationGracePeriodSeconds: {{ . }}
{{- end }}
{{- if .Values.initContainers }}
initContainers:
{{- $initContainers := list }}
{{- range $index, $key := (keys .Values.initContainers | uniq | sortAlpha) }}
{{- $container := get $.Values.initContainers $key }}
{{- if not $container.name -}}
{{- $_ := set $container "name" $key }}
{{- end }}
{{- if $container.env -}}
{{- $_ := set $ "ObjectValues" (dict "envVars" $container.env) -}}
{{- $newEnv := fromYaml (include "bjw-s.common.lib.container.envVars" $) -}}
{{- $_ := unset $.ObjectValues "envVars" -}}
{{- $_ := set $container "env" $newEnv.env }}
{{- end }}
{{- $initContainers = append $initContainers $container }}
{{- end }}
{{- tpl (toYaml $initContainers) $ | nindent 2 }}
{{- end }}
containers:
{{- include "bjw-s.common.lib.controller.mainContainer" . | nindent 2 }}
{{- with (merge .Values.sidecars .Values.additionalContainers) }}
{{- $sidecarContainers := list }}
{{- range $name, $container := . }}
{{- if not $container.name -}}
{{- $_ := set $container "name" $name }}
{{- end }}
{{- if $container.env -}}
{{- $_ := set $ "ObjectValues" (dict "envVars" $container.env) -}}
{{- $newEnv := fromYaml (include "bjw-s.common.lib.container.envVars" $) -}}
{{- $_ := set $container "env" $newEnv.env }}
{{- $_ := unset $.ObjectValues "envVars" -}}
{{- end }}
{{- $sidecarContainers = append $sidecarContainers $container }}
{{- end }}
{{- tpl (toYaml $sidecarContainers) $ | nindent 2 }}
{{- end }}
{{- with (include "bjw-s.common.lib.controller.volumes" . | trim) }}
volumes:
{{- nindent 2 . }}
{{- end }}
{{- with .Values.hostAliases }}
hostAliases:
{{- toYaml . | nindent 2 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 2 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 2 }}
{{- end }}
{{- with .Values.topologySpreadConstraints }}
topologySpreadConstraints:
{{- toYaml . | nindent 2 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 2 }}
{{- end }}
{{- with .Values.controller.restartPolicy }}
restartPolicy: {{ . }}
{{- end }}
{{- end -}}

View file

@ -0,0 +1,18 @@
{{/*
Validate controller values
*/}}
{{- define "bjw-s.common.lib.controller.validate" -}}
{{- $rootContext := .rootContext -}}
{{- $controllerValues := .object -}}
{{- $allowedControllerTypes := list "deployment" "daemonset" "statefulset" "cronjob" -}}
{{- if not (has $controllerValues.type $allowedControllerTypes) -}}
{{- fail (printf "Not a valid controller.type (%s)" $controllerValues.type) -}}
{{- end -}}
{{- $enabledContainers := include "bjw-s.common.lib.controller.enabledContainers" (dict "rootContext" $rootContext "controllerObject" $controllerValues) | fromYaml }}
{{- /* Validate at least one container is enabled */ -}}
{{- if not $enabledContainers -}}
{{- fail (printf "No containers enabled for controller (%s)" $controllerValues.identifier) -}}
{{- end -}}
{{- end -}}

View file

@ -0,0 +1,36 @@
{{/*
Convert controller values to an object
*/}}
{{- define "bjw-s.common.lib.controller.valuesToObject" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $objectValues := .values -}}
{{- /* Determine and inject the controller name */ -}}
{{- $objectName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}}
{{- if $objectValues.nameOverride -}}
{{- $objectName = printf "%s-%s" $objectName $objectValues.nameOverride -}}
{{- else -}}
{{- if ne $identifier "main" -}}
{{- $objectName = printf "%s-%s" $objectName $identifier -}}
{{- end -}}
{{- end -}}
{{- $_ := set $objectValues "name" $objectName -}}
{{- $_ := set $objectValues "identifier" $identifier -}}
{{- /* Set the default Pod options for the controller */ -}}
{{- range $index, $key := keys $rootContext.Values.defaultPodOptions -}}
{{- if not (hasKey $objectValues "pod") -}}
{{- $_ := set $objectValues "pod" dict -}}
{{- end -}}
{{- $defaultValue := get $rootContext.Values.defaultPodOptions $key -}}
{{- if not (hasKey $objectValues.pod $key) -}}
{{- $_ := set $objectValues.pod $key $defaultValue -}}
{{- end -}}
{{- end -}}
{{- /* Return the controller object */ -}}
{{- $objectValues | toYaml -}}
{{- end -}}

View file

@ -1,68 +0,0 @@
{{/*
Volumes included by the controller.
*/}}
{{- define "bjw-s.common.lib.controller.volumes" -}}
{{- range $index, $persistence := .Values.persistence }}
{{- if $persistence.enabled }}
- name: {{ $index }}
{{- if eq (default "pvc" $persistence.type) "pvc" }}
{{- $pvcName := (include "bjw-s.common.lib.chart.names.fullname" $) -}}
{{- if $persistence.existingClaim }}
{{- /* Always prefer an existingClaim if that is set */}}
{{- $pvcName = $persistence.existingClaim -}}
{{- else -}}
{{- /* Otherwise refer to the PVC name */}}
{{- if $persistence.nameOverride -}}
{{- if not (eq $persistence.nameOverride "-") -}}
{{- $pvcName = (printf "%s-%s" (include "bjw-s.common.lib.chart.names.fullname" $) $persistence.nameOverride) -}}
{{- end -}}
{{- else -}}
{{- $pvcName = (printf "%s-%s" (include "bjw-s.common.lib.chart.names.fullname" $) $index) -}}
{{- end -}}
{{- end }}
persistentVolumeClaim:
claimName: {{ $pvcName }}
{{- else if or (eq $persistence.type "configMap") (eq $persistence.type "secret") }}
{{- $objectName := (required (printf "name not set for persistence item %s" $index) $persistence.name) }}
{{- $objectName = tpl $objectName $ }}
{{- if eq $persistence.type "configMap" }}
configMap:
name: {{ $objectName }}
{{- else }}
secret:
secretName: {{ $objectName }}
{{- end }}
{{- with $persistence.defaultMode }}
defaultMode: {{ . }}
{{- end }}
{{- with $persistence.items }}
items:
{{- toYaml . | nindent 6 }}
{{- end }}
{{- else if eq $persistence.type "emptyDir" }}
{{- $emptyDir := dict -}}
{{- with $persistence.medium -}}
{{- $_ := set $emptyDir "medium" . -}}
{{- end -}}
{{- with $persistence.sizeLimit -}}
{{- $_ := set $emptyDir "sizeLimit" . -}}
{{- end }}
emptyDir: {{- $emptyDir | toYaml | nindent 4 }}
{{- else if eq $persistence.type "hostPath" }}
hostPath:
path: {{ required "hostPath not set" $persistence.hostPath }}
{{- with $persistence.hostPathType }}
type: {{ . }}
{{- end }}
{{- else if eq $persistence.type "nfs" }}
nfs:
server: {{ required "server not set" $persistence.server }}
path: {{ required "path not set" $persistence.path }}
{{- else if eq $persistence.type "custom" }}
{{- toYaml $persistence.volumeSpec | nindent 2 }}
{{- else }}
{{- fail (printf "Not a valid persistence.type (%s)" $persistence.type) }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}

View file

@ -0,0 +1,11 @@
{{/*
Validate CronJob values
*/}}
{{- define "bjw-s.common.lib.cronjob.validate" -}}
{{- $rootContext := .rootContext -}}
{{- $cronjobValues := .object -}}
{{- if and (ne $cronjobValues.pod.restartPolicy "Never") (ne $cronjobValues.pod.restartPolicy "OnFailure") -}}
{{- fail (printf "Not a valid restartPolicy type for CronJob. (controller: %s, restartPolicy: %s)" $cronjobValues.identifier $cronjobValues.pod.restartPolicy) }}
{{- end -}}
{{- end -}}

View file

@ -0,0 +1,18 @@
{{/*
Convert Cronjob values to an object
*/}}
{{- define "bjw-s.common.lib.cronjob.valuesToObject" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $objectValues := .values -}}
{{- if not (hasKey $objectValues "pod") -}}
{{- $_ := set $objectValues "pod" dict -}}
{{- end -}}
{{- $restartPolicy := default "Never" $objectValues.pod.restartPolicy -}}
{{- $_ := set $objectValues.pod "restartPolicy" $restartPolicy -}}
{{- /* Return the CronJob object */ -}}
{{- $objectValues | toYaml -}}
{{- end -}}

View file

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

View file

@ -0,0 +1,11 @@
{{/*
Convert DaemonSet values to an object
*/}}
{{- define "bjw-s.common.lib.daemonset.valuesToObject" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $objectValues := .values -}}
{{- /* Return the DaemonSet object */ -}}
{{- $objectValues | toYaml -}}
{{- end -}}

View file

@ -0,0 +1,11 @@
{{/*
Validate Deployment values
*/}}
{{- define "bjw-s.common.lib.deployment.validate" -}}
{{- $rootContext := .rootContext -}}
{{- $deploymentValues := .object -}}
{{- if and (ne $deploymentValues.strategy "Recreate") (ne $deploymentValues.strategy "RollingUpdate") -}}
{{- fail (printf "Not a valid strategy type for Deployment. (controller: %s, strategy: %s)" $deploymentValues.identifier $deploymentValues.strategy) }}
{{- end -}}
{{- end -}}

View file

@ -0,0 +1,14 @@
{{/*
Convert Deployment values to an object
*/}}
{{- define "bjw-s.common.lib.deployment.valuesToObject" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $objectValues := .values -}}
{{- $strategy := default "Recreate" $objectValues.strategy -}}
{{- $_ := set $objectValues "strategy" $strategy -}}
{{- /* Return the Deployment object */ -}}
{{- $objectValues | toYaml -}}
{{- end -}}

View file

@ -1,4 +1,4 @@
{{/* Return the name of the primary ingress object */}}
{{/* Return the name of the primary Ingress object */}}
{{- define "bjw-s.common.lib.ingress.primary" -}}
{{- $enabledIngresses := dict -}}
{{- range $name, $ingress := .Values.ingress -}}

View file

@ -0,0 +1,15 @@
{{/*
Validate Ingress values
*/}}
{{- define "bjw-s.common.lib.ingress.validate" -}}
{{- $rootContext := .rootContext -}}
{{- $ingressValues := .object -}}
{{- range $ingressValues.hosts -}}
{{- range .paths -}}
{{- if or (eq (dig "service" "name" "" .) "") (not .service.name) -}}
{{- fail (printf "No service name configured. (ingress: %s, path: %s)" $ingressValues.identifier .path) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}

View file

@ -0,0 +1,24 @@
{{/*
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 -}}
{{- $objectName = printf "%s-%s" $objectName $objectValues.nameOverride -}}
{{- else -}}
{{- if ne $identifier "main" -}}
{{- $objectName = printf "%s-%s" $objectName $identifier -}}
{{- end -}}
{{- end -}}
{{- $_ := set $objectValues "name" $objectName -}}
{{- $_ := set $objectValues "identifier" $identifier -}}
{{- /* Return the ingress object */ -}}
{{- $objectValues | toYaml -}}
{{- end -}}

View file

@ -1,26 +0,0 @@
{{/* Determine the Pod annotations used in the controller */}}
{{- define "bjw-s.common.lib.metadata.podAnnotations" -}}
{{- if .Values.podAnnotations -}}
{{- tpl (toYaml .Values.podAnnotations) . | nindent 0 -}}
{{- end -}}
{{- $configMapsFound := dict -}}
{{- range $name, $configmap := .Values.configMaps -}}
{{- if $configmap.enabled -}}
{{- $_ := set $configMapsFound $name (toYaml $configmap.data | sha256sum) -}}
{{- end -}}
{{- end -}}
{{- if $configMapsFound -}}
{{- printf "checksum/config: %v" (toYaml $configMapsFound | sha256sum) | nindent 0 -}}
{{- end -}}
{{- $secretsFound := dict -}}
{{- range $name, $secret := .Values.secrets -}}
{{- if $secret.enabled -}}
{{- $_ := set $secretsFound $name (toYaml $secret.data | sha256sum) -}}
{{- end -}}
{{- end -}}
{{- if $secretsFound -}}
{{- printf "checksum/secrets: %v" (toYaml $secretsFound | sha256sum) | nindent 0 -}}
{{- end -}}
{{- end -}}

View file

@ -0,0 +1,34 @@
{{- /*
Returns the value for the specified field
*/ -}}
{{- define "bjw-s.common.lib.pod.getOption" -}}
{{- $rootContext := .ctx.rootContext -}}
{{- $controllerObject := .ctx.controllerObject -}}
{{- $option := .option -}}
{{- $value := "" -}}
{{- /* Set to the default if it is set */ -}}
{{- $defaultOption := get $rootContext.Values.defaultPodOptions $option -}}
{{- if kindIs "bool" $defaultOption -}}
{{- $value = $defaultOption -}}
{{- else if not (empty $defaultOption) -}}
{{- $value = $defaultOption -}}
{{- end -}}
{{- /* See if a pod-specific override is needed */ -}}
{{- if hasKey $controllerObject "pod" -}}
{{- $podOption := get $controllerObject.pod $option -}}
{{- if kindIs "bool" $podOption -}}
{{- $value = $podOption -}}
{{- else if not (empty $podOption) -}}
{{- $value = $podOption -}}
{{- end -}}
{{- end -}}
{{- if kindIs "bool" $value -}}
{{- $value | toYaml -}}
{{- else if not (empty $value) -}}
{{- $value | toYaml -}}
{{- end -}}
{{- end -}}

View file

@ -0,0 +1,67 @@
{{- /*
The pod definition included in the controller.
*/ -}}
{{- define "bjw-s.common.lib.pod.spec" -}}
{{- $rootContext := .rootContext -}}
{{- $controllerObject := .controllerObject -}}
{{- $ctx := dict "rootContext" $rootContext "controllerObject" $controllerObject -}}
enableServiceLinks: {{ $controllerObject.pod.enableServiceLinks }}
serviceAccountName: {{ include "bjw-s.common.lib.pod.field.serviceAccountName" (dict "ctx" $ctx) | trim }}
automountServiceAccountToken: {{ $controllerObject.pod.automountServiceAccountToken }}
{{- with ($controllerObject.pod.priorityClassName) }}
priorityClassName: {{ . | trim }}
{{- end -}}
{{- with ($controllerObject.pod.runtimeClassName) }}
runtimeClassName: {{ . | trim }}
{{- end -}}
{{- with ($controllerObject.pod.schedulerName) }}
schedulerName: {{ . | trim }}
{{- end -}}
{{- with ($controllerObject.pod.securityContext) }}
securityContext: {{ . | trim | nindent 2 }}
{{- end -}}
{{- with ($controllerObject.pod.hostname) }}
hostname: {{ . | trim }}
{{- end }}
hostIPC: {{ $controllerObject.pod.hostIPC }}
hostNetwork: {{ $controllerObject.pod.hostNetwork }}
hostPID: {{ $controllerObject.pod.hostPID }}
dnsPolicy: {{ include "bjw-s.common.lib.pod.field.dnsPolicy" (dict "ctx" $ctx) | trim }}
{{- with $controllerObject.pod.dnsConfig }}
dnsConfig: {{ . | trim | nindent 2 }}
{{- end -}}
{{- with $controllerObject.pod.hostAliases }}
hostAliases: {{ . | trim | nindent 2 }}
{{- end -}}
{{- with $controllerObject.pod.imagePullSecrets }}
imagePullSecrets: {{ . | trim | nindent 2 }}
{{- end -}}
{{- with $controllerObject.pod.terminationGracePeriodSeconds }}
terminationGracePeriodSeconds: {{ . | trim }}
{{- end -}}
{{- with $controllerObject.pod.restartPolicy }}
restartPolicy: {{ . | trim }}
{{- end -}}
{{- with $controllerObject.pod.nodeSelector }}
nodeSelector: {{ . | trim | nindent 2 }}
{{- end -}}
{{- with $controllerObject.pod.affinity }}
affinity: {{ . | trim | nindent 2 }}
{{- end -}}
{{- with $controllerObject.pod.topologySpreadConstraints }}
topologySpreadConstraints: {{ . | trim | nindent 2 }}
{{- end -}}
{{- with $controllerObject.pod.tolerations }}
tolerations: {{ . | trim | nindent 2 }}
{{- end }}
{{- with (include "bjw-s.common.lib.pod.field.initContainers" (dict "ctx" $ctx) | trim) }}
initContainers: {{ . | nindent 2 }}
{{- end -}}
{{- with (include "bjw-s.common.lib.pod.field.containers" (dict "ctx" $ctx) | trim) }}
containers: {{ . | nindent 2 }}
{{- end -}}
{{- with (include "bjw-s.common.lib.pod.field.volumes" (dict "ctx" $ctx) | trim) }}
volumes: {{ . | nindent 2 }}
{{- end -}}
{{- end -}}

View file

@ -0,0 +1,28 @@
{{- /*
Returns the value for containers
*/ -}}
{{- define "bjw-s.common.lib.pod.field.containers" -}}
{{- $rootContext := .ctx.rootContext -}}
{{- $controllerObject := .ctx.controllerObject -}}
{{- /* Default to empty list */ -}}
{{- $containers := list -}}
{{- /* Fetch configured containers for this controller */ -}}
{{- $enabledContainers := include "bjw-s.common.lib.controller.enabledContainers" (dict "rootContext" $rootContext "controllerObject" $controllerObject) | fromYaml }}
{{- range $key, $containerValues := $enabledContainers -}}
{{- /* Create object from the container values */ -}}
{{- $containerObject := (include "bjw-s.common.lib.container.valuesToObject" (dict "rootContext" $ "id" $key "values" $containerValues)) | fromYaml -}}
{{- /* Perform validations on the Container before rendering */ -}}
{{- include "bjw-s.common.lib.container.validate" (dict "rootContext" $ "object" $containerObject) -}}
{{- /* Generate the Container spec */ -}}
{{- $renderedContainer := include "bjw-s.common.lib.container.spec" (dict "rootContext" $rootContext "controllerObject" $controllerObject "containerObject" $containerObject) | fromYaml -}}
{{- $containers = append $containers $renderedContainer -}}
{{- end -}}
{{- if not (empty $containers) -}}
{{- $containers | toYaml -}}
{{- end -}}
{{- end -}}

View file

@ -0,0 +1,25 @@
{{- /*
Returns the value for dnsPolicy
*/ -}}
{{- define "bjw-s.common.lib.pod.field.dnsPolicy" -}}
{{- $ctx := .ctx -}}
{{- $controllerObject := $ctx.controllerObject -}}
{{- /* Default to "ClusterFirst" */ -}}
{{- $dnsPolicy := "ClusterFirst" -}}
{{- /* Get hostNetwork value "" */ -}}
{{- $hostNetwork:= get $controllerObject.pod "hostNetwork" -}}
{{- if $hostNetwork -}}
{{- $dnsPolicy = "ClusterFirstWithHostNet" -}}
{{- end -}}
{{- /* See if an override is desired */ -}}
{{- $override := get $controllerObject.pod "dnsPolicy" -}}
{{- if not (empty $override) -}}
{{- $dnsPolicy = $override -}}
{{- end -}}
{{- $dnsPolicy -}}
{{- end -}}

View file

@ -0,0 +1,27 @@
{{- /*
Returns the value for initContainers
*/ -}}
{{- define "bjw-s.common.lib.pod.field.initContainers" -}}
{{- $rootContext := .ctx.rootContext -}}
{{- $controllerObject := .ctx.controllerObject -}}
{{- /* Default to empty list */ -}}
{{- $containers := list -}}
{{- /* Fetch configured containers for this controller */ -}}
{{- range $key, $containerValues := $controllerObject.initContainers -}}
{{- /* Create object from the container values */ -}}
{{- $containerObject := (include "bjw-s.common.lib.container.valuesToObject" (dict "rootContext" $ "id" $key "values" $containerValues)) | fromYaml -}}
{{- /* Perform validations on the Container before rendering */ -}}
{{- include "bjw-s.common.lib.container.validate" (dict "rootContext" $ "object" $containerObject) -}}
{{- /* Generate the Container spec */ -}}
{{- $renderedContainer := include "bjw-s.common.lib.container.spec" (dict "rootContext" $rootContext "containerObject" $containerObject) | fromYaml -}}
{{- $containers = append $containers $renderedContainer -}}
{{- end -}}
{{- if not (empty $containers) -}}
{{- $containers | toYaml -}}
{{- end -}}
{{- end -}}

View file

@ -0,0 +1,18 @@
{{- /*
Returns the value for serviceAccountName
*/ -}}
{{- define "bjw-s.common.lib.pod.field.serviceAccountName" -}}
{{- $rootContext := .ctx.rootContext -}}
{{- /* Default to "default" */ -}}
{{- $name := "default" -}}
{{- /* See if an override is needed */ -}}
{{- if $rootContext.Values.serviceAccount.create -}}
{{- $serviceAccountValues := (mustDeepCopy $rootContext.Values.serviceAccount) -}}
{{- $serviceAccountObject := (include "bjw-s.common.lib.serviceAccount.valuesToObject" (dict "rootContext" $rootContext "id" "default" "values" $serviceAccountValues)) | fromYaml -}}
{{- $name = $serviceAccountObject.name -}}
{{- end -}}
{{- $name -}}
{{- end -}}

View file

@ -0,0 +1,118 @@
{{- /*
Returns the value for volumes
*/ -}}
{{- define "bjw-s.common.lib.pod.field.volumes" -}}
{{- $rootContext := .ctx.rootContext -}}
{{- $controllerObject := .ctx.controllerObject -}}
{{- /* Default to empty list */ -}}
{{- $persistenceItemsToProcess := dict -}}
{{- $volumes := list -}}
{{- /* Loop over persistence values */ -}}
{{- range $identifier, $persistenceValues := $rootContext.Values.persistence -}}
{{- /* Enable persistence item by default, but allow override */ -}}
{{- $persistenceEnabled := true -}}
{{- if hasKey $persistenceValues "enabled" -}}
{{- $persistenceEnabled = $persistenceValues.enabled -}}
{{- end -}}
{{- if $persistenceEnabled -}}
{{- $advancedMounts := dig "advancedMounts" $controllerObject.identifier list $persistenceValues -}}
{{- if $advancedMounts -}}
{{- $_ := set $persistenceItemsToProcess $identifier $persistenceValues -}}
{{- else -}}
{{- $_ := set $persistenceItemsToProcess $identifier $persistenceValues -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- /* Loop over persistence items */ -}}
{{- range $identifier, $persistenceValues := $persistenceItemsToProcess -}}
{{- $volume := dict "name" $identifier -}}
{{- /* PVC persistence type */ -}}
{{- if eq (default "persistentVolumeClaim" $persistenceValues.type) "persistentVolumeClaim" -}}
{{- $pvcName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}}
{{- if $persistenceValues.existingClaim -}}
{{- /* Always prefer an existingClaim if that is set */ -}}
{{- $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 -}}
{{- $pvcName = (printf "%s-%s" (include "bjw-s.common.lib.chart.names.fullname" $rootContext) $identifier) -}}
{{- end -}}
{{- end -}}
{{- $_ := set $volume "persistentVolumeClaim" (dict "claimName" $pvcName) -}}
{{- /* configMap persistence type */ -}}
{{- else if eq $persistenceValues.type "configMap" -}}
{{- $objectName := (required (printf "name not set for persistence item %s" $identifier) $persistenceValues.name) -}}
{{- $objectName = tpl $objectName $rootContext -}}
{{- $_ := set $volume "configMap" dict -}}
{{- $_ := set $volume.configMap "name" $objectName -}}
{{- with $persistenceValues.defaultMode -}}
{{- $_ := set $volume.configMap "defaultMode" . -}}
{{- end -}}
{{- with $persistenceValues.items -}}
{{- $_ := set $volume.configMap "items" . -}}
{{- end -}}
{{- /* Secret persistence type */ -}}
{{- else if eq $persistenceValues.type "secret" -}}
{{- $objectName := (required (printf "name not set for persistence item %s" $identifier) $persistenceValues.name) -}}
{{- $objectName = tpl $objectName $rootContext -}}
{{- $_ := set $volume "secret" dict -}}
{{- $_ := set $volume.secret "secretName" $objectName -}}
{{- with $persistenceValues.defaultMode -}}
{{- $_ := set $volume.secret "defaultMode" . -}}
{{- end -}}
{{- with $persistenceValues.items -}}
{{- $_ := set $volume.secret "items" . -}}
{{- end -}}
{{- /* emptyDir persistence type */ -}}
{{- else if eq $persistenceValues.type "emptyDir" -}}
{{- $_ := set $volume "emptyDir" dict -}}
{{- with $persistenceValues.medium -}}
{{- $_ := set $volume.emptyDir "medium" . -}}
{{- end -}}
{{- with $persistenceValues.sizeLimit -}}
{{- $_ := set $volume.emptyDir "sizeLimit" . -}}
{{- end -}}
{{- /* hostPath persistence type */ -}}
{{- else if eq $persistenceValues.type "hostPath" -}}
{{- $_ := set $volume "hostPath" dict -}}
{{- $_ := set $volume.hostPath "path" (required "hostPath not set" $persistenceValues.hostPath) -}}
{{- with $persistenceValues.hostPathType }}
{{- $_ := set $volume.hostPath "type" . -}}
{{- end -}}
{{- /* hostPath persistence type */ -}}
{{- else if eq $persistenceValues.type "nfs" -}}
{{- $_ := set $volume "nfs" dict -}}
{{- $_ := set $volume.nfs "server" (required "server not set" $persistenceValues.server) -}}
{{- $_ := set $volume.nfs "path" (required "path not set" $persistenceValues.path) -}}
{{- /* custom persistence type */ -}}
{{- else if eq $persistenceValues.type "custom" -}}
{{- $volume = $persistenceValues.volumeSpec -}}
{{- $_ := set $volume "name" $identifier -}}
{{- /* Fail otherwise */ -}}
{{- else -}}
{{- fail (printf "Not a valid persistence.type (%s)" $persistenceValues.type) -}}
{{- end -}}
{{- $volumes = append $volumes $volume -}}
{{- end -}}
{{- if not (empty $volumes) -}}
{{- $volumes | toYaml -}}
{{- end -}}
{{- end -}}

View file

@ -0,0 +1,56 @@
{{- /*
Returns the value for annotations
*/ -}}
{{- define "bjw-s.common.lib.pod.metadata.annotations" -}}
{{- $rootContext := .rootContext -}}
{{- $controllerObject := .controllerObject -}}
{{- /* Default annotations */ -}}
{{- $annotations := dict -}}
{{- /* Set to the default if it is set */ -}}
{{- $defaultOption := get $rootContext.Values.defaultPodOptions "annotations" -}}
{{- if not (empty $defaultOption) -}}
{{- $annotations = merge $defaultOption $annotations -}}
{{- end -}}
{{- /* See if a pod-specific override is set */ -}}
{{- if hasKey $controllerObject "pod" -}}
{{- $podOption := get $controllerObject.pod "annotations" -}}
{{- if not (empty $podOption) -}}
{{- $annotations = merge $podOption $annotations -}}
{{- end -}}
{{- end -}}
{{- /* Add configMaps checksum */ -}}
{{- $configMapsFound := dict -}}
{{- range $name, $configmap := $rootContext.Values.configMaps -}}
{{- if $configmap.enabled -}}
{{- $_ := set $configMapsFound $name (toYaml $configmap.data | sha256sum) -}}
{{- end -}}
{{- end -}}
{{- if $configMapsFound -}}
{{- $annotations = merge
(dict "checksum/configMaps" (toYaml $configMapsFound | sha256sum))
$annotations
-}}
{{- end -}}
{{- /* Add Secrets checksum */ -}}
{{- $secretsFound := dict -}}
{{- range $name, $secret := $rootContext.Values.secrets -}}
{{- if $secret.enabled -}}
{{- $_ := set $secretsFound $name (toYaml $secret.stringData | sha256sum) -}}
{{- end -}}
{{- end -}}
{{- if $secretsFound -}}
{{- $annotations = merge
(dict "checksum/secrets" (toYaml $secretsFound | sha256sum))
$annotations
-}}
{{- end -}}
{{- if not (empty $annotations) -}}
{{- $annotations | toYaml -}}
{{- end -}}
{{- end -}}

View file

@ -0,0 +1,36 @@
{{- /*
Returns the value for labels
*/ -}}
{{- define "bjw-s.common.lib.pod.metadata.labels" -}}
{{- $rootContext := .rootContext -}}
{{- $controllerObject := .controllerObject -}}
{{- /* Default labels */ -}}
{{- $labels := merge
(dict "app.kubernetes.io/component" $controllerObject.identifier)
-}}
{{- /* Fetch the Pod selectorLabels */ -}}
{{- $selectorLabels := include "bjw-s.common.lib.metadata.selectorLabels" $rootContext | fromYaml -}}
{{- if not (empty $selectorLabels) -}}
{{- $labels = merge $selectorLabels $labels -}}
{{- end -}}
{{- /* Set to the default if it is set */ -}}
{{- $defaultOption := get $rootContext.Values.defaultPodOptions "labels" -}}
{{- if not (empty $defaultOption) -}}
{{- $labels = merge $defaultOption $labels -}}
{{- end -}}
{{- /* See if a pod-specific override is set */ -}}
{{- if hasKey $controllerObject "pod" -}}
{{- $podOption := get $controllerObject.pod "labels" -}}
{{- if not (empty $podOption) -}}
{{- $labels = merge $podOption $labels -}}
{{- end -}}
{{- end -}}
{{- if not (empty $labels) -}}
{{- $labels | toYaml -}}
{{- end -}}
{{- end -}}

View file

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

View file

@ -0,0 +1,24 @@
{{/*
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 -}}
{{- $objectName = printf "%s-%s" $objectName $identifier -}}
{{- end -}}
{{- $_ := set $objectValues "name" $objectName -}}
{{- $_ := set $objectValues "identifier" $identifier -}}
{{- /* Return the PVC object */ -}}
{{- $objectValues | toYaml -}}
{{- end -}}

View file

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

View file

@ -0,0 +1,24 @@
{{/*
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 -}}
{{- $objectName = printf "%s-%s" $objectName $objectValues.nameOverride -}}
{{- else -}}
{{- if ne $identifier (include "bjw-s.common.lib.route.primary" $rootContext) -}}
{{- $objectName = printf "%s-%s" $objectName $identifier -}}
{{- end -}}
{{- end -}}
{{- $_ := set $objectValues "name" $objectName -}}
{{- $_ := set $objectValues "identifier" $identifier -}}
{{- /* Return the Route object */ -}}
{{- $objectValues | toYaml -}}
{{- end -}}

View file

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

View file

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

View file

@ -2,9 +2,12 @@
Return the enabled ports for a given Service object.
*/}}
{{- define "bjw-s.common.lib.service.enabledPorts" -}}
{{- $rootContext := .rootContext -}}
{{- $serviceObject := .serviceObject -}}
{{- $enabledPorts := dict -}}
{{- range $name, $port := .values.ports -}}
{{- range $name, $port := $serviceObject.ports -}}
{{- if kindIs "map" $port -}}
{{- $portEnabled := true -}}
{{- if hasKey $port "enabled" -}}

View file

@ -2,17 +2,22 @@
Return the enabled services.
*/}}
{{- define "bjw-s.common.lib.service.enabledServices" -}}
{{- $rootContext := .rootContext -}}
{{- $enabledServices := dict -}}
{{- range $name, $service := .Values.service -}}
{{- range $name, $service := $rootContext.Values.service -}}
{{- if kindIs "map" $service -}}
{{- /* Enable Service by default, but allow override */ -}}
{{- $serviceEnabled := true -}}
{{- if hasKey $service "enabled" -}}
{{- $serviceEnabled = $service.enabled -}}
{{- end -}}
{{- if $serviceEnabled -}}
{{- $_ := set $enabledServices $name . -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $enabledServices | toYaml -}}
{{- end -}}

View file

@ -0,0 +1,13 @@
{{/*
Return a service Object by its Identifier.
*/}}
{{- define "bjw-s.common.lib.service.getByIdentifier" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- range $name, $serviceValues := $rootContext.Values.service -}}
{{- if eq $name $identifier -}}
{{- include "bjw-s.common.lib.service.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $serviceValues) -}}
{{- end -}}
{{- end -}}
{{- end -}}

View file

@ -1,18 +0,0 @@
{{/*
Return the primary service object
*/}}
{{- define "bjw-s.common.lib.service.primary" -}}
{{- $enabledServices := (include "bjw-s.common.lib.service.enabledServices" $ | fromYaml ) }}
{{- $result := "" -}}
{{- range $name, $service := $enabledServices -}}
{{- if and (hasKey $service "primary") $service.primary -}}
{{- $result = $name -}}
{{- end -}}
{{- end -}}
{{- if not $result -}}
{{- $result = keys $enabledServices | first -}}
{{- end -}}
{{- $result -}}
{{- end -}}

View file

@ -0,0 +1,30 @@
{{/*
Return the primary service object for a controller
*/}}
{{- define "bjw-s.common.lib.service.primaryForController" -}}
{{- $rootContext := .rootContext -}}
{{- $controllerIdentifier := .controllerIdentifier -}}
{{- $identifier := "" -}}
{{- $result := dict -}}
{{- /* Loop over all enabled services */ -}}
{{- $enabledServices := (include "bjw-s.common.lib.service.enabledServices" (dict "rootContext" $rootContext) | fromYaml ) }}
{{- if $enabledServices -}}
{{- range $name, $service := $enabledServices -}}
{{- /* Determine the Service that has been marked as primary */ -}}
{{- if and (hasKey $service "primary") $service.primary -}}
{{- $identifier = $name -}}
{{- $result = $service -}}
{{- end -}}
{{- end -}}
{{- /* Return the first Service if none has been explicitly marked as primary */ -}}
{{- if not $result -}}
{{- $identifier = keys $enabledServices | first -}}
{{- $result = get $enabledServices $identifier -}}
{{- end -}}
{{- include "bjw-s.common.lib.service.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $result) -}}
{{- end -}}
{{- end -}}

View file

@ -2,17 +2,24 @@
Return the primary port for a given Service object.
*/}}
{{- define "bjw-s.common.lib.service.primaryPort" -}}
{{- $enabledPorts := (include "bjw-s.common.lib.service.enabledPorts" . | fromYaml) }}
{{- $rootContext := .rootContext -}}
{{- $serviceObject := .serviceObject -}}
{{- $result := "" -}}
{{- /* Loop over all enabled ports */ -}}
{{- $enabledPorts := include "bjw-s.common.lib.service.enabledPorts" (dict "rootContext" $rootContext "serviceObject" $serviceObject) | fromYaml }}
{{- range $name, $port := $enabledPorts -}}
{{- /* Determine the port that has been marked as primary */ -}}
{{- if and (hasKey $port "primary") $port.primary -}}
{{- $result = $name -}}
{{- $result = $port -}}
{{- end -}}
{{- end -}}
{{- /* Return the first port if none has been explicitly marked as primary */ -}}
{{- if not $result -}}
{{- $result = keys $enabledPorts | first -}}
{{- $firstPortKey := keys $enabledPorts | first -}}
{{- $result = get $enabledPorts $firstPortKey -}}
{{- end -}}
{{- $result -}}
{{- $result | toYaml -}}
{{- end -}}

View file

@ -0,0 +1,37 @@
{{/*
Validate Service values
*/}}
{{- define "bjw-s.common.lib.service.validate" -}}
{{- $rootContext := .rootContext -}}
{{- $serviceObject := .object -}}
{{- if empty (get $serviceObject "controller") -}}
{{- fail (printf "controller is required for Service. (service: %s)" $serviceObject.identifier) -}}
{{- end -}}
{{- /* Validate Service type */ -}}
{{- $validServiceTypes := (list "ClusterIP" "LoadBalancer" "NodePort" "ExternalName" "ExternalIP") -}}
{{- if and $serviceObject.type (not (mustHas $serviceObject.type $validServiceTypes)) -}}
{{- fail (
printf "invalid service type \"%s\" for Service with key \"%s\". Allowed values are [%s]"
$serviceObject.type
$serviceObject.identifier
(join ", " $validServiceTypes)
) -}}
{{- end -}}
{{- if ne $serviceObject.type "ExternalName" -}}
{{- $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) -}}
{{- 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) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}

View file

@ -0,0 +1,24 @@
{{/*
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 -}}
{{- $objectName = printf "%s-%s" $objectName $objectValues.nameOverride -}}
{{- else -}}
{{- if not $objectValues.primary -}}
{{- $objectName = printf "%s-%s" $objectName $identifier -}}
{{- end -}}
{{- end -}}
{{- $_ := set $objectValues "name" $objectName -}}
{{- $_ := set $objectValues "identifier" $identifier -}}
{{- /* Return the Service object */ -}}
{{- $objectValues | toYaml -}}
{{- end -}}

View file

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

View file

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

View file

@ -0,0 +1,11 @@
{{/*
Validate serviceMonitor values
*/}}
{{- define "bjw-s.common.lib.serviceMonitor.validate" -}}
{{- $rootContext := .rootContext -}}
{{- $serviceMonitorObject := .object -}}
{{- if not $serviceMonitorObject.endpoints -}}
{{- fail (printf "endpoints are required for serviceMonitor with key \"%v\"" $serviceMonitorObject.identifier) -}}
{{- end -}}
{{- end -}}

View file

@ -0,0 +1,24 @@
{{/*
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 -}}
{{- $objectName = printf "%s-%s" $objectName $objectValues.nameOverride -}}
{{- else -}}
{{- if ne $identifier "main" -}}
{{- $objectName = printf "%s-%s" $objectName $identifier -}}
{{- end -}}
{{- end -}}
{{- $_ := set $objectValues "name" $objectName -}}
{{- $_ := set $objectValues "identifier" $identifier -}}
{{- /* Return the ServiceMonitor object */ -}}
{{- $objectValues | toYaml -}}
{{- end -}}

View file

@ -0,0 +1,23 @@
{{/*
Validate StatefulSet values
*/}}
{{- define "bjw-s.common.lib.statefulset.validate" -}}
{{- $rootContext := .rootContext -}}
{{- $statefulsetValues := .object -}}
{{- if and (ne $statefulsetValues.strategy "OnDelete") (ne $statefulsetValues.strategy "RollingUpdate") -}}
{{- fail (printf "Not a valid strategy type for StatefulSet. (controller: %s, strategy: %s)" $statefulsetValues.identifier $statefulsetValues.strategy) -}}
{{- end -}}
{{- if not (empty (dig "statefulset" "volumeClaimTemplates" "" $statefulsetValues)) -}}
{{- range $index, $volumeClaimTemplate := $statefulsetValues.statefulset.volumeClaimTemplates -}}
{{- if empty (get . "size") -}}
{{- fail (printf "size is required for volumeClaimTemplate. (controller: %s, volumeClaimTemplate: %s)" $statefulsetValues.identifier $volumeClaimTemplate.name) -}}
{{- end -}}
{{- if empty (get . "accessMode") -}}
{{- fail (printf "accessMode is required for volumeClaimTemplate. (controller: %s, volumeClaimTemplate: %s)" $statefulsetValues.identifier $volumeClaimTemplate.name) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}

View file

@ -0,0 +1,14 @@
{{/*
Convert StatefulSet values to an object
*/}}
{{- define "bjw-s.common.lib.statefulset.valuesToObject" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $objectValues := .values -}}
{{- $strategy := default "RollingUpdate" $objectValues.strategy -}}
{{- $_ := set $objectValues "strategy" $strategy -}}
{{- /* Return the StatefulSet object */ -}}
{{- $objectValues | toYaml -}}
{{- end -}}

View file

@ -0,0 +1,45 @@
{{/*
Basic VolumeClaimTemplate template
*/}}
{{- define "bjw-s.common.lib.statefulset.volumeclaimtemplate" -}}
{{- $rootContext := .rootContext -}}
{{- $values := .values -}}
metadata:
name: {{ $values.name }}
{{- with ($values.labels | default dict) }}
labels: {{- toYaml . | nindent 10 }}
{{- end }}
{{- with ($values.annotations | default dict) }}
annotations: {{- toYaml . | nindent 10 }}
{{- end }}
spec:
accessModes:
- {{ $values.accessMode | quote }}
resources:
requests:
storage: {{ $values.size | quote }}
{{- if $values.storageClass }}
storageClassName: {{ if (eq "-" $values.storageClass) }}""{{- else }}{{ $values.storageClass | quote }}{{- end }}
{{- end }}
{{- end -}}
{{/*
VolumeClaimTemplates for StatefulSet
*/}}
{{- define "bjw-s.common.lib.statefulset.volumeclaimtemplates" -}}
{{- $rootContext := .rootContext -}}
{{- $statefulsetObject := .statefulsetObject -}}
{{- /* Default to empty list */ -}}
{{- $volumeClaimTemplates := list -}}
{{- range $index, $volumeClaimTemplate := $statefulsetObject.statefulset.volumeClaimTemplates }}
{{- $vct := include "bjw-s.common.lib.statefulset.volumeclaimtemplate" (dict "rootContext" $rootContext "values" $volumeClaimTemplate) -}}
{{- $volumeClaimTemplates = append $volumeClaimTemplates ($vct | fromYaml) -}}
{{- end -}}
{{- if not (empty $volumeClaimTemplates) -}}
{{ $volumeClaimTemplates | toYaml }}
{{- end -}}
{{- end -}}