diff --git a/charts/posthog/Chart.yaml b/charts/posthog/Chart.yaml index 373b7eff..7b63cb55 100644 --- a/charts/posthog/Chart.yaml +++ b/charts/posthog/Chart.yaml @@ -11,7 +11,7 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. -version: 30.32.0 +version: 30.33.0 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. diff --git a/charts/posthog/templates/_snippet-plugins-deployment.tpl b/charts/posthog/templates/_snippet-plugins-deployment.tpl index 27652612..d9544da0 100644 --- a/charts/posthog/templates/_snippet-plugins-deployment.tpl +++ b/charts/posthog/templates/_snippet-plugins-deployment.tpl @@ -44,6 +44,7 @@ spec: {{- end }} spec: serviceAccountName: {{ template "posthog.serviceAccountName" .root }} + {{- include "_snippet-topologySpreadConstraints" .root | nindent 6 }} {{- if .params.affinity }} affinity: diff --git a/charts/posthog/templates/_snippet-topologySpreadConstraints.tpl b/charts/posthog/templates/_snippet-topologySpreadConstraints.tpl new file mode 100644 index 00000000..6711f8d8 --- /dev/null +++ b/charts/posthog/templates/_snippet-topologySpreadConstraints.tpl @@ -0,0 +1,35 @@ +{{/* Common topologySpreadConstraints definition */}} +{{/* + matchLabelsKeys are the set of unique pod labels for which the constraints are applied + any missing labels are ignored. + + pod-template-hash is added automatically by deployments and is unique for each rollout. + Including this means we don't get out of sync on rollouts as it ignores the locations + of existing pods that will be terminated after the rollout is finished. + */}} +{{- define "_snippet-selectors" -}} +labelSelector: + matchLabels: {} +matchLabelKeys: +- pod-template-hash +- app +- release +- role +- app.kubernetes.io/name +- app.kubernetes.io/instance +{{- end }} +{{- define "_snippet-topologySpreadConstraints" }} +{{- if (.Values.includeDefaultTopologySpreadConstraints | default false) }} +topologySpreadConstraints: +- maxSkew: 1 + topologyKey: topology.kubernetes.io/zone + whenUnsatisfiable: ScheduleAnyway + nodeTaintsPolicy: Honor + {{- include "_snippet-selectors" . | nindent 2 }} +- maxSkew: 3 + topologyKey: kubernetes.io/hostname + whenUnsatisfiable: ScheduleAnyway + nodeTaintsPolicy: Honor + {{- include "_snippet-selectors" . | nindent 2 }} +{{- end }} +{{- end }} diff --git a/charts/posthog/templates/decide-deployment.yaml b/charts/posthog/templates/decide-deployment.yaml index e7eb7f9f..09b10b4e 100644 --- a/charts/posthog/templates/decide-deployment.yaml +++ b/charts/posthog/templates/decide-deployment.yaml @@ -41,6 +41,7 @@ spec: spec: terminationGracePeriodSeconds: {{ include "snippet.web-deployments.terminationGracePeriodSeconds" . }} serviceAccountName: {{ template "posthog.serviceAccountName" . }} + {{- include "_snippet-topologySpreadConstraints" . | nindent 6 }} {{- if .Values.web.affinity }} affinity: diff --git a/charts/posthog/templates/events-deployment.yaml b/charts/posthog/templates/events-deployment.yaml index eba51d62..697a8fcd 100644 --- a/charts/posthog/templates/events-deployment.yaml +++ b/charts/posthog/templates/events-deployment.yaml @@ -41,6 +41,7 @@ spec: spec: terminationGracePeriodSeconds: {{ include "snippet.web-deployments.terminationGracePeriodSeconds" . }} serviceAccountName: {{ template "posthog.serviceAccountName" . }} + {{- include "_snippet-topologySpreadConstraints" . | nindent 6 }} {{- if .Values.web.affinity }} affinity: diff --git a/charts/posthog/templates/pgbouncer-deployment.yaml b/charts/posthog/templates/pgbouncer-deployment.yaml index c59abaa1..ce2579de 100644 --- a/charts/posthog/templates/pgbouncer-deployment.yaml +++ b/charts/posthog/templates/pgbouncer-deployment.yaml @@ -42,6 +42,7 @@ spec: terminationGracePeriodSeconds: 65 serviceAccountName: {{ template "posthog.serviceAccountName" . }} + {{- include "_snippet-topologySpreadConstraints" . | nindent 6 }} {{- if .Values.pgbouncer.affinity }} affinity: {{ toYaml .Values.pgbouncer.affinity | nindent 8 }} diff --git a/charts/posthog/templates/pgbouncer-read-deployment.yaml b/charts/posthog/templates/pgbouncer-read-deployment.yaml index 6260b688..e27951b7 100644 --- a/charts/posthog/templates/pgbouncer-read-deployment.yaml +++ b/charts/posthog/templates/pgbouncer-read-deployment.yaml @@ -42,6 +42,7 @@ spec: terminationGracePeriodSeconds: 65 serviceAccountName: {{ template "posthog.serviceAccountName" . }} + {{- include "_snippet-topologySpreadConstraints" . | nindent 6 }} {{- if .Values.pgbouncerRead.affinity }} affinity: {{ toYaml .Values.pgbouncerRead.affinity | nindent 8 }} diff --git a/charts/posthog/templates/recordings-deployment.yaml b/charts/posthog/templates/recordings-deployment.yaml index 375e7b0f..1f956967 100644 --- a/charts/posthog/templates/recordings-deployment.yaml +++ b/charts/posthog/templates/recordings-deployment.yaml @@ -41,6 +41,7 @@ spec: spec: terminationGracePeriodSeconds: {{ include "snippet.web-deployments.terminationGracePeriodSeconds" . }} serviceAccountName: {{ template "posthog.serviceAccountName" . }} + {{- include "_snippet-topologySpreadConstraints" . | nindent 6 }} {{- if .Values.web.affinity }} affinity: diff --git a/charts/posthog/templates/temporal-py-worker-deployment.yaml b/charts/posthog/templates/temporal-py-worker-deployment.yaml index c3583575..30a9253d 100644 --- a/charts/posthog/templates/temporal-py-worker-deployment.yaml +++ b/charts/posthog/templates/temporal-py-worker-deployment.yaml @@ -35,6 +35,7 @@ spec: spec: terminationGracePeriodSeconds: {{ .Values.temporalPyWorker.terminationGracePeriodSeconds }} serviceAccountName: {{ template "posthog.serviceAccountName" . }} + {{- include "_snippet-topologySpreadConstraints" . | nindent 6 }} {{- if .Values.temporalPyWorker.affinity }} affinity: diff --git a/charts/posthog/templates/web-deployment.yaml b/charts/posthog/templates/web-deployment.yaml index ba1306e1..74939d5d 100644 --- a/charts/posthog/templates/web-deployment.yaml +++ b/charts/posthog/templates/web-deployment.yaml @@ -41,6 +41,7 @@ spec: spec: terminationGracePeriodSeconds: {{ include "snippet.web-deployments.terminationGracePeriodSeconds" . }} serviceAccountName: {{ template "posthog.serviceAccountName" . }} + {{- include "_snippet-topologySpreadConstraints" . | nindent 6 }} {{- if .Values.web.affinity }} affinity: diff --git a/charts/posthog/templates/worker-deployment.yaml b/charts/posthog/templates/worker-deployment.yaml index a5669ad8..13751718 100644 --- a/charts/posthog/templates/worker-deployment.yaml +++ b/charts/posthog/templates/worker-deployment.yaml @@ -40,6 +40,7 @@ spec: {{- end }} spec: serviceAccountName: {{ template "posthog.serviceAccountName" . }} + {{- include "_snippet-topologySpreadConstraints" . | nindent 6 }} {{- if .Values.worker.affinity }} affinity: diff --git a/charts/posthog/tests/_topologySpreadConstraints.yaml b/charts/posthog/tests/_topologySpreadConstraints.yaml new file mode 100644 index 00000000..685602a3 --- /dev/null +++ b/charts/posthog/tests/_topologySpreadConstraints.yaml @@ -0,0 +1,49 @@ +suite: _topologySpreadConstraints +templates: + - templates/plugins-deployment.yaml + - templates/web-deployment.yaml + - templates/worker-deployment.yaml + # NOTE: we need to include this as it is required by the other templates + - templates/secrets.yaml +tests: + - it: spec.template.spec.topologySpreadConstraints should be empty by default + templates: + - templates/plugins-deployment.yaml + - templates/web-deployment.yaml + - templates/worker-deployment.yaml + set: + cloud: local + asserts: + - hasDocuments: + count: 1 + - isEmpty: + path: spec.template.spec.topologySpreadConstraints + - it: spec.template.spec.topologySpreadConstraints should exist if includeDefaultTopologySpreadConstraints is set + templates: + - templates/plugins-deployment.yaml + - templates/web-deployment.yaml + - templates/worker-deployment.yaml + set: + cloud: local + includeDefaultTopologySpreadConstraints: true + asserts: + - hasDocuments: + count: 1 + - equal: + path: spec.template.spec.topologySpreadConstraints[0].topologyKey + value: topology.kubernetes.io/zone + - equal: + path: spec.template.spec.topologySpreadConstraints[0].maxSkew + value: 1 + - equal: + path: spec.template.spec.topologySpreadConstraints[0].whenUnsatisfiable + value: ScheduleAnyway + - equal: + path: spec.template.spec.topologySpreadConstraints[1].topologyKey + value: kubernetes.io/hostname + - equal: + path: spec.template.spec.topologySpreadConstraints[1].maxSkew + value: 3 + - equal: + path: spec.template.spec.topologySpreadConstraints[1].whenUnsatisfiable + value: ScheduleAnyway diff --git a/charts/posthog/values.yaml b/charts/posthog/values.yaml index 83640446..0293a1a8 100644 --- a/charts/posthog/values.yaml +++ b/charts/posthog/values.yaml @@ -3396,3 +3396,7 @@ busybox: # -- Kubernetes cluster domain name clusterDomain: cluster.local + +# Whether to set a topologySpreadConstraint on all deployments +# to balance pods between availability zones and nodes +includeDefaultTopologySpreadConstraints: false