From d5fa9cec06ecb5d45c68b3da8739a199c714357e Mon Sep 17 00:00:00 2001 From: Martin Kirchner Date: Mon, 17 Mar 2025 20:12:04 +0100 Subject: [PATCH] Extract a template for the nextcloud container (app/cronjob) Signed-off-by: Martin Kirchner --- charts/nextcloud/Chart.yaml | 2 +- charts/nextcloud/templates/_helpers.tpl | 45 ++++++++++++++++ charts/nextcloud/templates/deployment.yaml | 62 ++-------------------- 3 files changed, 50 insertions(+), 59 deletions(-) diff --git a/charts/nextcloud/Chart.yaml b/charts/nextcloud/Chart.yaml index 378fb7b5..af1c4ba3 100644 --- a/charts/nextcloud/Chart.yaml +++ b/charts/nextcloud/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v2 name: nextcloud -version: 6.6.9 +version: 6.6.10 # renovate: image=docker.io/library/nextcloud appVersion: 30.0.6 description: A file sharing server that puts the control and security of your own data back into your hands. diff --git a/charts/nextcloud/templates/_helpers.tpl b/charts/nextcloud/templates/_helpers.tpl index 20f82799..4af4e9a2 100644 --- a/charts/nextcloud/templates/_helpers.tpl +++ b/charts/nextcloud/templates/_helpers.tpl @@ -431,4 +431,49 @@ app.kubernetes.io/managed-by: {{ .rootContext.Release.Service }} {{- with .rootContext.Chart.AppVersion }} app.kubernetes.io/version: {{ quote . }} {{- end }} +{{- end -}} + +{{/* +Create nextcloud container definition for deployment and cronjob. +Pass these parameters in the dict: +- containerName: name of the container +- context: Pointer to the context in the values.yaml where "lifecycle, resources" can be found +- securityContext: Pointer to the securityContext in the values.yaml +- rootContext: $ (Inside a template the scope changes, i.e. you cannot access variables of the parent context or its parents. + Unfortunately this is also the case for the root context, this means .Values, .Release, .Chart cannot be accessed. + 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.) +*/}} +{{- define "nextcloud.container" -}} +- name: {{ .containerName }} + image: {{ include "nextcloud.image" .rootContext }} + imagePullPolicy: {{ .rootContext.Values.image.pullPolicy }} + {{- if .context.command }} + command: + {{- toYaml .context.command | nindent 4 }} + {{- end }} + {{- with .context.lifecycle }} + lifecycle: + {{- with .postStartCommand }} + postStart: + exec: + command: + {{- toYaml . | nindent 10 }} + {{- end }} + {{- with .preStopCommand }} + preStop: + exec: + command: + {{- toYaml . | nindent 10 }} + {{- end }} + {{- end }} + env: + {{- include "nextcloud.env" .rootContext | nindent 4 }} + resources: + {{- toYaml .context.resources | nindent 4 }} + {{- with .securityContext }} + securityContext: + {{- toYaml . | nindent 4 }} + {{- end }} + volumeMounts: + {{- include "nextcloud.volumeMounts" .rootContext | trim | nindent 4 }} {{- end -}} \ No newline at end of file diff --git a/charts/nextcloud/templates/deployment.yaml b/charts/nextcloud/templates/deployment.yaml index 1948e47d..487c4d04 100644 --- a/charts/nextcloud/templates/deployment.yaml +++ b/charts/nextcloud/templates/deployment.yaml @@ -49,34 +49,8 @@ spec: {{- end}} {{- end }} containers: - - name: {{ .Chart.Name }} - image: {{ include "nextcloud.image" . }} - imagePullPolicy: {{ .Values.image.pullPolicy }} - {{- with .Values.lifecycle }} - lifecycle: - {{- with .postStartCommand }} - postStart: - exec: - command: - {{- toYaml . | nindent 18 }} - {{- end }} - {{- with .preStopCommand }} - preStop: - exec: - command: - {{- toYaml . | nindent 18 }} - {{- end }} - {{- end }} - env: - {{- include "nextcloud.env" . | nindent 12 }} - resources: - {{- toYaml .Values.resources | nindent 12 }} - {{- with .Values.nextcloud.securityContext }} - securityContext: - {{- toYaml . | nindent 12 }} - {{- end }} - volumeMounts: - {{- include "nextcloud.volumeMounts" . | trim | nindent 12 }} + {{- $containerName := .Chart.Name }} + {{- include "nextcloud.container" ( dict "containerName" $containerName "securityContext" .Values.nextcloud.securityContext "rootContext" $ "context" .Values ) | nindent 8 }} {{- range $hook, $shell := .Values.nextcloud.hooks }} {{- if $shell }} - name: nextcloud-hooks @@ -241,36 +215,8 @@ spec: {{- end }} {{- end }}{{/* end-if nginx.enabled */}} {{- if .Values.cronjob.enabled }} - - name: {{ .Chart.Name }}-cron - image: {{ include "nextcloud.image" . }} - imagePullPolicy: {{ .Values.image.pullPolicy }} - command: - {{- toYaml .Values.cronjob.command | nindent 12 }} - {{- with .Values.cronjob.lifecycle }} - lifecycle: - {{- with .postStartCommand }} - postStart: - exec: - command: - {{- toYaml . | nindent 18 }} - {{- end }} - {{- with .preStopCommand }} - preStop: - exec: - command: - {{- toYaml . | nindent 18 }} - {{- end }} - {{- end }} - env: - {{- include "nextcloud.env" . | nindent 12 }} - resources: - {{- toYaml .Values.cronjob.resources | nindent 12 }} - {{- with .Values.cronjob.securityContext }} - securityContext: - {{- toYaml . | nindent 12 }} - {{- end }} - volumeMounts: - {{- include "nextcloud.volumeMounts" . | trim | nindent 12 }} + {{- $containerName := printf "%s-cron" .Chart.Name }} + {{- include "nextcloud.container" ( dict "containerName" $containerName "securityContext" .Values.cronjob.securityContext "rootContext" $ "context" .Values.cronjob ) | nindent 8 }} {{- end }}{{/* end-if cronjob.enabled */}} {{- with .Values.nextcloud.extraSidecarContainers }} {{- toYaml . | nindent 8 }}