Skip to content

Commit

Permalink
Make sure matchLables of Deployment and Cronjob are different
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 5, 2025
1 parent fe88c1a commit fbc0286
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
46 changes: 30 additions & 16 deletions charts/nextcloud/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -446,43 +446,57 @@ volumes:

{{/*
Create match labels for the nextcloud container as well as the cronjob container.
Parameters:
- component: app or cronjob
- 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.pods.matchlabels" -}}
app.kubernetes.io/name: {{ include "nextcloud.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: app
app.kubernetes.io/name: {{ include "nextcloud.name" .rootContext }}
app.kubernetes.io/instance: {{ .rootContext.Release.Name }}
app.kubernetes.io/component: {{ .component }}
{{- end -}}
{{/*
Create match labels for the nextcloud deployment as well as the cronjob.
Parameters:
- component: app or cronjob
- 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.pods.labels" -}}
{{ include "nextcloud.pods.matchlabels" . }}
helm.sh/chart: {{ include "nextcloud.chart" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{ include "nextcloud.pods.matchlabels" ( dict "component" .component "rootContext" .rootContext) }}
helm.sh/chart: {{ include "nextcloud.chart" .rootContext }}
app.kubernetes.io/managed-by: {{ .rootContext.Release.Service }}
{{- end -}}

{{/*
Create metadata for the nextcloud deployment template as well as the cronjob template.
- component: app or cronjob
- 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.deployment.template.metadata" -}}
metadata:
labels:
{{- include "nextcloud.pods.matchlabels" . | nindent 4 }}
{{- if .Values.redis.enabled }}
{{ include "nextcloud.redis.fullname" . }}-client: "true"
{{- include "nextcloud.pods.matchlabels" ( dict "component" .component "rootContext" .rootContext) | nindent 4 }}
{{- if .rootContext.Values.redis.enabled }}
{{ include "nextcloud.redis.fullname" .rootContext }}-client: "true"
{{- end }}
{{- with .Values.podLabels }}
{{- with .rootContext.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 }}
nextcloud-config-hash: {{ print (toJson .rootContext.Values.nextcloud.defaultConfigs) "-" (toJson .rootContext.Values.nextcloud.configs) | sha256sum }}
php-config-hash: {{ toJson .rootContext.Values.nextcloud.phpConfigs | sha256sum }}
{{- if .rootContext.Values.nginx.enabled }}
nginx-config-hash: {{ print .rootContext.Values.nginx.config.default "-" .rootContext.Values.nginx.config.custom | sha256sum }}
{{- end }}
hooks-hash: {{ toYaml .Values.nextcloud.hooks | sha256sum }}
{{- with .Values.podAnnotations }}
hooks-hash: {{ toYaml .rootContext.Values.nextcloud.hooks | sha256sum }}
{{- with .rootContext.Values.podAnnotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end -}}
Expand Down
6 changes: 3 additions & 3 deletions charts/nextcloud/templates/cronjob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ kind: CronJob
metadata:
name: {{ template "nextcloud.fullname" . }}-cron
labels:
{{- include "nextcloud.pods.labels" . | nindent 4 }}
{{- include "nextcloud.pods.labels" ( dict "component" "cronjob" "rootContext" $ ) | nindent 4 }}
spec:
schedule: "*/5 * * * *"
concurrencyPolicy: Forbid
failedJobsHistoryLimit: 5
jobTemplate:
{{- include "nextcloud.deployment.template.metadata" . | nindent 4 }}
{{- include "nextcloud.deployment.template.metadata" ( dict "component" "cronjob" "rootContext" $ ) | nindent 4 }}
spec:
template:
{{- include "nextcloud.deployment.template.metadata" . | nindent 8 }}
{{- include "nextcloud.deployment.template.metadata" ( dict "component" "cronjob" "rootContext" $ ) | nindent 8 }}
spec:
containers:
{{- $containerName := printf "%s-cron" .Chart.Name }}
Expand Down
6 changes: 3 additions & 3 deletions charts/nextcloud/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: Deployment
metadata:
name: {{ template "nextcloud.fullname" . }}
labels:
{{- include "nextcloud.pods.labels" . | nindent 4 }}
{{- include "nextcloud.pods.labels" ( dict "component" "app" "rootContext" $ ) | nindent 4 }}
{{- with .Values.deploymentLabels }}
{{- toYaml . | nindent 4 }}
{{- end }}
Expand All @@ -20,9 +20,9 @@ spec:
{{- toYaml .Values.nextcloud.strategy | nindent 4 }}
selector:
matchLabels:
{{- include "nextcloud.pods.matchlabels" . | nindent 6 }}
{{- include "nextcloud.pods.matchlabels" ( dict "component" "app" "rootContext" $ ) | nindent 6 }}
template:
{{- include "nextcloud.deployment.template.metadata" . | nindent 4 }}
{{- include "nextcloud.deployment.template.metadata" ( dict "component" "app" "rootContext" $ ) | nindent 4 }}
spec:
containers:
{{- $containerName := .Chart.Name }}
Expand Down

0 comments on commit fbc0286

Please sign in to comment.