Skip to content

Commit b31f45c

Browse files
committed
feat: add templating to initContainers and sidecarContainers
1 parent ed3317b commit b31f45c

File tree

5 files changed

+53
-12
lines changed

5 files changed

+53
-12
lines changed

charts/minecraft/templates/_helpers.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this
3939
{{- end }}
4040
{{- end }}
4141

42-
{{- define "extraDeploy.render" -}}
42+
{{- define "tplRender" -}}
4343
{{- $value := typeIs "string" .value | ternary .value (.value | toYaml) }}
4444
{{- if contains "{{" (toJson .value) }}
4545
{{- if .scope }}

charts/minecraft/templates/deployment.yaml

+8-7
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ spec:
6868
{{- end }}
6969
securityContext:
7070
{{- toYaml .Values.podSecurityContext | nindent 8 }}
71-
{{- if .Values.initContainers }}
72-
initContainers:
73-
{{- toYaml .Values.initContainers | nindent 8 }}
74-
{{- end }}
7571
containers:
7672
- name: {{ template "minecraft.fullname" . }}
7773
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
@@ -439,11 +435,12 @@ spec:
439435
securityContext:
440436
{{- toYaml .Values.securityContext | nindent 10 }}
441437
{{- end }}
442-
{{- if .Values.sidecarContainers }}
443-
{{- toYaml .Values.sidecarContainers | nindent 6 }}
438+
{{- range .Values.sidecarContainers }}
439+
- {{ include "tplRender" (dict "value" . "context" $) | nindent 8 | trim }}
444440
{{- end }}
445-
{{- if or (eq .Values.mcbackup.backupMethod "rclone") (eq (include "isResticWithRclone" $) "true") }}
441+
{{- if or .Values.initContainers (eq .Values.mcbackup.backupMethod "rclone") (eq (include "isResticWithRclone" $) "true") }}
446442
initContainers:
443+
{{- if or (eq .Values.mcbackup.backupMethod "rclone") (eq (include "isResticWithRclone" $) "true") }}
447444
- name: init-container
448445
image: busybox
449446
command: ['sh', '-c', 'cp /secret/rclone.conf /config/rclone/']
@@ -452,6 +449,10 @@ spec:
452449
mountPath: /secret
453450
- name: rclone-config
454451
mountPath: /config/rclone
452+
{{- end }}
453+
{{- range .Values.initContainers }}
454+
- {{ include "tplRender" (dict "value" . "context" $) | nindent 10 | trim }}
455+
{{- end }}
455456
{{- end }}
456457
volumes:
457458
- name: tmp
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{{- range .Values.extraDeploy }}
22
---
3-
{{ include "extraDeploy.render" (dict "value" . "context" $) }}
3+
{{ include "tplRender" (dict "value" . "context" $) }}
44
{{- end }}

charts/minecraft/values.schema.json

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "http://json-schema.org/draft-07/schema",
3-
"required": ["minecraftServer"],
3+
"required": ["minecraftServer", "initContainers", "sidecarContainers"],
44
"properties": {
55
"minecraftServer": {
66
"type": "object",
@@ -195,6 +195,24 @@
195195
},
196196
"extraPodSpec": {
197197
"type": "object"
198+
},
199+
"initContainers": {
200+
"items": {
201+
"type": ["object", "string"]
202+
},
203+
"type": "array"
204+
},
205+
"sidecarContainers": {
206+
"items": {
207+
"type": ["object", "string"]
208+
},
209+
"type": "array"
210+
},
211+
"extraDeploy": {
212+
"items": {
213+
"type": ["object", "string"]
214+
},
215+
"type": "array"
198216
}
199217
}
200218
}

charts/minecraft/values.yaml

+24-2
Original file line numberDiff line numberDiff line change
@@ -80,24 +80,46 @@ startupProbe:
8080
failureThreshold: 30
8181
periodSeconds: 10
8282

83+
## Array of initContainers to add to include in deployment (supports templating)
84+
##
8385
# initContainers:
8486
# - name: do-something
8587
# image: busybox
8688
# command: ['do', 'something']
87-
# volumesMounts:
89+
# volumeMounts:
90+
# - name: nfs
91+
# mountPath: /mnt/volume
92+
# readOnly: true
93+
# - |
94+
# name: {{ template "minecraft.fullname" . }}-init
95+
# image: busybox
96+
# command: ['do', 'something']
97+
# volumeMounts:
8898
# - name: nfs
8999
# mountPath: /mnt/volume
90100
# readOnly: true
91101
initContainers: []
92102

103+
## Array of additional sidecards to include in the deployment (supports templating)
104+
##
93105
# sidecarContainers:
94106
# - name: do-something
95107
# image: busybox
96108
# command: ['do', 'something']
97-
# volumesMounts:
109+
# volumeMounts:
98110
# - name: nfs
99111
# mountPath: /mnt/volume
100112
# readOnly: true
113+
# - |
114+
# name: {{ template "minecraft.fullname" . }}-sidecar
115+
# image: busybox
116+
# command: ['do', 'something', 'with', 'rcon']
117+
# env:
118+
# - name: RCON_PASSWORD
119+
# valueFrom:
120+
# secretKeyRef:
121+
# name: '{{ .Values.minecraftServer.rcon.existingSecret | default (printf "%s-rcon" (include "minecraft.fullname" .)) }}'
122+
# key: "{{ .Values.minecraftServer.rcon.secretKey | default "rcon-password" }}"
101123
sidecarContainers: []
102124

103125
# extraVolumes:

0 commit comments

Comments
 (0)