Have a common helper for constructing StatefulSet.spec too

This commit is contained in:
Ben Banfield-Zanin committed 2025-11-17 15:48:29 +00:00
1 parent 8a1640ca8c
commit fd210e257b
12 files changed
+52 -54

No files matched your search

@@ -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:
@@ -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:
@@ -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 }}
@@ -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 }}
@@ -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:
@@ -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:
@@ -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:
@@ -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:
@@ -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:
@@ -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:
@@ -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 }}
+1
View File
@@ -0,0 +1 @@
Unify management of `StatefulSet.spec` along with `Deployment.spec`.