From ee5c73d6490919ced566ec162c2f5e0ae3c3cf46 Mon Sep 17 00:00:00 2001 From: Nguyen Huu Kim <13513658+kimyvgy@users.noreply.github.com> Date: Fri, 26 Jul 2024 13:34:16 +0700 Subject: [PATCH] refactor(instant-chart): render containers & initContainers --- charts/instant-chart/templates/_helpers.tpl | 12 ++++++++++++ charts/instant-chart/templates/deployment.yaml | 10 ++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/charts/instant-chart/templates/_helpers.tpl b/charts/instant-chart/templates/_helpers.tpl index 7794d60..14c1b6d 100644 --- a/charts/instant-chart/templates/_helpers.tpl +++ b/charts/instant-chart/templates/_helpers.tpl @@ -80,3 +80,15 @@ Clean volumes by removing .persistentVolumeClaim.requests {{- end -}} {{- $cleanVolumes | toYaml | nindent 0 | trim -}} {{- end -}} + +{{/* +Generate the container definitions +Usage: +{{- include "instant-chart.containers" (dict "containers" .Values.containers "prefix" "container") | trim | nindent 6 -}} +*/}} +{{- define "instant-chart.containers" -}} +{{- range $index, $container := .containers }} +- name: {{ $container.name | default (printf "%s-%d" $.prefix $index) }} + {{- omit $container "name" | toYaml | nindent 2 }} +{{- end -}} +{{- end -}} diff --git a/charts/instant-chart/templates/deployment.yaml b/charts/instant-chart/templates/deployment.yaml index d407a8a..fc94201 100644 --- a/charts/instant-chart/templates/deployment.yaml +++ b/charts/instant-chart/templates/deployment.yaml @@ -22,16 +22,10 @@ spec: {{- include "instant-chart.labels" . | nindent 8 }} spec: containers: - {{- range $index, $container := .Values.containers }} - - name: {{ $container.name | default (printf "container-%d" $index) }} - {{- omit $container "name" | toYaml | nindent 8 }} - {{- end }} + {{- include "instant-chart.containers" (dict "containers" .Values.containers "prefix" "container") | trim | nindent 6 -}} {{- with .Values.initContainers }} initContainers: - {{- range $index, $container := . }} - - name: {{ $container.name | default (printf "init-%d" $index) }} - {{- omit $container "name" | toYaml | nindent 8 }} - {{- end }} + {{- include "instant-chart.containers" (dict "containers" . "prefix" "init") | trim | nindent 6 -}} {{- end }} {{- if .Values.volumes }} volumes: