mirror of
https://github.com/bjw-s-labs/helm-charts.git
synced 2025-07-04 00:47:04 +02:00
feat(common): Release version 2.0.0-beta.1 (#173)
This commit is contained in:
parent
19767d668c
commit
7b6ee00be6
189 changed files with 3110 additions and 3023 deletions
|
@ -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 -}}
|
|
@ -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 -}}
|
|
@ -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 -}}
|
|
@ -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 -}}
|
51
charts/library/common/templates/lib/container/_spec.tpl
Normal file
51
charts/library/common/templates/lib/container/_spec.tpl
Normal 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 -}}
|
11
charts/library/common/templates/lib/container/_validate.tpl
Normal file
11
charts/library/common/templates/lib/container/_validate.tpl
Normal 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 -}}
|
|
@ -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 -}}
|
|
@ -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 }}
|
|
@ -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 -}}
|
|
@ -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 -}}
|
|
@ -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 -}}
|
|
@ -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 -}}
|
|
@ -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 -}}
|
|
@ -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 -}}
|
|
@ -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 -}}
|
Loading…
Add table
Add a link
Reference in a new issue