From b31f45c4b8328ee6be2171aee93f44bda370144e Mon Sep 17 00:00:00 2001 From: Yung Wood Date: Sun, 1 Sep 2024 17:20:39 +0930 Subject: [PATCH] feat: add templating to initContainers and sidecarContainers --- charts/minecraft/templates/_helpers.tpl | 2 +- charts/minecraft/templates/deployment.yaml | 15 +++++++------ charts/minecraft/templates/extra-list.yaml | 2 +- charts/minecraft/values.schema.json | 20 ++++++++++++++++- charts/minecraft/values.yaml | 26 ++++++++++++++++++++-- 5 files changed, 53 insertions(+), 12 deletions(-) diff --git a/charts/minecraft/templates/_helpers.tpl b/charts/minecraft/templates/_helpers.tpl index 7e5db1e8..0c400f62 100644 --- a/charts/minecraft/templates/_helpers.tpl +++ b/charts/minecraft/templates/_helpers.tpl @@ -39,7 +39,7 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this {{- end }} {{- end }} -{{- define "extraDeploy.render" -}} +{{- define "tplRender" -}} {{- $value := typeIs "string" .value | ternary .value (.value | toYaml) }} {{- if contains "{{" (toJson .value) }} {{- if .scope }} diff --git a/charts/minecraft/templates/deployment.yaml b/charts/minecraft/templates/deployment.yaml index 0e2d4f8c..0812437c 100644 --- a/charts/minecraft/templates/deployment.yaml +++ b/charts/minecraft/templates/deployment.yaml @@ -68,10 +68,6 @@ spec: {{- end }} securityContext: {{- toYaml .Values.podSecurityContext | nindent 8 }} - {{- if .Values.initContainers }} - initContainers: - {{- toYaml .Values.initContainers | nindent 8 }} - {{- end }} containers: - name: {{ template "minecraft.fullname" . }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" @@ -439,11 +435,12 @@ spec: securityContext: {{- toYaml .Values.securityContext | nindent 10 }} {{- end }} - {{- if .Values.sidecarContainers }} - {{- toYaml .Values.sidecarContainers | nindent 6 }} + {{- range .Values.sidecarContainers }} + - {{ include "tplRender" (dict "value" . "context" $) | nindent 8 | trim }} {{- end }} - {{- if or (eq .Values.mcbackup.backupMethod "rclone") (eq (include "isResticWithRclone" $) "true") }} + {{- if or .Values.initContainers (eq .Values.mcbackup.backupMethod "rclone") (eq (include "isResticWithRclone" $) "true") }} initContainers: + {{- if or (eq .Values.mcbackup.backupMethod "rclone") (eq (include "isResticWithRclone" $) "true") }} - name: init-container image: busybox command: ['sh', '-c', 'cp /secret/rclone.conf /config/rclone/'] @@ -452,6 +449,10 @@ spec: mountPath: /secret - name: rclone-config mountPath: /config/rclone + {{- end }} + {{- range .Values.initContainers }} + - {{ include "tplRender" (dict "value" . "context" $) | nindent 10 | trim }} + {{- end }} {{- end }} volumes: - name: tmp diff --git a/charts/minecraft/templates/extra-list.yaml b/charts/minecraft/templates/extra-list.yaml index 1bf92ded..4c44c9b8 100644 --- a/charts/minecraft/templates/extra-list.yaml +++ b/charts/minecraft/templates/extra-list.yaml @@ -1,4 +1,4 @@ {{- range .Values.extraDeploy }} --- -{{ include "extraDeploy.render" (dict "value" . "context" $) }} +{{ include "tplRender" (dict "value" . "context" $) }} {{- end }} diff --git a/charts/minecraft/values.schema.json b/charts/minecraft/values.schema.json index 4cf41fc3..03e8b128 100644 --- a/charts/minecraft/values.schema.json +++ b/charts/minecraft/values.schema.json @@ -1,6 +1,6 @@ { "$schema": "http://json-schema.org/draft-07/schema", - "required": ["minecraftServer"], + "required": ["minecraftServer", "initContainers", "sidecarContainers"], "properties": { "minecraftServer": { "type": "object", @@ -195,6 +195,24 @@ }, "extraPodSpec": { "type": "object" + }, + "initContainers": { + "items": { + "type": ["object", "string"] + }, + "type": "array" + }, + "sidecarContainers": { + "items": { + "type": ["object", "string"] + }, + "type": "array" + }, + "extraDeploy": { + "items": { + "type": ["object", "string"] + }, + "type": "array" } } } diff --git a/charts/minecraft/values.yaml b/charts/minecraft/values.yaml index afb8a7b6..7671f613 100644 --- a/charts/minecraft/values.yaml +++ b/charts/minecraft/values.yaml @@ -80,24 +80,46 @@ startupProbe: failureThreshold: 30 periodSeconds: 10 +## Array of initContainers to add to include in deployment (supports templating) +## # initContainers: # - name: do-something # image: busybox # command: ['do', 'something'] -# volumesMounts: +# volumeMounts: +# - name: nfs +# mountPath: /mnt/volume +# readOnly: true +# - | +# name: {{ template "minecraft.fullname" . }}-init +# image: busybox +# command: ['do', 'something'] +# volumeMounts: # - name: nfs # mountPath: /mnt/volume # readOnly: true initContainers: [] +## Array of additional sidecards to include in the deployment (supports templating) +## # sidecarContainers: # - name: do-something # image: busybox # command: ['do', 'something'] -# volumesMounts: +# volumeMounts: # - name: nfs # mountPath: /mnt/volume # readOnly: true +# - | +# name: {{ template "minecraft.fullname" . }}-sidecar +# image: busybox +# command: ['do', 'something', 'with', 'rcon'] +# env: +# - name: RCON_PASSWORD +# valueFrom: +# secretKeyRef: +# name: '{{ .Values.minecraftServer.rcon.existingSecret | default (printf "%s-rcon" (include "minecraft.fullname" .)) }}' +# key: "{{ .Values.minecraftServer.rcon.secretKey | default "rcon-password" }}" sidecarContainers: [] # extraVolumes: