From fd210e257b6ca57ea33ef035b800d07c76144d52 Mon Sep 17 00:00:00 2001 From: Ben Banfield-Zanin Date: Mon, 17 Nov 2025 15:34:23 +0000 Subject: [PATCH] Have a common helper for constructing StatefulSet.spec too --- .../templates/element-admin/deployment.yaml | 2 +- .../templates/element-web/deployment.yaml | 2 +- .../templates/ess-library/_deployments.tpl | 31 -------------- .../templates/ess-library/_workloads.tpl | 42 +++++++++++++++++++ .../templates/haproxy/deployment.yaml | 2 +- .../deployment.yaml | 2 +- .../matrix-rtc/authorisation_deployment.yaml | 2 +- .../templates/matrix-rtc/sfu_deployment.yaml | 2 +- .../templates/postgres/statefulset.yaml | 8 +--- .../templates/synapse/redis_deployment.yaml | 2 +- .../synapse/synapse_statefulset.yaml | 10 +---- newsfragments/872.changed.md | 1 + 12 files changed, 52 insertions(+), 54 deletions(-) delete mode 100644 charts/matrix-stack/templates/ess-library/_deployments.tpl create mode 100644 charts/matrix-stack/templates/ess-library/_workloads.tpl create mode 100644 newsfragments/872.changed.md diff --git a/charts/matrix-stack/templates/element-admin/deployment.yaml b/charts/matrix-stack/templates/element-admin/deployment.yaml index 621f9105..c5407407 100644 --- a/charts/matrix-stack/templates/element-admin/deployment.yaml +++ b/charts/matrix-stack/templates/element-admin/deployment.yaml @@ -18,7 +18,7 @@ metadata: name: {{ $.Release.Name }}-element-admin namespace: {{ $.Release.Namespace }} spec: - {{ include "element-io.ess-library.deployments.commonSpec" (dict "root" $ "context" (dict "replicas" .replicas "nameSuffix" "element-admin")) | nindent 2 }} + {{ include "element-io.ess-library.workloads.commonSpec" (dict "root" $ "context" (dict "nameSuffix" "element-admin" "kind" "Deployment" "componentValues" .)) | nindent 2 }} template: metadata: labels: diff --git a/charts/matrix-stack/templates/element-web/deployment.yaml b/charts/matrix-stack/templates/element-web/deployment.yaml index 6a015f75..a4315e08 100644 --- a/charts/matrix-stack/templates/element-web/deployment.yaml +++ b/charts/matrix-stack/templates/element-web/deployment.yaml @@ -20,7 +20,7 @@ metadata: name: {{ $.Release.Name }}-element-web namespace: {{ $.Release.Namespace }} spec: - {{ include "element-io.ess-library.deployments.commonSpec" (dict "root" $ "context" (dict "replicas" .replicas "nameSuffix" "element-web")) | nindent 2 }} + {{ include "element-io.ess-library.workloads.commonSpec" (dict "root" $ "context" (dict "nameSuffix" "element-web" "kind" "Deployment" "componentValues" .)) | nindent 2 }} template: metadata: labels: diff --git a/charts/matrix-stack/templates/ess-library/_deployments.tpl b/charts/matrix-stack/templates/ess-library/_deployments.tpl deleted file mode 100644 index c4908440..00000000 --- a/charts/matrix-stack/templates/ess-library/_deployments.tpl +++ /dev/null @@ -1,31 +0,0 @@ -{{- /* -Copyright 2025 New Vector Ltd -Copyright 2025 Element Creations Ltd - -SPDX-License-Identifier: AGPL-3.0-only -*/ -}} - - -{{- define "element-io.ess-library.deployments.commonSpec" -}} -{{- $root := .root -}} -{{- with required "element-io.ess-library.deployments.commonSpec missing context" .context -}} -{{- if hasKey . "replicas" }} -replicas: {{ required (printf "element-io.ess-library.deployments.commonSpec with nameSuffix %s is missing a replicas value" .nameSuffix) .replicas }} -strategy: - type: RollingUpdate - rollingUpdate: - maxUnavailable: {{ min (max 0 (sub .replicas 1)) 1 }} - maxSurge: 2 -{{- else }} -replicas: 1 -strategy: - type: RollingUpdate - rollingUpdate: - maxUnavailable: 0 - maxSurge: 2 -{{- end }} -selector: - matchLabels: - app.kubernetes.io/instance: {{ $root.Release.Name }}-{{ .nameSuffix }} -{{- end }} -{{- end }} diff --git a/charts/matrix-stack/templates/ess-library/_workloads.tpl b/charts/matrix-stack/templates/ess-library/_workloads.tpl new file mode 100644 index 00000000..65a287f7 --- /dev/null +++ b/charts/matrix-stack/templates/ess-library/_workloads.tpl @@ -0,0 +1,42 @@ +{{- /* +Copyright 2025 New Vector Ltd +Copyright 2025 Element Creations Ltd + +SPDX-License-Identifier: AGPL-3.0-only +*/ -}} + + +{{- define "element-io.ess-library.workloads.commonSpec" -}} +{{- $root := .root -}} +{{- with required "element-io.ess-library.workloads.commonSpec missing context" .context -}} +{{- $nameSuffix := required "element-io.ess-library.workloads.commonSpec missing context.nameSuffix" .nameSuffix -}} +{{- $serviceNameSuffix := .serviceNameSuffix | default $nameSuffix -}} +{{- $kind := required "element-io.ess-library.workloads.commonSpec missing context.kind" .kind -}} +{{- with required "element-io.ess-library.workloads.commonSpec missing context.componentValues" .componentValues -}} +replicas: {{ .replicas | default 1 }} +selector: + matchLabels: + app.kubernetes.io/instance: {{ $root.Release.Name }}-{{ $nameSuffix }} +{{- if eq "Deployment" $kind }} +strategy: + type: RollingUpdate + rollingUpdate: +{{- if hasKey . "replicas" }} + maxUnavailable: {{ min (max 0 (sub .replicas 1)) 1 }} +{{- else }} + maxUnavailable: 0 +{{- end }} + maxSurge: 2 +{{- else }} +serviceName: {{ $root.Release.Name }}-{{ $serviceNameSuffix }} +updateStrategy: + type: RollingUpdate +{{- if ne "postgres" $nameSuffix }} +{{- /* Until we have a migration path in https://github.com/element-hq/ess-helm/pull/870 */}} +# Without this CrashLoopBackoffs due to config failures block pod recreation +podManagementPolicy: Parallel +{{- end }} +{{- end }} +{{- end }} +{{- end }} +{{- end }} diff --git a/charts/matrix-stack/templates/haproxy/deployment.yaml b/charts/matrix-stack/templates/haproxy/deployment.yaml index 9bda2859..8105f235 100644 --- a/charts/matrix-stack/templates/haproxy/deployment.yaml +++ b/charts/matrix-stack/templates/haproxy/deployment.yaml @@ -27,7 +27,7 @@ metadata: name: {{ $.Release.Name }}-haproxy namespace: {{ $.Release.Namespace }} spec: - {{ include "element-io.ess-library.deployments.commonSpec" (dict "root" $ "context" (dict "replicas" .replicas "nameSuffix" "haproxy")) | nindent 2 }} + {{ include "element-io.ess-library.workloads.commonSpec" (dict "root" $ "context" (dict "nameSuffix" "haproxy" "kind" "Deployment" "componentValues" .)) | nindent 2 }} template: metadata: labels: diff --git a/charts/matrix-stack/templates/matrix-authentication-service/deployment.yaml b/charts/matrix-stack/templates/matrix-authentication-service/deployment.yaml index 9a0ac545..b157cfb1 100644 --- a/charts/matrix-stack/templates/matrix-authentication-service/deployment.yaml +++ b/charts/matrix-stack/templates/matrix-authentication-service/deployment.yaml @@ -26,7 +26,7 @@ metadata: name: {{ $.Release.Name }}-matrix-authentication-service namespace: {{ $.Release.Namespace }} spec: - {{ include "element-io.ess-library.deployments.commonSpec" (dict "root" $ "context" (dict "replicas" .replicas "nameSuffix" "matrix-authentication-service")) | nindent 2 }} + {{ include "element-io.ess-library.workloads.commonSpec" (dict "root" $ "context" (dict "nameSuffix" "matrix-authentication-service" "kind" "Deployment" "componentValues" .)) | nindent 2 }} template: metadata: labels: diff --git a/charts/matrix-stack/templates/matrix-rtc/authorisation_deployment.yaml b/charts/matrix-stack/templates/matrix-rtc/authorisation_deployment.yaml index 0b62b9a0..8b011cc2 100644 --- a/charts/matrix-stack/templates/matrix-rtc/authorisation_deployment.yaml +++ b/charts/matrix-stack/templates/matrix-rtc/authorisation_deployment.yaml @@ -20,7 +20,7 @@ metadata: name: {{ $.Release.Name }}-matrix-rtc-authorisation-service namespace: {{ $.Release.Namespace }} spec: - {{ include "element-io.ess-library.deployments.commonSpec" (dict "root" $ "context" (dict "replicas" .replicas "nameSuffix" "matrix-rtc-authorisation-service")) | nindent 2 }} + {{ include "element-io.ess-library.workloads.commonSpec" (dict "root" $ "context" (dict "nameSuffix" "matrix-rtc-authorisation-service" "kind" "Deployment" "componentValues" .)) | nindent 2 }} template: metadata: labels: diff --git a/charts/matrix-stack/templates/matrix-rtc/sfu_deployment.yaml b/charts/matrix-stack/templates/matrix-rtc/sfu_deployment.yaml index 6537ebb3..b4b48aad 100644 --- a/charts/matrix-stack/templates/matrix-rtc/sfu_deployment.yaml +++ b/charts/matrix-stack/templates/matrix-rtc/sfu_deployment.yaml @@ -23,7 +23,7 @@ metadata: name: {{ $.Release.Name }}-matrix-rtc-sfu namespace: {{ $.Release.Namespace }} spec: - {{ include "element-io.ess-library.deployments.commonSpec" (dict "root" $ "context" (dict "nameSuffix" "matrix-rtc-sfu")) | nindent 2 }} + {{ include "element-io.ess-library.workloads.commonSpec" (dict "root" $ "context" (dict "nameSuffix" "matrix-rtc-sfu" "kind" "Deployment" "componentValues" .)) | nindent 2 }} template: metadata: labels: diff --git a/charts/matrix-stack/templates/postgres/statefulset.yaml b/charts/matrix-stack/templates/postgres/statefulset.yaml index c4175d94..c291fe5a 100644 --- a/charts/matrix-stack/templates/postgres/statefulset.yaml +++ b/charts/matrix-stack/templates/postgres/statefulset.yaml @@ -20,13 +20,7 @@ metadata: {{- toYaml . | nindent 4 }} {{- end }} spec: - serviceName: {{ $.Release.Name }}-postgres - replicas: 1 - selector: - matchLabels: - app.kubernetes.io/instance: {{ $.Release.Name }}-postgres - updateStrategy: - type: RollingUpdate + {{ include "element-io.ess-library.workloads.commonSpec" (dict "root" $ "context" (dict "nameSuffix" "postgres" "kind" "StatefulSet" "componentValues" .)) | nindent 2 }} template: metadata: labels: diff --git a/charts/matrix-stack/templates/synapse/redis_deployment.yaml b/charts/matrix-stack/templates/synapse/redis_deployment.yaml index 953ec1de..da92361f 100644 --- a/charts/matrix-stack/templates/synapse/redis_deployment.yaml +++ b/charts/matrix-stack/templates/synapse/redis_deployment.yaml @@ -22,7 +22,7 @@ metadata: name: {{ $.Release.Name }}-synapse-redis namespace: {{ $.Release.Namespace }} spec: - {{ include "element-io.ess-library.deployments.commonSpec" (dict "root" $ "context" (dict "nameSuffix" "synapse-redis")) | nindent 2 }} + {{ include "element-io.ess-library.workloads.commonSpec" (dict "root" $ "context" (dict "nameSuffix" "synapse-redis" "kind" "Deployment" "componentValues" .)) | nindent 2 }} template: metadata: labels: diff --git a/charts/matrix-stack/templates/synapse/synapse_statefulset.yaml b/charts/matrix-stack/templates/synapse/synapse_statefulset.yaml index 02af3859..6e0ada9f 100644 --- a/charts/matrix-stack/templates/synapse/synapse_statefulset.yaml +++ b/charts/matrix-stack/templates/synapse/synapse_statefulset.yaml @@ -37,15 +37,7 @@ metadata: name: {{ $.Release.Name }}-synapse-{{ $workerTypeName }} namespace: {{ $.Release.Namespace }} spec: - serviceName: {{ $.Release.Name }}-synapse-{{ $workerTypeName }} - replicas: {{ .replicas | default 1 }} - selector: - matchLabels: - app.kubernetes.io/instance: {{ $.Release.Name }}-synapse-{{ $processType }} - updateStrategy: - type: RollingUpdate - # Without this CrashLoopBackoffs due to config failures block pod recreation - podManagementPolicy: Parallel + {{ include "element-io.ess-library.workloads.commonSpec" (dict "root" $ "context" (dict "nameSuffix" (printf "synapse-%s" $processType) "serviceNameSuffix" (printf "synapse-%s" $workerTypeName) "kind" "StatefulSet" "componentValues" .)) | nindent 2 }} {{- include "element-io.synapse.pod-template" (dict "root" $ "context" .) | nindent 2 }} --- {{- end }} diff --git a/newsfragments/872.changed.md b/newsfragments/872.changed.md new file mode 100644 index 00000000..761c1b2a --- /dev/null +++ b/newsfragments/872.changed.md @@ -0,0 +1 @@ +Unify management of `StatefulSet.spec` along with `Deployment.spec`.