Skip to content

Commit

Permalink
add global nodeSelector, tolerations and affinity
Browse files Browse the repository at this point in the history
  • Loading branch information
klamas committed Jan 17, 2023
1 parent 3c06726 commit 3a7606a
Show file tree
Hide file tree
Showing 15 changed files with 241 additions and 108 deletions.
3 changes: 3 additions & 0 deletions charts/posthog/ALL_VALUES.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ The following table lists the configurable parameters of the PostHog chart and t
| 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. |
| posthogSecretKey.existingSecretKey | string | `"posthog-secret"` | Specify the key within the secret from which SECRET_KEY should be taken. |
| env | list | `[]` | Environment variables to inject into every PostHog deployment. |
| nodeSelector | object | `{}` | Global Node labels for all deployment. |
| tolerations | list | `[]` | Global Toleration labels for all deployment. |
| affinity | object | `{}` | Global Affinity settings for all deployment. |
| migrate.enabled | bool | `true` | Whether to install the PostHog migrate job or not. |
| events.enabled | bool | `true` | Whether to install the PostHog events stack or not. |
| events.replicacount | int | `1` | Count of events pods to run. This setting is ignored if `events.hpa.enabled` is set to `true`. |
Expand Down
19 changes: 3 additions & 16 deletions charts/posthog/templates/_snippet-plugins-deployment.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,9 @@ spec:
{{- end }}
spec:
serviceAccountName: {{ template "posthog.serviceAccountName" .root }}

{{- if .params.affinity }}
affinity:
{{- toYaml .params.affinity | nindent 8 }}
{{- end }}

{{- if .params.nodeSelector }}
nodeSelector:
{{- toYaml .params.nodeSelector | nindent 8 }}
{{- end }}

{{- if .params.tolerations }}
tolerations:
{{- toYaml .params.tolerations | nindent 8 }}
{{- end }}

affinity: {{ toYaml (merge .params.affinity .root.Values.affinity) | nindent 8 }}
nodeSelector: {{ toYaml (merge .params.nodeSelector .root.Values.nodeSelector) | nindent 8 }}
tolerations: {{ toYaml (coalesce .params.tolerations .root.Values.tolerations) | nindent 8 }}
{{- if .params.schedulerName }}
schedulerName: "{{ .params.schedulerName }}"
{{- end }}
Expand Down
3 changes: 3 additions & 0 deletions charts/posthog/templates/clickhouse-backup-cronjob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ spec:
{{- end }}
{{- end }}
{{- end }}
affinity: {{ toYaml (merge .Values.clickhouse.affinity .Values.affinity) | nindent 12 }}
nodeSelector: {{ toYaml (merge .Values.clickhouse.nodeSelector .Values.nodeSelector) | nindent 12 }}
tolerations: {{ toYaml (coalesce .Values.clickhouse.tolerations .Values.tolerations) | nindent 12 }}

initContainers:
#
Expand Down
13 changes: 3 additions & 10 deletions charts/posthog/templates/clickhouse_instance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,9 @@ spec:
podDistribution: {{ toYaml .Values.clickhouse.podDistribution | nindent 12 }}
{{- end}}
spec:
{{- if .Values.clickhouse.affinity }}
affinity: {{ toYaml .Values.clickhouse.affinity | nindent 12 }}
{{- end }}
{{- if .Values.clickhouse.tolerations }}
tolerations: {{ toYaml .Values.clickhouse.tolerations | nindent 12 }}
{{- end }}
{{- if .Values.clickhouse.nodeSelector }}
nodeSelector: {{ toYaml .Values.clickhouse.nodeSelector | nindent 12 }}
{{- end }}

affinity: {{ toYaml (merge .Values.clickhouse.affinity .Values.affinity) | nindent 12 }}
nodeSelector: {{ toYaml (merge .Values.clickhouse.nodeSelector .Values.nodeSelector) | nindent 12 }}
tolerations: {{ toYaml (coalesce .Values.clickhouse.tolerations .Values.tolerations) | nindent 12 }}
{{- if .Values.clickhouse.persistence.enabled }}
volumes:
{{- if .Values.clickhouse.persistence.existingClaim }}
Expand Down
23 changes: 5 additions & 18 deletions charts/posthog/templates/events-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ spec:
metadata:
annotations:
checksum/secrets.yaml: {{ include (print $.Template.BasePath "/secrets.yaml") . | sha256sum }}
{{- if .Values.web.podAnnotations }}
{{ toYaml .Values.web.podAnnotations | indent 8 }}
{{- if .Values.events.podAnnotations }}
{{ toYaml .Values.events.podAnnotations | indent 8 }}
{{- end }}
labels:
app: {{ template "posthog.fullname" . }}
Expand All @@ -41,22 +41,9 @@ spec:
spec:
terminationGracePeriodSeconds: {{ include "snippet.web-deployments.terminationGracePeriodSeconds" . }}
serviceAccountName: {{ template "posthog.serviceAccountName" . }}

{{- if .Values.web.affinity }}
affinity:
{{ toYaml .Values.web.affinity | indent 8 }}
{{- end }}

{{- if .Values.web.nodeSelector }}
nodeSelector:
{{ toYaml .Values.web.nodeSelector | indent 8 }}
{{- end }}

{{- if .Values.web.tolerations }}
tolerations:
{{ toYaml .Values.web.tolerations | indent 8 }}
{{- end }}

affinity: {{ toYaml (merge .Values.events.affinity .Values.affinity) | nindent 8 }}
nodeSelector: {{ toYaml (merge .Values.events.nodeSelector .Values.nodeSelector) | nindent 8 }}
tolerations: {{ toYaml (coalesce .Values.events.tolerations .Values.tolerations) | nindent 8 }}
{{- if .Values.web.schedulerName }}
schedulerName: "{{ .Values.web.schedulerName }}"
{{- end }}
Expand Down
20 changes: 4 additions & 16 deletions charts/posthog/templates/migrate.job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,16 @@ spec:
{{ toYaml .Values.worker.podLabels | indent 8 }}
{{- end }}
spec:
{{- with .Values.hooks.affinity }}
affinity:
{{ toYaml . | indent 8 }}
{{- end }}

{{- with .Values.hooks.nodeSelector }}
nodeSelector:
{{ toYaml . | indent 8 }}
{{- end }}

{{- with .Values.hooks.tolerations }}
tolerations:
{{ toYaml . | indent 8 }}
{{- end }}

affinity: {{ toYaml (merge .Values.hooks.affinity .Values.affinity) | nindent 8 }}
nodeSelector: {{ toYaml (merge .Values.hooks.nodeSelector .Values.nodeSelector) | nindent 8 }}
tolerations: {{ toYaml (coalesce .Values.hooks.tolerations .Values.tolerations) | nindent 8 }}
restartPolicy: Never

{{- if .Values.image.imagePullSecrets }}
imagePullSecrets:
{{ toYaml .Values.image.imagePullSecrets | indent 8 }}
{{- end }}

# I do not know for sure if the old one has been used anywhere, so do both :(
{{- if .Values.image.pullSecrets }}
imagePullSecrets:
Expand Down
17 changes: 3 additions & 14 deletions charts/posthog/templates/pgbouncer-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,10 @@ spec:
# shuts down and exits before the terminationGracePeriod is done, we
# moves to the next step immediately.
terminationGracePeriodSeconds: 65

serviceAccountName: {{ template "posthog.serviceAccountName" . }}

{{- if .Values.pgbouncer.affinity }}
affinity: {{ toYaml .Values.pgbouncer.affinity | nindent 8 }}
{{- end }}

{{- if .Values.pgbouncer.nodeSelector }}
nodeSelector: {{ toYaml .Values.pgbouncer.nodeSelector | nindent 8 }}
{{- end }}

{{- if .Values.pgbouncer.tolerations }}
tolerations: {{ toYaml .Values.pgbouncer.tolerations | nindent 8 }}
{{- end }}

affinity: {{ toYaml (merge .Values.pgbouncer.affinity .Values.affinity) | nindent 8 }}
nodeSelector: {{ toYaml (merge .Values.pgbouncer.nodeSelector .Values.nodeSelector) | nindent 8 }}
tolerations: {{ toYaml (coalesce .Values.pgbouncer.tolerations .Values.tolerations) | nindent 8 }}
{{- if .Values.pgbouncer.schedulerName }}
schedulerName: "{{ .Values.pgbouncer.schedulerName }}"
{{- end }}
Expand Down
19 changes: 3 additions & 16 deletions charts/posthog/templates/web-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,9 @@ spec:
spec:
terminationGracePeriodSeconds: {{ include "snippet.web-deployments.terminationGracePeriodSeconds" . }}
serviceAccountName: {{ template "posthog.serviceAccountName" . }}

{{- if .Values.web.affinity }}
affinity:
{{ toYaml .Values.web.affinity | indent 8 }}
{{- end }}

{{- if .Values.web.nodeSelector }}
nodeSelector:
{{ toYaml .Values.web.nodeSelector | indent 8 }}
{{- end }}

{{- if .Values.web.tolerations }}
tolerations:
{{ toYaml .Values.web.tolerations | indent 8 }}
{{- end }}

affinity: {{ toYaml (merge .Values.web.affinity .Values.affinity) | nindent 8 }}
nodeSelector: {{ toYaml (merge .Values.web.nodeSelector .Values.nodeSelector) | nindent 8 }}
tolerations: {{ toYaml (coalesce .Values.web.tolerations .Values.tolerations) | nindent 8 }}
{{- if .Values.web.schedulerName }}
schedulerName: "{{ .Values.web.schedulerName }}"
{{- end }}
Expand Down
19 changes: 3 additions & 16 deletions charts/posthog/templates/worker-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,9 @@ spec:
{{- end }}
spec:
serviceAccountName: {{ template "posthog.serviceAccountName" . }}

{{- if .Values.worker.affinity }}
affinity:
{{ toYaml .Values.worker.affinity | indent 8 }}
{{- end }}

{{- if .Values.worker.nodeSelector }}
nodeSelector:
{{ toYaml .Values.worker.nodeSelector | indent 8 }}
{{- end }}

{{- if .Values.worker.tolerations }}
tolerations:
{{ toYaml .Values.worker.tolerations | indent 8 }}
{{- end }}

affinity: {{ toYaml (merge .Values.worker.affinity .Values.affinity) | nindent 8 }}
nodeSelector: {{ toYaml (merge .Values.worker.nodeSelector .Values.nodeSelector) | nindent 8 }}
tolerations: {{ toYaml (coalesce .Values.worker.tolerations .Values.tolerations) | nindent 8 }}
{{- if .Values.worker.schedulerName }}
schedulerName: "{{ .Values.worker.schedulerName }}"
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ should match the snapshot when backup is true:
labels:
job: clickhouse-backup
spec:
affinity: {}
containers:
- command:
- /bin/sh
Expand Down Expand Up @@ -67,7 +68,9 @@ should match the snapshot when backup is true:
image: busybox:1.34
imagePullPolicy: IfNotPresent
name: wait-for-service-dependencies
nodeSelector: {}
restartPolicy: Never
tolerations: null
volumes:
- configMap:
defaultMode: 511
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ the manifest should match the snapshot when using default values:
podTemplates:
- name: pod-template
spec:
affinity: {}
containers:
- command:
- /bin/bash
Expand All @@ -87,10 +88,12 @@ the manifest should match the snapshot when using default values:
volumeMounts:
- mountPath: /var/lib/clickhouse
name: data-volumeclaim-template
nodeSelector: {}
securityContext:
fsGroup: 101
runAsGroup: 101
runAsUser: 101
tolerations: null
volumes:
- name: data-volumeclaim-template
persistentVolumeClaim:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
should match snapshot data:
1: |
affinity: {}
containers:
- env:
- name: POSTGRESQL_USERNAME
Expand Down Expand Up @@ -54,5 +55,7 @@ should match snapshot data:
tcpSocket:
port: 6543
timeoutSeconds: 2
nodeSelector: {}
serviceAccountName: RELEASE-NAME-posthog
terminationGracePeriodSeconds: 65
tolerations: null
89 changes: 88 additions & 1 deletion charts/posthog/tests/clickhouse-instance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,84 @@ tests:
- mountPath: /var/lib/clickhouse
name: existing-volumeclaim

- it: nodeSelector override via 'clickhouse.nodeSelector' works
- it: nodeSelector, affinity and tolerations via '.Values.<key>' works
set:
nodeSelector:
diskType: hdd
nodeType: slow
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: node-group
operator: In
values:
- test
tolerations:
- key: dedicated
operator: Equal
value: test
effect: NoExecute
asserts:
- hasDocuments:
count: 1
- equal:
path: spec.templates.podTemplates[0].spec.nodeSelector
value:
diskType: hdd
nodeType: slow
- equal:
path: spec.templates.podTemplates[0].spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms[0].matchExpressions[0]
value:
key: node-group
operator: In
values:
- test
- equal:
path: spec.templates.podTemplates[0].spec.tolerations[0]
value:
key: dedicated
operator: Equal
value: test
effect: NoExecute

- it: nodeSelector, affinity and tolerations override via '.Values.clickhouse.<key>' works
set:
nodeSelector:
diskType: hdd
nodeType: slow
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: node-group
operator: In
values:
- test
tolerations:
- key: dedicated
operator: Equal
value: test
effect: NoExecute
clickhouse.nodeSelector:
diskType: ssd
nodeType: fast
clickhouse.affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: node-group
operator: In
values:
- test-override
clickhouse.tolerations:
- key: dedicated
operator: Equal
value: test-override
effect: NoExecute
asserts:
- hasDocuments:
count: 1
Expand All @@ -159,6 +232,20 @@ tests:
value:
diskType: ssd
nodeType: fast
- equal:
path: spec.templates.podTemplates[0].spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms[0].matchExpressions[0]
value:
key: node-group
operator: In
values:
- test-override
- equal:
path: spec.templates.podTemplates[0].spec.tolerations[0]
value:
key: dedicated
operator: Equal
value: test-override
effect: NoExecute

- it: volumeClaimTemplates shouldn't exit if clickhouse.persistence.enabled is false
set:
Expand Down
Loading

0 comments on commit 3a7606a

Please sign in to comment.