[common] Indenting and fix volume logic (#130)

This commit is contained in:
Bernd Schörgers 2020-11-09 13:55:25 +01:00 committed by GitHub
parent 899a444153
commit b083c8516c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 65 additions and 59 deletions

View File

@ -2,7 +2,7 @@ apiVersion: v2
name: common name: common
description: Function library for k8s-at-home charts description: Function library for k8s-at-home charts
type: library type: library
version: 1.0.4 version: 1.0.5
keywords: keywords:
- k8s-at-home - k8s-at-home
- common - common

View File

@ -38,7 +38,7 @@ spec:
{{- end }} {{- end }}
volumes: volumes:
{{- include "common.controller.volumes" . | nindent 6 }} {{- include "common.controller.volumes" . | trim | nindent 6 }}
{{- with .Values.nodeSelector }} {{- with .Values.nodeSelector }}
nodeSelector: nodeSelector:

View File

@ -39,7 +39,7 @@ spec:
{{- end }} {{- end }}
volumes: volumes:
{{- include "common.controller.volumes" . | nindent 6 }} {{- include "common.controller.volumes" . | trim | nindent 6 }}
{{- with .Values.nodeSelector }} {{- with .Values.nodeSelector }}
nodeSelector: nodeSelector:

View File

@ -10,17 +10,17 @@ metadata:
labels: labels:
{{- include "common.labels" . | nindent 4 }} {{- include "common.labels" . | nindent 4 }}
data: data:
{{- if .Values.addons.vpn.configFile }} {{- with .Values.addons.vpn.configFile }}
vpnConfigfile: |- vpnConfigfile: |-
{{- .Values.addons.vpn.configFile | nindent 4}} {{- . | nindent 4}}
{{- end }} {{- end }}
{{- if .Values.addons.vpn.scripts.up }} {{- with .Values.addons.vpn.scripts.up }}
up.sh: |- up.sh: |-
{{- .Values.addons.vpn.scripts.up | nindent 4}} {{- . | nindent 4}}
{{- end }} {{- end }}
{{- if .Values.addons.vpn.scripts.down }} {{- with .Values.addons.vpn.scripts.down }}
down.sh: |- down.sh: |-
{{- .Values.addons.vpn.scripts.down | nindent 4}} {{- . | nindent 4}}
{{- end }} {{- end }}
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}

View File

@ -14,8 +14,8 @@ spec:
policyTypes: policyTypes:
- Egress - Egress
egress: egress:
{{- if .Values.addons.vpn.networkPolicy.egress }} {{- with .Values.addons.vpn.networkPolicy.egress }}
{{- .Values.addons.vpn.networkPolicy.egress | toYaml | nindent 4 }} {{- . | toYaml | nindent 4 }}
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}

View File

@ -15,7 +15,7 @@ Template to render VPN addon
{{- $configmap := include "common.addon.vpn.configmap" . -}} {{- $configmap := include "common.addon.vpn.configmap" . -}}
{{- if $configmap -}} {{- if $configmap -}}
{{- print "---" | nindent 0 -}} {{- print "---" | nindent 0 -}}
{{- $configmap -}} {{- $configmap | nindent 0 -}}
{{- end -}} {{- end -}}
{{/* Append the vpn config volume to the additionalVolumes */}} {{/* Append the vpn config volume to the additionalVolumes */}}
@ -29,7 +29,7 @@ Template to render VPN addon
{{- $networkpolicy := include "common.addon.vpn.networkpolicy" . -}} {{- $networkpolicy := include "common.addon.vpn.networkpolicy" . -}}
{{- if $networkpolicy -}} {{- if $networkpolicy -}}
{{- print "---" | nindent 0 -}} {{- print "---" | nindent 0 -}}
{{- $networkpolicy -}} {{- $networkpolicy | nindent 0 -}}
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}

View File

@ -5,7 +5,7 @@ Template to render OpenVPN addon
{{/* Append the openVPN container to the additionalContainers */}} {{/* Append the openVPN container to the additionalContainers */}}
{{- $container := include "common.addon.openvpn.container" . | fromYaml -}} {{- $container := include "common.addon.openvpn.container" . | fromYaml -}}
{{- if $container -}} {{- if $container -}}
{{- $additionalContainers := append .Values.additionalContainers $container }} {{- $additionalContainers := append .Values.additionalContainers $container -}}
{{- $_ := set .Values "additionalContainers" $additionalContainers -}} {{- $_ := set .Values "additionalContainers" $additionalContainers -}}
{{- end -}} {{- end -}}
@ -13,6 +13,6 @@ Template to render OpenVPN addon
{{- $secret := include "common.addon.openvpn.secret" . -}} {{- $secret := include "common.addon.openvpn.secret" . -}}
{{- if $secret -}} {{- if $secret -}}
{{- print "---" | nindent 0 -}} {{- print "---" | nindent 0 -}}
{{- $secret -}} {{- $secret | nindent 0 -}}
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}

View File

@ -9,9 +9,9 @@ securityContext:
capabilities: capabilities:
add: add:
- NET_ADMIN - NET_ADMIN
{{- if .Values.addons.vpn.env }} {{- with .Values.addons.vpn.env }}
env: env:
{{- range $k, $v := .Values.addons.vpn.env }} {{- range $k, $v := . }}
- name: {{ $k }} - name: {{ $k }}
value: {{ $v }} value: {{ $v }}
{{- end }} {{- end }}
@ -43,15 +43,19 @@ volumeMounts:
subPath: down.sh subPath: down.sh
{{- end }} {{- end }}
{{- if .Values.persistence.shared.enabled }} {{- if .Values.persistence.shared.enabled }}
- mountPath: {{ .Values.persistence.shared.mountPath }} - mountPath: {{ .Values.persistence.shared.mountPath }}
name: shared name: shared
{{- end }} {{- end }}
{{- if .Values.addons.vpn.additionalVolumeMounts }} {{- with .Values.addons.vpn.additionalVolumeMounts }}
{{- toYaml .Values.addons.vpn.additionalVolumeMounts | nindent 2 }} {{- toYaml . | nindent 2 }}
{{- end }} {{- end }}
{{- end }} {{- end }}
{{- if .Values.addons.vpn.livenessProbe }} {{- with .Values.addons.vpn.livenessProbe }}
livenessProbe: livenessProbe:
{{- toYaml .Values.addons.vpn.livenessProbe | nindent 4 }} {{- toYaml . | nindent 4 }}
{{- end -}} {{- end -}}
{{- with .Values.addons.vpn.resources }}
resources:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end -}} {{- end -}}

View File

@ -2,14 +2,14 @@
The OpenVPN secrets to be included The OpenVPN secrets to be included
*/}} */}}
{{- define "common.addon.openvpn.secret" -}} {{- define "common.addon.openvpn.secret" -}}
{{- if .Values.addons.vpn.openvpn.auth -}} {{- with .Values.addons.vpn.openvpn.auth -}}
apiVersion: v1 apiVersion: v1
kind: Secret kind: Secret
metadata: metadata:
name: {{ template "common.names.fullname" . }}-openvpn name: {{ template "common.names.fullname" $ }}-openvpn
labels: labels:
{{- include "common.labels" . | nindent 4 }} {{- include "common.labels" $ | nindent 4 }}
data: data:
VPN_AUTH: {{ .Values.addons.vpn.openvpn.auth | b64enc }} VPN_AUTH: {{ . | b64enc }}
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}

View File

@ -5,7 +5,7 @@ Template to render Wireguard addon
{{/* Append the Wireguard container to the additionalContainers */}} {{/* Append the Wireguard container to the additionalContainers */}}
{{- $container := include "common.addon.wireguard.container" . | fromYaml -}} {{- $container := include "common.addon.wireguard.container" . | fromYaml -}}
{{- if $container -}} {{- if $container -}}
{{- $additionalContainers := append .Values.additionalContainers $container }} {{- $additionalContainers := append .Values.additionalContainers $container -}}
{{- $_ := set .Values "additionalContainers" $additionalContainers -}} {{- $_ := set .Values "additionalContainers" $additionalContainers -}}
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}

View File

@ -11,9 +11,9 @@ securityContext:
add: add:
- NET_ADMIN - NET_ADMIN
- SYS_MODULE - SYS_MODULE
{{- if .Values.addons.vpn.env }} {{- with .Values.addons.vpn.env }}
env: env:
{{- range $k, $v := .Values.addons.vpn.env }} {{- range $k, $v := . }}
- name: {{ $k }} - name: {{ $k }}
value: {{ $v }} value: {{ $v }}
{{- end }} {{- end }}
@ -36,15 +36,19 @@ volumeMounts:
subPath: down.sh subPath: down.sh
{{- end }} {{- end }}
{{- if .Values.persistence.shared.enabled }} {{- if .Values.persistence.shared.enabled }}
- mountPath: {{ .Values.persistence.shared.mountPath }} - mountPath: {{ .Values.persistence.shared.mountPath }}
name: shared name: shared
{{- end }} {{- end }}
{{- if .Values.addons.vpn.additionalVolumeMounts }} {{- with .Values.addons.vpn.additionalVolumeMounts }}
{{- toYaml .Values.addons.vpn.additionalVolumeMounts | nindent 2 }} {{- toYaml . | nindent 2 }}
{{- end }} {{- end }}
{{- end }} {{- end }}
{{- if .Values.addons.vpn.livenessProbe }} {{- with .Values.addons.vpn.livenessProbe }}
livenessProbe: livenessProbe:
{{- toYaml .Values.addons.vpn.livenessProbe | nindent 4 }} {{- toYaml . | nindent 4 }}
{{- end -}} {{- end -}}
{{- with .Values.addons.vpn.resources }}
resources:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end -}} {{- end -}}

View File

@ -38,6 +38,6 @@
{{- with .Values.resources }} {{- with .Values.resources }}
resources: resources:
{{- toYaml . | nindent 12 }} {{- toYaml . | nindent 4 }}
{{- end }} {{- end }}
{{- end -}} {{- end -}}

View File

@ -2,32 +2,30 @@
volumes included by the controller volumes included by the controller
*/}} */}}
{{- define "common.controller.volumes" -}} {{- define "common.controller.volumes" -}}
{{/* Store the context to refer in later scope */}} {{- range $index, $persistence := .Values.persistence }}
{{- $context := . -}} {{- if $persistence.enabled }}
{{/* 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 -}}
- name: {{ $index }} - name: {{ $index }}
{{- if not $PVC.emptyDir }} {{- if $persistence.existingClaim }}
{{/* Always prefer an existingClaim if that is set */}}
persistentVolumeClaim: persistentVolumeClaim:
claimName: {{ $claimName }} claimName: {{ $persistence.existingClaim }}
{{- else }} {{- else -}}
{{- if $persistence.emptyDir -}}
{{/* Always prefer an emptyDir next if that is set */}}
emptyDir: {} 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 }}
{{- end }} {{- end }}
{{- if .Values.additionalVolumes }} {{- if .Values.additionalVolumes }}
{{- toYaml .Values.additionalVolumes | nindent 0 }} {{- toYaml .Values.additionalVolumes | nindent 0 }}
{{- end }} {{- end }}
{{- end }} {{- end -}}