Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add topology spread constraint snippet to all deployments #777

Merged
merged 4 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion charts/posthog/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions charts/posthog/templates/_snippet-plugins-deployment.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ spec:
{{- end }}
spec:
serviceAccountName: {{ template "posthog.serviceAccountName" .root }}
{{- include "_snippet-topologySpreadConstraints" .root | nindent 6 }}

{{- if .params.affinity }}
affinity:
Expand Down
35 changes: 35 additions & 0 deletions charts/posthog/templates/_snippet-topologySpreadConstraints.tpl
Original file line number Diff line number Diff line change
@@ -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 }}
1 change: 1 addition & 0 deletions charts/posthog/templates/decide-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions charts/posthog/templates/events-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions charts/posthog/templates/pgbouncer-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions charts/posthog/templates/pgbouncer-read-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions charts/posthog/templates/recordings-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ spec:
spec:
terminationGracePeriodSeconds: {{ .Values.temporalPyWorker.terminationGracePeriodSeconds }}
serviceAccountName: {{ template "posthog.serviceAccountName" . }}
{{- include "_snippet-topologySpreadConstraints" . | nindent 6 }}

{{- if .Values.temporalPyWorker.affinity }}
affinity:
Expand Down
1 change: 1 addition & 0 deletions charts/posthog/templates/web-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions charts/posthog/templates/worker-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ spec:
{{- end }}
spec:
serviceAccountName: {{ template "posthog.serviceAccountName" . }}
{{- include "_snippet-topologySpreadConstraints" . | nindent 6 }}

{{- if .Values.worker.affinity }}
affinity:
Expand Down
49 changes: 49 additions & 0 deletions charts/posthog/tests/_topologySpreadConstraints.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions charts/posthog/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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