diff --git a/charts/common/Chart.yaml b/charts/common/Chart.yaml index 3204b9b2..e2646e2a 100644 --- a/charts/common/Chart.yaml +++ b/charts/common/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: common description: Function library for k8s-at-home charts type: library -version: 1.0.4 +version: 1.0.5 keywords: - k8s-at-home - common diff --git a/charts/common/templates/_deployment.tpl b/charts/common/templates/_deployment.tpl index 92bdebc6..694d1800 100644 --- a/charts/common/templates/_deployment.tpl +++ b/charts/common/templates/_deployment.tpl @@ -38,7 +38,7 @@ spec: {{- end }} volumes: - {{- include "common.controller.volumes" . | nindent 6 }} + {{- include "common.controller.volumes" . | trim | nindent 6 }} {{- with .Values.nodeSelector }} nodeSelector: diff --git a/charts/common/templates/_statefulset.tpl b/charts/common/templates/_statefulset.tpl index 5f652fef..c18568bf 100644 --- a/charts/common/templates/_statefulset.tpl +++ b/charts/common/templates/_statefulset.tpl @@ -39,7 +39,7 @@ spec: {{- end }} volumes: - {{- include "common.controller.volumes" . | nindent 6 }} + {{- include "common.controller.volumes" . | trim | nindent 6 }} {{- with .Values.nodeSelector }} nodeSelector: diff --git a/charts/common/templates/addons/vpn/_configmap.tpl b/charts/common/templates/addons/vpn/_configmap.tpl index d0af61c9..48266754 100644 --- a/charts/common/templates/addons/vpn/_configmap.tpl +++ b/charts/common/templates/addons/vpn/_configmap.tpl @@ -10,17 +10,17 @@ metadata: labels: {{- include "common.labels" . | nindent 4 }} data: -{{- if .Values.addons.vpn.configFile }} +{{- with .Values.addons.vpn.configFile }} vpnConfigfile: |- - {{- .Values.addons.vpn.configFile | nindent 4}} + {{- . | nindent 4}} {{- end }} -{{- if .Values.addons.vpn.scripts.up }} +{{- with .Values.addons.vpn.scripts.up }} up.sh: |- - {{- .Values.addons.vpn.scripts.up | nindent 4}} + {{- . | nindent 4}} {{- end }} -{{- if .Values.addons.vpn.scripts.down }} +{{- with .Values.addons.vpn.scripts.down }} down.sh: |- - {{- .Values.addons.vpn.scripts.down | nindent 4}} + {{- . | nindent 4}} {{- end }} {{- end -}} {{- end -}} diff --git a/charts/common/templates/addons/vpn/_networkpolicy.tpl b/charts/common/templates/addons/vpn/_networkpolicy.tpl index 4b4eaf86..e2b008a2 100644 --- a/charts/common/templates/addons/vpn/_networkpolicy.tpl +++ b/charts/common/templates/addons/vpn/_networkpolicy.tpl @@ -14,8 +14,8 @@ spec: policyTypes: - Egress egress: - {{- if .Values.addons.vpn.networkPolicy.egress }} - {{- .Values.addons.vpn.networkPolicy.egress | toYaml | nindent 4 }} + {{- with .Values.addons.vpn.networkPolicy.egress }} + {{- . | toYaml | nindent 4 }} {{- end -}} {{- end -}} {{- end -}} diff --git a/charts/common/templates/addons/vpn/_vpn.tpl b/charts/common/templates/addons/vpn/_vpn.tpl index 0f179d05..66b5eee7 100644 --- a/charts/common/templates/addons/vpn/_vpn.tpl +++ b/charts/common/templates/addons/vpn/_vpn.tpl @@ -15,7 +15,7 @@ Template to render VPN addon {{- $configmap := include "common.addon.vpn.configmap" . -}} {{- if $configmap -}} {{- print "---" | nindent 0 -}} - {{- $configmap -}} + {{- $configmap | nindent 0 -}} {{- end -}} {{/* Append the vpn config volume to the additionalVolumes */}} @@ -29,7 +29,7 @@ Template to render VPN addon {{- $networkpolicy := include "common.addon.vpn.networkpolicy" . -}} {{- if $networkpolicy -}} {{- print "---" | nindent 0 -}} - {{- $networkpolicy -}} + {{- $networkpolicy | nindent 0 -}} {{- end -}} {{- end -}} {{- end -}} diff --git a/charts/common/templates/addons/vpn/openvpn/_addon.tpl b/charts/common/templates/addons/vpn/openvpn/_addon.tpl index 748a4646..da84a3e3 100644 --- a/charts/common/templates/addons/vpn/openvpn/_addon.tpl +++ b/charts/common/templates/addons/vpn/openvpn/_addon.tpl @@ -5,7 +5,7 @@ Template to render OpenVPN addon {{/* Append the openVPN container to the additionalContainers */}} {{- $container := include "common.addon.openvpn.container" . | fromYaml -}} {{- if $container -}} - {{- $additionalContainers := append .Values.additionalContainers $container }} + {{- $additionalContainers := append .Values.additionalContainers $container -}} {{- $_ := set .Values "additionalContainers" $additionalContainers -}} {{- end -}} @@ -13,6 +13,6 @@ Template to render OpenVPN addon {{- $secret := include "common.addon.openvpn.secret" . -}} {{- if $secret -}} {{- print "---" | nindent 0 -}} - {{- $secret -}} + {{- $secret | nindent 0 -}} {{- end -}} {{- end -}} diff --git a/charts/common/templates/addons/vpn/openvpn/_container.tpl b/charts/common/templates/addons/vpn/openvpn/_container.tpl index a5f96bdd..2cdd344a 100644 --- a/charts/common/templates/addons/vpn/openvpn/_container.tpl +++ b/charts/common/templates/addons/vpn/openvpn/_container.tpl @@ -9,9 +9,9 @@ securityContext: capabilities: add: - NET_ADMIN -{{- if .Values.addons.vpn.env }} +{{- with .Values.addons.vpn.env }} env: -{{- range $k, $v := .Values.addons.vpn.env }} +{{- range $k, $v := . }} - name: {{ $k }} value: {{ $v }} {{- end }} @@ -43,15 +43,19 @@ volumeMounts: subPath: down.sh {{- end }} {{- if .Values.persistence.shared.enabled }} -- mountPath: {{ .Values.persistence.shared.mountPath }} - name: shared + - mountPath: {{ .Values.persistence.shared.mountPath }} + name: shared {{- end }} -{{- if .Values.addons.vpn.additionalVolumeMounts }} - {{- toYaml .Values.addons.vpn.additionalVolumeMounts | nindent 2 }} +{{- with .Values.addons.vpn.additionalVolumeMounts }} + {{- toYaml . | nindent 2 }} {{- end }} {{- end }} -{{- if .Values.addons.vpn.livenessProbe }} +{{- with .Values.addons.vpn.livenessProbe }} livenessProbe: - {{- toYaml .Values.addons.vpn.livenessProbe | nindent 4 }} + {{- toYaml . | nindent 4 }} {{- end -}} +{{- with .Values.addons.vpn.resources }} +resources: + {{- toYaml . | nindent 4 }} +{{- end }} {{- end -}} diff --git a/charts/common/templates/addons/vpn/openvpn/_secret.tpl b/charts/common/templates/addons/vpn/openvpn/_secret.tpl index 54d99e98..8b8bd457 100644 --- a/charts/common/templates/addons/vpn/openvpn/_secret.tpl +++ b/charts/common/templates/addons/vpn/openvpn/_secret.tpl @@ -2,14 +2,14 @@ The OpenVPN secrets to be included */}} {{- define "common.addon.openvpn.secret" -}} -{{- if .Values.addons.vpn.openvpn.auth -}} +{{- with .Values.addons.vpn.openvpn.auth -}} apiVersion: v1 kind: Secret metadata: - name: {{ template "common.names.fullname" . }}-openvpn + name: {{ template "common.names.fullname" $ }}-openvpn labels: - {{- include "common.labels" . | nindent 4 }} + {{- include "common.labels" $ | nindent 4 }} data: - VPN_AUTH: {{ .Values.addons.vpn.openvpn.auth | b64enc }} + VPN_AUTH: {{ . | b64enc }} {{- end -}} {{- end -}} diff --git a/charts/common/templates/addons/vpn/wireguard/_addon.tpl b/charts/common/templates/addons/vpn/wireguard/_addon.tpl index b2863b4a..59a78ee5 100644 --- a/charts/common/templates/addons/vpn/wireguard/_addon.tpl +++ b/charts/common/templates/addons/vpn/wireguard/_addon.tpl @@ -5,7 +5,7 @@ Template to render Wireguard addon {{/* Append the Wireguard container to the additionalContainers */}} {{- $container := include "common.addon.wireguard.container" . | fromYaml -}} {{- if $container -}} - {{- $additionalContainers := append .Values.additionalContainers $container }} + {{- $additionalContainers := append .Values.additionalContainers $container -}} {{- $_ := set .Values "additionalContainers" $additionalContainers -}} {{- end -}} {{- end -}} diff --git a/charts/common/templates/addons/vpn/wireguard/_container.tpl b/charts/common/templates/addons/vpn/wireguard/_container.tpl index 6d5e71da..71500060 100644 --- a/charts/common/templates/addons/vpn/wireguard/_container.tpl +++ b/charts/common/templates/addons/vpn/wireguard/_container.tpl @@ -11,13 +11,13 @@ securityContext: add: - NET_ADMIN - SYS_MODULE -{{- if .Values.addons.vpn.env }} +{{- with .Values.addons.vpn.env }} env: -{{- range $k, $v := .Values.addons.vpn.env }} +{{- range $k, $v := . }} - name: {{ $k }} value: {{ $v }} {{- end }} -{{- end }} +{{- end }} {{- if or .Values.addons.vpn.configFile .Values.addons.vpn.scripts.up .Values.addons.vpn.scripts.down .Values.addons.vpn.additionalVolumeMounts .Values.persistence.shared.enabled }} volumeMounts: {{- if .Values.addons.vpn.configFile }} @@ -36,15 +36,19 @@ volumeMounts: subPath: down.sh {{- end }} {{- if .Values.persistence.shared.enabled }} -- mountPath: {{ .Values.persistence.shared.mountPath }} - name: shared + - mountPath: {{ .Values.persistence.shared.mountPath }} + name: shared {{- end }} -{{- if .Values.addons.vpn.additionalVolumeMounts }} - {{- toYaml .Values.addons.vpn.additionalVolumeMounts | nindent 2 }} +{{- with .Values.addons.vpn.additionalVolumeMounts }} + {{- toYaml . | nindent 2 }} {{- end }} {{- end }} -{{- if .Values.addons.vpn.livenessProbe }} +{{- with .Values.addons.vpn.livenessProbe }} livenessProbe: - {{- toYaml .Values.addons.vpn.livenessProbe | nindent 4 }} + {{- toYaml . | nindent 4 }} {{- end -}} +{{- with .Values.addons.vpn.resources }} +resources: + {{- toYaml . | nindent 4 }} +{{- end }} {{- end -}} diff --git a/charts/common/templates/lib/controller/_container.tpl b/charts/common/templates/lib/controller/_container.tpl index 79a1bac5..6d58d5bd 100644 --- a/charts/common/templates/lib/controller/_container.tpl +++ b/charts/common/templates/lib/controller/_container.tpl @@ -38,6 +38,6 @@ {{- with .Values.resources }} resources: - {{- toYaml . | nindent 12 }} + {{- toYaml . | nindent 4 }} {{- end }} {{- end -}} diff --git a/charts/common/templates/lib/controller/_volumes.tpl b/charts/common/templates/lib/controller/_volumes.tpl index 6767a30e..43f16e25 100644 --- a/charts/common/templates/lib/controller/_volumes.tpl +++ b/charts/common/templates/lib/controller/_volumes.tpl @@ -2,32 +2,30 @@ volumes included by the controller */}} {{- define "common.controller.volumes" -}} -{{/* Store the context to refer in later scope */}} -{{- $context := . -}} -{{/* Determine the PVC name */}} -{{- range $index, $PVC := .Values.persistence }} -{{- if $PVC.enabled }} - -{{- $claimName := "" -}} -{{- if $PVC.existingClaim -}} - {{- $claimName = $PVC.existingClaim -}} -{{- else }} - {{- if $PVC.nameSuffix -}} - {{- $claimName = printf "%s-%s" (include "common.names.fullname" $context) $PVC.nameSuffix -}} - {{- else }} - {{- $claimName = printf "%s-%s" (include "common.names.fullname" $context) $index -}} - {{- end -}} -{{- end -}} +{{- range $index, $persistence := .Values.persistence }} +{{- if $persistence.enabled }} - name: {{ $index }} - {{- if not $PVC.emptyDir }} +{{- if $persistence.existingClaim }} +{{/* Always prefer an existingClaim if that is set */}} persistentVolumeClaim: - claimName: {{ $claimName }} - {{- else }} + claimName: {{ $persistence.existingClaim }} +{{- else -}} + {{- if $persistence.emptyDir -}} + {{/* Always prefer an emptyDir next if that is set */}} emptyDir: {} + {{- else -}} + {{/* Otherwise refer to the PVC name */}} + persistentVolumeClaim: + {{- if $persistence.nameSuffix }} + claimName: {{ printf "%s-%s" (include "common.names.fullname" $) $persistence.nameSuffix }} + {{- else }} + claimName: {{ printf "%s-%s" (include "common.names.fullname" $) $index }} + {{- end }} {{- end }} -{{ end }} +{{- end }} +{{- end }} {{- end }} {{- if .Values.additionalVolumes }} {{- toYaml .Values.additionalVolumes | nindent 0 }} {{- end }} -{{- end }} +{{- end -}}