From 04a3aa95403984d5c9400f563d7e99cc9cc4bda9 Mon Sep 17 00:00:00 2001 From: kjeld Schouten-Lebbing Date: Sun, 23 Jan 2022 15:11:09 +0100 Subject: [PATCH] feat(common): add upgrade and install specific initContainers --- charts/library/common/Chart.yaml | 2 +- .../common/templates/lib/controller/_pod.tpl | 26 +++++++++++++++++++ charts/library/common/values.yaml | 6 +++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/charts/library/common/Chart.yaml b/charts/library/common/Chart.yaml index bd190101045..eeef0dd769b 100644 --- a/charts/library/common/Chart.yaml +++ b/charts/library/common/Chart.yaml @@ -15,4 +15,4 @@ maintainers: name: common sources: null type: library -version: 8.13.5 +version: 8.14.0 diff --git a/charts/library/common/templates/lib/controller/_pod.tpl b/charts/library/common/templates/lib/controller/_pod.tpl index 27807239bd8..78e93f4548c 100644 --- a/charts/library/common/templates/lib/controller/_pod.tpl +++ b/charts/library/common/templates/lib/controller/_pod.tpl @@ -63,6 +63,32 @@ initContainers: {{- end }} {{- tpl (toYaml $initContainers) $ | nindent 2 }} {{- end }} + {{- if .Release.IsInstall }} + {{- if .Values.installContainers }} + {{- $initContainers := list }} + {{- range $index, $key := (keys .Values.initContainers | uniq | sortAlpha) }} + {{- $container := get $.Values.initContainers $key }} + {{- if not $container.name -}} + {{- $_ := set $container "name" $key }} + {{- end }} + {{- $initContainers = append $initContainers $container }} + {{- end }} + {{- tpl (toYaml $initContainers) $ | nindent 2 }} + {{- end }} + {{- end }} + {{- if .Release.IsUpgrade }} + {{- if .Values.upgradeContainers }} + {{- $initContainers := list }} + {{- range $index, $key := (keys .Values.initContainers | uniq | sortAlpha) }} + {{- $container := get $.Values.initContainers $key }} + {{- if not $container.name -}} + {{- $_ := set $container "name" $key }} + {{- end }} + {{- $initContainers = append $initContainers $container }} + {{- end }} + {{- tpl (toYaml $initContainers) $ | nindent 2 }} + {{- end }} + {{- end }} containers: {{- include "common.controller.mainContainer" . | nindent 2 }} {{- with .Values.additionalContainers }} diff --git a/charts/library/common/values.yaml b/charts/library/common/values.yaml index 5ef1504c898..654abfdc908 100644 --- a/charts/library/common/values.yaml +++ b/charts/library/common/values.yaml @@ -334,6 +334,12 @@ securityContext: # -- Configure the lifecycle for the main container lifecycle: {} +# -- These containers will be run, as an initcontainer, a single time at install only. +installContainers: {} + +# -- These containers will be run, as an initcontainer, a single time at each edit or update of the chart. +upgradeContainers: {} + # -- Specify any initContainers here as dictionary items. Each initContainer should have its own key. # The dictionary item key will determine the order. Helm templates can be used. initContainers: {}