Skip to content

Commit 998259a

Browse files
author
Martin Kirchner
committed
Extract a template for the nextcloud container (app/cronjob)
Signed-off-by: Martin Kirchner <[email protected]>
1 parent 00d8a86 commit 998259a

File tree

3 files changed

+50
-59
lines changed

3 files changed

+50
-59
lines changed

charts/nextcloud/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
apiVersion: v2
22
name: nextcloud
3-
version: 6.6.9
3+
version: 6.6.10
44
# renovate: image=docker.io/library/nextcloud
55
appVersion: 30.0.6
66
description: A file sharing server that puts the control and security of your own data back into your hands.

charts/nextcloud/templates/_helpers.tpl

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,4 +431,49 @@ app.kubernetes.io/managed-by: {{ .rootContext.Release.Service }}
431431
{{- with .rootContext.Chart.AppVersion }}
432432
app.kubernetes.io/version: {{ quote . }}
433433
{{- end }}
434+
{{- end -}}
435+
436+
{{/*
437+
Create nextcloud container definition for deployment and cronjob.
438+
Pass these parameters in the dict:
439+
- containerName: name of the container
440+
- context: Pointer to the context in the values.yaml where "lifecycle, securityContext" can be found
441+
- resources: Pointer to the context in the values.yaml where "resources" can be found
442+
- rootContext: $ (Inside a template the scope changes, i.e. you cannot access variables of the parent context or its parents.
443+
Unfortunately this is also the case for the root context, this means .Values, .Release, .Chart cannot be accessed.
444+
However the other templates need values from the objects. That's why the caller has to pass on reference to the root context which this template in turn passes on.)
445+
*/}}
446+
{{- define "nextcloud.container" -}}
447+
- name: {{ .containerName }}
448+
image: {{ include "nextcloud.image" .rootContext }}
449+
imagePullPolicy: {{ .rootContext.Values.image.pullPolicy }}
450+
{{- if .context.command }}
451+
command:
452+
{{- toYaml .context.command | nindent 4 }}
453+
{{- end }}
454+
{{- with .context.lifecycle }}
455+
lifecycle:
456+
{{- with .postStartCommand }}
457+
postStart:
458+
exec:
459+
command:
460+
{{- toYaml . | nindent 10 }}
461+
{{- end }}
462+
{{- with .preStopCommand }}
463+
preStop:
464+
exec:
465+
command:
466+
{{- toYaml . | nindent 10 }}
467+
{{- end }}
468+
{{- end }}
469+
env:
470+
{{- include "nextcloud.env" .rootContext | nindent 4 }}
471+
resources:
472+
{{- toYaml .context.resources | nindent 4 }}
473+
{{- with .securityContext }}
474+
securityContext:
475+
{{- toYaml . | nindent 4 }}
476+
{{- end }}
477+
volumeMounts:
478+
{{- include "nextcloud.volumeMounts" .rootContext | trim | nindent 4 }}
434479
{{- end -}}

charts/nextcloud/templates/deployment.yaml

Lines changed: 4 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -49,34 +49,8 @@ spec:
4949
{{- end}}
5050
{{- end }}
5151
containers:
52-
- name: {{ .Chart.Name }}
53-
image: {{ include "nextcloud.image" . }}
54-
imagePullPolicy: {{ .Values.image.pullPolicy }}
55-
{{- with .Values.lifecycle }}
56-
lifecycle:
57-
{{- with .postStartCommand }}
58-
postStart:
59-
exec:
60-
command:
61-
{{- toYaml . | nindent 18 }}
62-
{{- end }}
63-
{{- with .preStopCommand }}
64-
preStop:
65-
exec:
66-
command:
67-
{{- toYaml . | nindent 18 }}
68-
{{- end }}
69-
{{- end }}
70-
env:
71-
{{- include "nextcloud.env" . | nindent 12 }}
72-
resources:
73-
{{- toYaml .Values.resources | nindent 12 }}
74-
{{- with .Values.nextcloud.securityContext }}
75-
securityContext:
76-
{{- toYaml . | nindent 12 }}
77-
{{- end }}
78-
volumeMounts:
79-
{{- include "nextcloud.volumeMounts" . | trim | nindent 12 }}
52+
{{- $containerName := .Chart.Name }}
53+
{{- include "nextcloud.container" ( dict "containerName" $containerName "securityContext" .Values.nextcloud.securityContext "rootContext" $ "context" .Values ) | nindent 8 }}
8054
{{- range $hook, $shell := .Values.nextcloud.hooks }}
8155
{{- if $shell }}
8256
- name: nextcloud-hooks
@@ -241,36 +215,8 @@ spec:
241215
{{- end }}
242216
{{- end }}{{/* end-if nginx.enabled */}}
243217
{{- if .Values.cronjob.enabled }}
244-
- name: {{ .Chart.Name }}-cron
245-
image: {{ include "nextcloud.image" . }}
246-
imagePullPolicy: {{ .Values.image.pullPolicy }}
247-
command:
248-
{{- toYaml .Values.cronjob.command | nindent 12 }}
249-
{{- with .Values.cronjob.lifecycle }}
250-
lifecycle:
251-
{{- with .postStartCommand }}
252-
postStart:
253-
exec:
254-
command:
255-
{{- toYaml . | nindent 18 }}
256-
{{- end }}
257-
{{- with .preStopCommand }}
258-
preStop:
259-
exec:
260-
command:
261-
{{- toYaml . | nindent 18 }}
262-
{{- end }}
263-
{{- end }}
264-
env:
265-
{{- include "nextcloud.env" . | nindent 12 }}
266-
resources:
267-
{{- toYaml .Values.cronjob.resources | nindent 12 }}
268-
{{- with .Values.cronjob.securityContext }}
269-
securityContext:
270-
{{- toYaml . | nindent 12 }}
271-
{{- end }}
272-
volumeMounts:
273-
{{- include "nextcloud.volumeMounts" . | trim | nindent 12 }}
218+
{{- $containerName := printf "%s-cron" .Chart.Name }}
219+
{{- include "nextcloud.container" ( dict "containerName" $containerName "securityContext" .Values.cronjob.securityContext "rootContext" $ "context" .Values.cronjob ) | nindent 8 }}
274220
{{- end }}{{/* end-if cronjob.enabled */}}
275221
{{- with .Values.nextcloud.extraSidecarContainers }}
276222
{{- toYaml . | nindent 8 }}

0 commit comments

Comments
 (0)