Skip to content

Commit 74ac365

Browse files
author
klamas
committed
add global nodeSelector, tolerations and affinity
1 parent c4bf1d4 commit 74ac365

13 files changed

+235
-85
lines changed

charts/posthog/ALL_VALUES.md

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ The following table lists the configurable parameters of the PostHog chart and t
2222
| posthogSecretKey.existingSecret | string | `nil` | Specify that the key should be pulled from an existing secret key. By default the chart will generate a secret and create a Kubernetes Secret containing it. |
2323
| posthogSecretKey.existingSecretKey | string | `"posthog-secret"` | Specify the key within the secret from which SECRET_KEY should be taken. |
2424
| env | list | `[]` | Environment variables to inject into every PostHog deployment. |
25+
| nodeSelector | object | `{}` | Global Node labels for all deployment. |
26+
| tolerations | list | `[]` | Global Toleration labels for all deployment. |
27+
| affinity | object | `{}` | Global Affinity settings for all deployment. |
2528
| migrate.enabled | bool | `true` | Whether to install the PostHog migrate job or not. |
2629
| events.enabled | bool | `true` | Whether to install the PostHog events stack or not. |
2730
| events.replicacount | int | `1` | Count of events pods to run. This setting is ignored if `events.hpa.enabled` is set to `true`. |

charts/posthog/templates/_snippet-plugins-deployment.tpl

+3-12
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,9 @@ spec:
3737
{{- end }}
3838
spec:
3939
serviceAccountName: {{ template "posthog.serviceAccountName" .root }}
40-
{{- if .params.affinity }}
41-
affinity:
42-
{{- toYaml .params.affinity | nindent 8 }}
43-
{{- end }}
44-
{{- if .params.nodeSelector }}
45-
nodeSelector:
46-
{{- toYaml .params.nodeSelector | nindent 8 }}
47-
{{- end }}
48-
{{- if .params.tolerations }}
49-
tolerations:
50-
{{- toYaml .params.tolerations | nindent 8 }}
51-
{{- end }}
40+
affinity: {{ toYaml (merge .params.affinity .root.Values.affinity) | nindent 8 }}
41+
nodeSelector: {{ toYaml (merge .params.nodeSelector .root.Values.nodeSelector) | nindent 8 }}
42+
tolerations: {{ toYaml (coalesce .params.tolerations .root.Values.tolerations) | nindent 8 }}
5243
{{- if .params.schedulerName }}
5344
schedulerName: "{{ .params.schedulerName }}"
5445
{{- end }}

charts/posthog/templates/clickhouse_instance.yaml

+3-10
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,9 @@ spec:
6868
podDistribution: {{ toYaml .Values.clickhouse.podDistribution | nindent 12 }}
6969
{{- end}}
7070
spec:
71-
{{- if .Values.clickhouse.affinity }}
72-
affinity: {{ toYaml .Values.clickhouse.affinity | nindent 12 }}
73-
{{- end }}
74-
{{- if .Values.clickhouse.tolerations }}
75-
tolerations: {{ toYaml .Values.clickhouse.tolerations | nindent 12 }}
76-
{{- end }}
77-
{{- if .Values.clickhouse.nodeSelector }}
78-
nodeSelector: {{ toYaml .Values.clickhouse.nodeSelector | nindent 12 }}
79-
{{- end }}
80-
71+
affinity: {{ toYaml (merge .Values.clickhouse.affinity .Values.affinity) | nindent 12 }}
72+
nodeSelector: {{ toYaml (merge .Values.clickhouse.nodeSelector .Values.nodeSelector) | nindent 12 }}
73+
tolerations: {{ toYaml (coalesce .Values.clickhouse.tolerations .Values.tolerations) | nindent 12 }}
8174
{{- if .Values.clickhouse.persistence.enabled }}
8275
volumes:
8376
{{- if .Values.clickhouse.persistence.existingClaim }}

charts/posthog/templates/events-deployment.yaml

+6-15
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ spec:
1818
metadata:
1919
annotations:
2020
checksum/secrets.yaml: {{ include (print $.Template.BasePath "/secrets.yaml") . | sha256sum }}
21-
{{- if .Values.web.podAnnotations }}
22-
{{ toYaml .Values.web.podAnnotations | indent 8 }}
21+
{{- if .Values.events.podAnnotations }}
22+
{{ toYaml .Values.events.podAnnotations | indent 8 }}
2323
{{- end }}
2424
labels:
2525
app: {{ template "posthog.fullname" . }}
@@ -34,18 +34,9 @@ spec:
3434
spec:
3535
terminationGracePeriodSeconds: {{ include "snippet.web-deployments.terminationGracePeriodSeconds" . }}
3636
serviceAccountName: {{ template "posthog.serviceAccountName" . }}
37-
{{- if .Values.web.affinity }}
38-
affinity:
39-
{{ toYaml .Values.web.affinity | indent 8 }}
40-
{{- end }}
41-
{{- if .Values.web.nodeSelector }}
42-
nodeSelector:
43-
{{ toYaml .Values.web.nodeSelector | indent 8 }}
44-
{{- end }}
45-
{{- if .Values.web.tolerations }}
46-
tolerations:
47-
{{ toYaml .Values.web.tolerations | indent 8 }}
48-
{{- end }}
37+
affinity: {{ toYaml (merge .Values.events.affinity .Values.affinity) | nindent 8 }}
38+
nodeSelector: {{ toYaml (merge .Values.events.nodeSelector .Values.nodeSelector) | nindent 8 }}
39+
tolerations: {{ toYaml (coalesce .Values.events.tolerations .Values.tolerations) | nindent 8 }}
4940
{{- if .Values.web.schedulerName }}
5041
schedulerName: "{{ .Values.web.schedulerName }}"
5142
{{- end }}
@@ -141,7 +132,7 @@ spec:
141132
timeoutSeconds: {{ .Values.web.startupProbe.timeoutSeconds }}
142133
resources:
143134
{{ if not .Values.events.resources }}
144-
{{ toYaml .Values.web.resources | indent 12 }}
135+
{{ toYaml .Values.events.resources | indent 12 }}
145136
{{ else }}
146137
{{ toYaml .Values.events.resources | indent 12 }}
147138
{{ end }}

charts/posthog/templates/migrate.job.yaml

+3-12
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,9 @@ spec:
2121
{{ toYaml .Values.worker.podLabels | indent 8 }}
2222
{{- end }}
2323
spec:
24-
{{- with .Values.hooks.affinity }}
25-
affinity:
26-
{{ toYaml . | indent 8 }}
27-
{{- end }}
28-
{{- with .Values.hooks.nodeSelector }}
29-
nodeSelector:
30-
{{ toYaml . | indent 8 }}
31-
{{- end }}
32-
{{- with .Values.hooks.tolerations }}
33-
tolerations:
34-
{{ toYaml . | indent 8 }}
35-
{{- end }}
24+
affinity: {{ toYaml (merge .Values.hooks.affinity .Values.affinity) | nindent 8 }}
25+
nodeSelector: {{ toYaml (merge .Values.hooks.nodeSelector .Values.nodeSelector) | nindent 8 }}
26+
tolerations: {{ toYaml (coalesce .Values.hooks.tolerations .Values.tolerations) | nindent 8 }}
3627
restartPolicy: Never
3728
{{- if .Values.image.imagePullSecrets }}
3829
imagePullSecrets:

charts/posthog/templates/pgbouncer-deployment.yaml

+3-10
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,10 @@ spec:
4040
# shuts down and exits before the terminationGracePeriod is done, we
4141
# moves to the next step immediately.
4242
terminationGracePeriodSeconds: 65
43-
4443
serviceAccountName: {{ template "posthog.serviceAccountName" . }}
45-
{{- if .Values.pgbouncer.affinity }}
46-
affinity: {{ toYaml .Values.pgbouncer.affinity | nindent 8 }}
47-
{{- end }}
48-
{{- if .Values.pgbouncer.nodeSelector }}
49-
nodeSelector: {{ toYaml .Values.pgbouncer.nodeSelector | nindent 8 }}
50-
{{- end }}
51-
{{- if .Values.pgbouncer.tolerations }}
52-
tolerations: {{ toYaml .Values.pgbouncer.tolerations | nindent 8 }}
53-
{{- end }}
44+
affinity: {{ toYaml (merge .Values.pgbouncer.affinity .Values.affinity) | nindent 8 }}
45+
nodeSelector: {{ toYaml (merge .Values.pgbouncer.nodeSelector .Values.nodeSelector) | nindent 8 }}
46+
tolerations: {{ toYaml (coalesce .Values.pgbouncer.tolerations .Values.tolerations) | nindent 8 }}
5447
{{- if .Values.pgbouncer.schedulerName }}
5548
schedulerName: "{{ .Values.pgbouncer.schedulerName }}"
5649
{{- end }}

charts/posthog/templates/web-deployment.yaml

+3-12
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,9 @@ spec:
3434
spec:
3535
terminationGracePeriodSeconds: {{ include "snippet.web-deployments.terminationGracePeriodSeconds" . }}
3636
serviceAccountName: {{ template "posthog.serviceAccountName" . }}
37-
{{- if .Values.web.affinity }}
38-
affinity:
39-
{{ toYaml .Values.web.affinity | indent 8 }}
40-
{{- end }}
41-
{{- if .Values.web.nodeSelector }}
42-
nodeSelector:
43-
{{ toYaml .Values.web.nodeSelector | indent 8 }}
44-
{{- end }}
45-
{{- if .Values.web.tolerations }}
46-
tolerations:
47-
{{ toYaml .Values.web.tolerations | indent 8 }}
48-
{{- end }}
37+
affinity: {{ toYaml (merge .Values.web.affinity .Values.affinity) | nindent 8 }}
38+
nodeSelector: {{ toYaml (merge .Values.web.nodeSelector .Values.nodeSelector) | nindent 8 }}
39+
tolerations: {{ toYaml (coalesce .Values.web.tolerations .Values.tolerations) | nindent 8 }}
4940
{{- if .Values.web.schedulerName }}
5041
schedulerName: "{{ .Values.web.schedulerName }}"
5142
{{- end }}

charts/posthog/templates/worker-deployment.yaml

+3-12
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,9 @@ spec:
3333
{{- end }}
3434
spec:
3535
serviceAccountName: {{ template "posthog.serviceAccountName" . }}
36-
{{- if .Values.worker.affinity }}
37-
affinity:
38-
{{ toYaml .Values.worker.affinity | indent 8 }}
39-
{{- end }}
40-
{{- if .Values.worker.nodeSelector }}
41-
nodeSelector:
42-
{{ toYaml .Values.worker.nodeSelector | indent 8 }}
43-
{{- end }}
44-
{{- if .Values.worker.tolerations }}
45-
tolerations:
46-
{{ toYaml .Values.worker.tolerations | indent 8 }}
47-
{{- end }}
36+
affinity: {{ toYaml (merge .Values.worker.affinity .Values.affinity) | nindent 8 }}
37+
nodeSelector: {{ toYaml (merge .Values.worker.nodeSelector .Values.nodeSelector) | nindent 8 }}
38+
tolerations: {{ toYaml (coalesce .Values.worker.tolerations .Values.tolerations) | nindent 8 }}
4839
{{- if .Values.worker.schedulerName }}
4940
schedulerName: "{{ .Values.worker.schedulerName }}"
5041
{{- end }}

charts/posthog/tests/__snapshot__/clickhouse-instance.yaml.snap

+3
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ the manifest should match the snapshot when using default values:
7070
podTemplates:
7171
- name: pod-template
7272
spec:
73+
affinity: {}
7374
containers:
7475
- command:
7576
- /bin/bash
@@ -87,10 +88,12 @@ the manifest should match the snapshot when using default values:
8788
volumeMounts:
8889
- mountPath: /var/lib/clickhouse
8990
name: data-volumeclaim-template
91+
nodeSelector: {}
9092
securityContext:
9193
fsGroup: 101
9294
runAsGroup: 101
9395
runAsUser: 101
96+
tolerations: null
9497
volumes:
9598
- name: data-volumeclaim-template
9699
persistentVolumeClaim:

charts/posthog/tests/__snapshot__/pgbouncer-deployment.yaml.snap

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
should match snapshot data:
22
1: |
3+
affinity: {}
34
containers:
45
- env:
56
- name: POSTGRESQL_USERNAME
@@ -54,5 +55,7 @@ should match snapshot data:
5455
tcpSocket:
5556
port: 6543
5657
timeoutSeconds: 2
58+
nodeSelector: {}
5759
serviceAccountName: RELEASE-NAME-posthog
5860
terminationGracePeriodSeconds: 65
61+
tolerations: null

charts/posthog/tests/clickhouse-instance.yaml

+88-1
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,84 @@ tests:
147147
- mountPath: /var/lib/clickhouse
148148
name: existing-volumeclaim
149149

150-
- it: nodeSelector override via 'clickhouse.nodeSelector' works
150+
- it: nodeSelector, affinity and tolerations via '.Values.<key>' works
151151
set:
152+
nodeSelector:
153+
diskType: hdd
154+
nodeType: slow
155+
affinity:
156+
nodeAffinity:
157+
requiredDuringSchedulingIgnoredDuringExecution:
158+
nodeSelectorTerms:
159+
- matchExpressions:
160+
- key: node-group
161+
operator: In
162+
values:
163+
- test
164+
tolerations:
165+
- key: dedicated
166+
operator: Equal
167+
value: test
168+
effect: NoExecute
169+
asserts:
170+
- hasDocuments:
171+
count: 1
172+
- equal:
173+
path: spec.templates.podTemplates[0].spec.nodeSelector
174+
value:
175+
diskType: hdd
176+
nodeType: slow
177+
- equal:
178+
path: spec.templates.podTemplates[0].spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms[0].matchExpressions[0]
179+
value:
180+
key: node-group
181+
operator: In
182+
values:
183+
- test
184+
- equal:
185+
path: spec.templates.podTemplates[0].spec.tolerations[0]
186+
value:
187+
key: dedicated
188+
operator: Equal
189+
value: test
190+
effect: NoExecute
191+
192+
- it: nodeSelector, affinity and tolerations override via '.Values.clickhouse.<key>' works
193+
set:
194+
nodeSelector:
195+
diskType: hdd
196+
nodeType: slow
197+
affinity:
198+
nodeAffinity:
199+
requiredDuringSchedulingIgnoredDuringExecution:
200+
nodeSelectorTerms:
201+
- matchExpressions:
202+
- key: node-group
203+
operator: In
204+
values:
205+
- test
206+
tolerations:
207+
- key: dedicated
208+
operator: Equal
209+
value: test
210+
effect: NoExecute
152211
clickhouse.nodeSelector:
153212
diskType: ssd
154213
nodeType: fast
214+
clickhouse.affinity:
215+
nodeAffinity:
216+
requiredDuringSchedulingIgnoredDuringExecution:
217+
nodeSelectorTerms:
218+
- matchExpressions:
219+
- key: node-group
220+
operator: In
221+
values:
222+
- test-override
223+
clickhouse.tolerations:
224+
- key: dedicated
225+
operator: Equal
226+
value: test-override
227+
effect: NoExecute
155228
asserts:
156229
- hasDocuments:
157230
count: 1
@@ -160,6 +233,20 @@ tests:
160233
value:
161234
diskType: ssd
162235
nodeType: fast
236+
- equal:
237+
path: spec.templates.podTemplates[0].spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms[0].matchExpressions[0]
238+
value:
239+
key: node-group
240+
operator: In
241+
values:
242+
- test-override
243+
- equal:
244+
path: spec.templates.podTemplates[0].spec.tolerations[0]
245+
value:
246+
key: dedicated
247+
operator: Equal
248+
value: test-override
249+
effect: NoExecute
163250

164251
- it: volumeClaimTemplates shouldn't exit if clickhouse.persistence.enabled is false
165252
set:

0 commit comments

Comments
 (0)