Skip to content

Commit b33d608

Browse files
author
klamas
committed
add global nodeSelector, tolerations and affinity
1 parent 3c06726 commit b33d608

14 files changed

+238
-108
lines changed

charts/posthog/ALL_VALUES.md

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ The following table lists the configurable parameters of the PostHog chart and t
2323
| 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. |
2424
| posthogSecretKey.existingSecretKey | string | `"posthog-secret"` | Specify the key within the secret from which SECRET_KEY should be taken. |
2525
| env | list | `[]` | Environment variables to inject into every PostHog deployment. |
26+
| nodeSelector | object | `{}` | Global Node labels for all deployment. |
27+
| tolerations | list | `[]` | Global Toleration labels for all deployment. |
28+
| affinity | object | `{}` | Global Affinity settings for all deployment. |
2629
| migrate.enabled | bool | `true` | Whether to install the PostHog migrate job or not. |
2730
| events.enabled | bool | `true` | Whether to install the PostHog events stack or not. |
2831
| 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-16
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,9 @@ spec:
4444
{{- end }}
4545
spec:
4646
serviceAccountName: {{ template "posthog.serviceAccountName" .root }}
47-
48-
{{- if .params.affinity }}
49-
affinity:
50-
{{- toYaml .params.affinity | nindent 8 }}
51-
{{- end }}
52-
53-
{{- if .params.nodeSelector }}
54-
nodeSelector:
55-
{{- toYaml .params.nodeSelector | nindent 8 }}
56-
{{- end }}
57-
58-
{{- if .params.tolerations }}
59-
tolerations:
60-
{{- toYaml .params.tolerations | nindent 8 }}
61-
{{- end }}
62-
47+
affinity: {{ toYaml (merge .params.affinity .root.Values.affinity) | nindent 8 }}
48+
nodeSelector: {{ toYaml (merge .params.nodeSelector .root.Values.nodeSelector) | nindent 8 }}
49+
tolerations: {{ toYaml (coalesce .params.tolerations .root.Values.tolerations) | nindent 8 }}
6350
{{- if .params.schedulerName }}
6451
schedulerName: "{{ .params.schedulerName }}"
6552
{{- end }}

charts/posthog/templates/clickhouse-backup-cronjob.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ spec:
2929
{{- end }}
3030
{{- end }}
3131
{{- end }}
32+
affinity: {{ toYaml (merge .Values.clickhouse.affinity .Values.affinity) | nindent 12 }}
33+
nodeSelector: {{ toYaml (merge .Values.clickhouse.nodeSelector .Values.nodeSelector) | nindent 12 }}
34+
tolerations: {{ toYaml (coalesce .Values.clickhouse.tolerations .Values.tolerations) | nindent 12 }}
3235

3336
initContainers:
3437
#

charts/posthog/templates/clickhouse_instance.yaml

+3-10
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,9 @@ spec:
7171
podDistribution: {{ toYaml .Values.clickhouse.podDistribution | nindent 12 }}
7272
{{- end}}
7373
spec:
74-
{{- if .Values.clickhouse.affinity }}
75-
affinity: {{ toYaml .Values.clickhouse.affinity | nindent 12 }}
76-
{{- end }}
77-
{{- if .Values.clickhouse.tolerations }}
78-
tolerations: {{ toYaml .Values.clickhouse.tolerations | nindent 12 }}
79-
{{- end }}
80-
{{- if .Values.clickhouse.nodeSelector }}
81-
nodeSelector: {{ toYaml .Values.clickhouse.nodeSelector | nindent 12 }}
82-
{{- end }}
83-
74+
affinity: {{ toYaml (merge .Values.clickhouse.affinity .Values.affinity) | nindent 12 }}
75+
nodeSelector: {{ toYaml (merge .Values.clickhouse.nodeSelector .Values.nodeSelector) | nindent 12 }}
76+
tolerations: {{ toYaml (coalesce .Values.clickhouse.tolerations .Values.tolerations) | nindent 12 }}
8477
{{- if .Values.clickhouse.persistence.enabled }}
8578
volumes:
8679
{{- if .Values.clickhouse.persistence.existingClaim }}

charts/posthog/templates/events-deployment.yaml

+5-18
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ spec:
2525
metadata:
2626
annotations:
2727
checksum/secrets.yaml: {{ include (print $.Template.BasePath "/secrets.yaml") . | sha256sum }}
28-
{{- if .Values.web.podAnnotations }}
29-
{{ toYaml .Values.web.podAnnotations | indent 8 }}
28+
{{- if .Values.events.podAnnotations }}
29+
{{ toYaml .Values.events.podAnnotations | indent 8 }}
3030
{{- end }}
3131
labels:
3232
app: {{ template "posthog.fullname" . }}
@@ -41,22 +41,9 @@ spec:
4141
spec:
4242
terminationGracePeriodSeconds: {{ include "snippet.web-deployments.terminationGracePeriodSeconds" . }}
4343
serviceAccountName: {{ template "posthog.serviceAccountName" . }}
44-
45-
{{- if .Values.web.affinity }}
46-
affinity:
47-
{{ toYaml .Values.web.affinity | indent 8 }}
48-
{{- end }}
49-
50-
{{- if .Values.web.nodeSelector }}
51-
nodeSelector:
52-
{{ toYaml .Values.web.nodeSelector | indent 8 }}
53-
{{- end }}
54-
55-
{{- if .Values.web.tolerations }}
56-
tolerations:
57-
{{ toYaml .Values.web.tolerations | indent 8 }}
58-
{{- end }}
59-
44+
affinity: {{ toYaml (merge .Values.events.affinity .Values.affinity) | nindent 8 }}
45+
nodeSelector: {{ toYaml (merge .Values.events.nodeSelector .Values.nodeSelector) | nindent 8 }}
46+
tolerations: {{ toYaml (coalesce .Values.events.tolerations .Values.tolerations) | nindent 8 }}
6047
{{- if .Values.web.schedulerName }}
6148
schedulerName: "{{ .Values.web.schedulerName }}"
6249
{{- end }}

charts/posthog/templates/migrate.job.yaml

+4-16
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,16 @@ 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-
29-
{{- with .Values.hooks.nodeSelector }}
30-
nodeSelector:
31-
{{ toYaml . | indent 8 }}
32-
{{- end }}
33-
34-
{{- with .Values.hooks.tolerations }}
35-
tolerations:
36-
{{ toYaml . | indent 8 }}
37-
{{- end }}
38-
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 }}
3927
restartPolicy: Never
4028

4129
{{- if .Values.image.imagePullSecrets }}
4230
imagePullSecrets:
4331
{{ toYaml .Values.image.imagePullSecrets | indent 8 }}
4432
{{- end }}
45-
33+
4634
# I do not know for sure if the old one has been used anywhere, so do both :(
4735
{{- if .Values.image.pullSecrets }}
4836
imagePullSecrets:

charts/posthog/templates/pgbouncer-deployment.yaml

+3-14
Original file line numberDiff line numberDiff line change
@@ -40,21 +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-
46-
{{- if .Values.pgbouncer.affinity }}
47-
affinity: {{ toYaml .Values.pgbouncer.affinity | nindent 8 }}
48-
{{- end }}
49-
50-
{{- if .Values.pgbouncer.nodeSelector }}
51-
nodeSelector: {{ toYaml .Values.pgbouncer.nodeSelector | nindent 8 }}
52-
{{- end }}
53-
54-
{{- if .Values.pgbouncer.tolerations }}
55-
tolerations: {{ toYaml .Values.pgbouncer.tolerations | nindent 8 }}
56-
{{- end }}
57-
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 }}
5847
{{- if .Values.pgbouncer.schedulerName }}
5948
schedulerName: "{{ .Values.pgbouncer.schedulerName }}"
6049
{{- end }}

charts/posthog/templates/web-deployment.yaml

+3-16
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,9 @@ spec:
4141
spec:
4242
terminationGracePeriodSeconds: {{ include "snippet.web-deployments.terminationGracePeriodSeconds" . }}
4343
serviceAccountName: {{ template "posthog.serviceAccountName" . }}
44-
45-
{{- if .Values.web.affinity }}
46-
affinity:
47-
{{ toYaml .Values.web.affinity | indent 8 }}
48-
{{- end }}
49-
50-
{{- if .Values.web.nodeSelector }}
51-
nodeSelector:
52-
{{ toYaml .Values.web.nodeSelector | indent 8 }}
53-
{{- end }}
54-
55-
{{- if .Values.web.tolerations }}
56-
tolerations:
57-
{{ toYaml .Values.web.tolerations | indent 8 }}
58-
{{- end }}
59-
44+
affinity: {{ toYaml (merge .Values.web.affinity .Values.affinity) | nindent 8 }}
45+
nodeSelector: {{ toYaml (merge .Values.web.nodeSelector .Values.nodeSelector) | nindent 8 }}
46+
tolerations: {{ toYaml (coalesce .Values.web.tolerations .Values.tolerations) | nindent 8 }}
6047
{{- if .Values.web.schedulerName }}
6148
schedulerName: "{{ .Values.web.schedulerName }}"
6249
{{- end }}

charts/posthog/templates/worker-deployment.yaml

+3-16
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,9 @@ spec:
4040
{{- end }}
4141
spec:
4242
serviceAccountName: {{ template "posthog.serviceAccountName" . }}
43-
44-
{{- if .Values.worker.affinity }}
45-
affinity:
46-
{{ toYaml .Values.worker.affinity | indent 8 }}
47-
{{- end }}
48-
49-
{{- if .Values.worker.nodeSelector }}
50-
nodeSelector:
51-
{{ toYaml .Values.worker.nodeSelector | indent 8 }}
52-
{{- end }}
53-
54-
{{- if .Values.worker.tolerations }}
55-
tolerations:
56-
{{ toYaml .Values.worker.tolerations | indent 8 }}
57-
{{- end }}
58-
43+
affinity: {{ toYaml (merge .Values.worker.affinity .Values.affinity) | nindent 8 }}
44+
nodeSelector: {{ toYaml (merge .Values.worker.nodeSelector .Values.nodeSelector) | nindent 8 }}
45+
tolerations: {{ toYaml (coalesce .Values.worker.tolerations .Values.tolerations) | nindent 8 }}
5946
{{- if .Values.worker.schedulerName }}
6047
schedulerName: "{{ .Values.worker.schedulerName }}"
6148
{{- 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
@@ -146,11 +146,84 @@ tests:
146146
- mountPath: /var/lib/clickhouse
147147
name: existing-volumeclaim
148148

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

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

0 commit comments

Comments
 (0)