Skip to content

Commit

Permalink
Extract labels and metainfo blocks of deployment and cronjob to helpers
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kirchner <martin.kirchner@cas.de>
  • Loading branch information
Martin Kirchner committed Mar 4, 2025
1 parent bc048eb commit a874bc4
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 62 deletions.
43 changes: 43 additions & 0 deletions charts/nextcloud/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -398,3 +398,46 @@ Create volume mounts for the nextcloud container as well as the cron sidecar con
subPath: {{ $key }}
{{- end }}
{{- end -}}

{{/*
Create match labels for the nextcloud container as well as the cronjob container.
*/}}
{{- define "nextcloud.pods.matchlabels" -}}
app.kubernetes.io/name: {{ include "nextcloud.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: app
{{- end -}}

{{/*
Create match labels for the nextcloud deployment as well as the cronjob.
*/}}
{{- define "nextcloud.pods.labels" -}}
{{ include "nextcloud.pods.matchlabels" . }}
helm.sh/chart: {{ include "nextcloud.chart" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}

{{/*
Create metadata for the nextcloud deployment template as well as the cronjob template.
*/}}
{{- define "nextcloud.deployment.template.metadata" -}}
metadata:
labels:
{{- include "nextcloud.pods.matchlabels" . | nindent 4 }}
{{- if .Values.redis.enabled }}
{{ include "nextcloud.redis.fullname" . }}-client: "true"
{{- end }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 4 }}
{{- end }}
annotations:
nextcloud-config-hash: {{ print (toJson .Values.nextcloud.defaultConfigs) "-" (toJson .Values.nextcloud.configs) | sha256sum }}
php-config-hash: {{ toJson .Values.nextcloud.phpConfigs | sha256sum }}
{{- if .Values.nginx.enabled }}
nginx-config-hash: {{ print .Values.nginx.config.default "-" .Values.nginx.config.custom | sha256sum }}
{{- end }}
hooks-hash: {{ toYaml .Values.nextcloud.hooks | sha256sum }}
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end -}}
38 changes: 5 additions & 33 deletions charts/nextcloud/templates/cronjob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,16 @@ kind: CronJob
metadata:
name: {{ template "nextcloud.fullname" . }}
labels:
app.kubernetes.io/name: {{ include "nextcloud.name" . }}
helm.sh/chart: {{ include "nextcloud.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/component: app
{{- include "nextcloud.pods.labels" . | nindent 4 }}
spec:
schedule: "*/5 * * * *"
concurrencyPolicy: Forbid
failedJobsHistoryLimit: 5
jobTemplate:
metadata:
labels:
app.kubernetes.io/name: {{ include "nextcloud.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: app
{{- if .Values.redis.enabled }}
{{ template "nextcloud.redis.fullname" . }}-client: "true"
{{- end }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
annotations:
nextcloud-config-hash: {{ print (toJson .Values.nextcloud.defaultConfigs) "-" (toJson .Values.nextcloud.configs) | sha256sum }}
php-config-hash: {{ toJson .Values.nextcloud.phpConfigs | sha256sum }}
{{- if .Values.nginx.enabled }}
nginx-config-hash: {{ print .Values.nginx.config.default "-" .Values.nginx.config.custom | sha256sum }}
{{- end }}
hooks-hash: {{ toYaml .Values.nextcloud.hooks | sha256sum }}
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- include "nextcloud.deployment.template.metadata" . | nindent 4 }}
spec:
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "nextcloud.name" . }}
helm.sh/chart: {{ include "nextcloud.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/component: app
{{- include "nextcloud.deployment.template.metadata" . | nindent 8 }}
spec:
{{- with .Values.image.pullSecrets }}
imagePullSecrets:
Expand Down Expand Up @@ -135,6 +105,8 @@ spec:
{{- with .Values.nextcloud.extraVolumes }}
{{- toYaml . | nindent 12 }}
{{- end }}
# Actually it does not make much sense to define securityContext and podSecurityContext on a pod with only one container
# except for backward compatibility when the cronjob was a sidecar container.
securityContext:
{{- with .Values.securityContext }}
{{- toYaml . | nindent 12 }}
Expand Down
32 changes: 3 additions & 29 deletions charts/nextcloud/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ kind: Deployment
metadata:
name: {{ template "nextcloud.fullname" . }}
labels:
app.kubernetes.io/name: {{ include "nextcloud.name" . }}
helm.sh/chart: {{ include "nextcloud.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/component: app
{{- include "nextcloud.pods.labels" . | nindent 4 }}
{{- with .Values.deploymentLabels }}
{{- toYaml . | nindent 4 }}
{{- end }}
Expand All @@ -24,31 +20,9 @@ spec:
{{- toYaml .Values.nextcloud.strategy | nindent 4 }}
selector:
matchLabels:
app.kubernetes.io/name: {{ include "nextcloud.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: app
{{- include "nextcloud.pods.matchlabels" . | nindent 6 }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "nextcloud.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: app
{{- if .Values.redis.enabled }}
{{ template "nextcloud.redis.fullname" . }}-client: "true"
{{- end }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
annotations:
nextcloud-config-hash: {{ print (toJson .Values.nextcloud.defaultConfigs) "-" (toJson .Values.nextcloud.configs) | sha256sum }}
php-config-hash: {{ toJson .Values.nextcloud.phpConfigs | sha256sum }}
{{- if .Values.nginx.enabled }}
nginx-config-hash: {{ print .Values.nginx.config.default "-" .Values.nginx.config.custom | sha256sum }}
{{- end }}
hooks-hash: {{ toYaml .Values.nextcloud.hooks | sha256sum }}
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- include "nextcloud.deployment.template.metadata" . | nindent 4 }}
spec:
{{- with .Values.image.pullSecrets }}
imagePullSecrets:
Expand Down

0 comments on commit a874bc4

Please sign in to comment.