diff --git a/charts/posthog/ALL_VALUES.md b/charts/posthog/ALL_VALUES.md index d5420965b..8f238e95e 100644 --- a/charts/posthog/ALL_VALUES.md +++ b/charts/posthog/ALL_VALUES.md @@ -22,6 +22,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`. | diff --git a/charts/posthog/templates/_snippet-plugins-deployment.tpl b/charts/posthog/templates/_snippet-plugins-deployment.tpl index 360e39e30..44d4c1134 100644 --- a/charts/posthog/templates/_snippet-plugins-deployment.tpl +++ b/charts/posthog/templates/_snippet-plugins-deployment.tpl @@ -37,18 +37,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 }} diff --git a/charts/posthog/templates/clickhouse_instance.yaml b/charts/posthog/templates/clickhouse_instance.yaml index 6e4b5a41e..ce1365388 100644 --- a/charts/posthog/templates/clickhouse_instance.yaml +++ b/charts/posthog/templates/clickhouse_instance.yaml @@ -68,16 +68,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 }} diff --git a/charts/posthog/templates/events-deployment.yaml b/charts/posthog/templates/events-deployment.yaml index 50d039f37..a5873fb2b 100644 --- a/charts/posthog/templates/events-deployment.yaml +++ b/charts/posthog/templates/events-deployment.yaml @@ -18,8 +18,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" . }} @@ -34,18 +34,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 }} @@ -141,7 +132,7 @@ spec: timeoutSeconds: {{ .Values.web.startupProbe.timeoutSeconds }} resources: {{ if not .Values.events.resources }} -{{ toYaml .Values.web.resources | indent 12 }} +{{ toYaml .Values.events.resources | indent 12 }} {{ else }} {{ toYaml .Values.events.resources | indent 12 }} {{ end }} diff --git a/charts/posthog/templates/migrate.job.yaml b/charts/posthog/templates/migrate.job.yaml index 6e78d41b8..b2c62a59c 100644 --- a/charts/posthog/templates/migrate.job.yaml +++ b/charts/posthog/templates/migrate.job.yaml @@ -21,18 +21,9 @@ 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: diff --git a/charts/posthog/templates/pgbouncer-deployment.yaml b/charts/posthog/templates/pgbouncer-deployment.yaml index 50f6da1aa..8b6803c5d 100644 --- a/charts/posthog/templates/pgbouncer-deployment.yaml +++ b/charts/posthog/templates/pgbouncer-deployment.yaml @@ -40,17 +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 }} diff --git a/charts/posthog/templates/web-deployment.yaml b/charts/posthog/templates/web-deployment.yaml index b6dff9a99..e21818f26 100644 --- a/charts/posthog/templates/web-deployment.yaml +++ b/charts/posthog/templates/web-deployment.yaml @@ -34,18 +34,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 }} diff --git a/charts/posthog/templates/worker-deployment.yaml b/charts/posthog/templates/worker-deployment.yaml index 444c7e41a..3fc15087c 100644 --- a/charts/posthog/templates/worker-deployment.yaml +++ b/charts/posthog/templates/worker-deployment.yaml @@ -33,18 +33,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 }} diff --git a/charts/posthog/tests/__snapshot__/clickhouse-instance.yaml.snap b/charts/posthog/tests/__snapshot__/clickhouse-instance.yaml.snap index 8449d52a7..abe083e29 100644 --- a/charts/posthog/tests/__snapshot__/clickhouse-instance.yaml.snap +++ b/charts/posthog/tests/__snapshot__/clickhouse-instance.yaml.snap @@ -70,6 +70,7 @@ the manifest should match the snapshot when using default values: podTemplates: - name: pod-template spec: + affinity: {} containers: - command: - /bin/bash @@ -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: diff --git a/charts/posthog/tests/__snapshot__/pgbouncer-deployment.yaml.snap b/charts/posthog/tests/__snapshot__/pgbouncer-deployment.yaml.snap index 4e82d25de..7c33adfbd 100644 --- a/charts/posthog/tests/__snapshot__/pgbouncer-deployment.yaml.snap +++ b/charts/posthog/tests/__snapshot__/pgbouncer-deployment.yaml.snap @@ -1,5 +1,6 @@ should match snapshot data: 1: | + affinity: {} containers: - env: - name: POSTGRESQL_USERNAME @@ -54,5 +55,7 @@ should match snapshot data: tcpSocket: port: 6543 timeoutSeconds: 2 + nodeSelector: {} serviceAccountName: RELEASE-NAME-posthog terminationGracePeriodSeconds: 65 + tolerations: null diff --git a/charts/posthog/tests/clickhouse-instance.yaml b/charts/posthog/tests/clickhouse-instance.yaml index 527dce34b..f60543898 100644 --- a/charts/posthog/tests/clickhouse-instance.yaml +++ b/charts/posthog/tests/clickhouse-instance.yaml @@ -147,11 +147,84 @@ tests: - mountPath: /var/lib/clickhouse name: existing-volumeclaim - - it: nodeSelector override via 'clickhouse.nodeSelector' works + - it: nodeSelector, affinity and tolerations via '.Values.' 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.' 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 @@ -160,6 +233,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: diff --git a/charts/posthog/tests/migrate-job.yaml b/charts/posthog/tests/migrate-job.yaml index 0a1efe8ab..e946cf6e0 100644 --- a/charts/posthog/tests/migrate-job.yaml +++ b/charts/posthog/tests/migrate-job.yaml @@ -45,13 +45,88 @@ tests: name: SENTRY_DSN value: sentry.endpoint + - it: nodeSelector via 'nodeSelector' works + template: templates/migrate.job.yaml # TODO: remove once secrets.yaml will be fixed/removed + set: + cloud: local # TODO: remove once secrets.yaml will be fixed/removed + 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.template.spec.nodeSelector + value: + diskType: hdd + nodeType: slow + - equal: + path: spec.template.spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms[0].matchExpressions[0] + value: + key: node-group + operator: In + values: + - test + - equal: + path: spec.template.spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms[0].matchExpressions[0] + value: + key: node-group + operator: In + values: + - test + - it: nodeSelector override via 'hooks.nodeSelector' works template: templates/migrate.job.yaml # TODO: remove once secrets.yaml will be fixed/removed set: cloud: local # TODO: remove once secrets.yaml will be fixed/removed + 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 hooks.nodeSelector: diskType: ssd nodeType: fast + hooks.affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: node-group + operator: In + values: + - test-override + hooks.tolerations: + - key: dedicated + operator: Equal + value: test-override + effect: NoExecute asserts: - hasDocuments: count: 1 @@ -60,3 +135,17 @@ tests: value: diskType: ssd nodeType: fast + - equal: + path: spec.template.spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms[0].matchExpressions[0] + value: + key: node-group + operator: In + values: + - test-override + - equal: + path: spec.template.spec.tolerations[0] + value: + key: dedicated + operator: Equal + value: test-override + effect: NoExecute diff --git a/charts/posthog/values.yaml b/charts/posthog/values.yaml index 8b33810a6..bf28cbaa9 100644 --- a/charts/posthog/values.yaml +++ b/charts/posthog/values.yaml @@ -39,16 +39,27 @@ env: [] # - name: FOO # value: bar +# -- Global Node labels for all deployment. +nodeSelector: {} +# -- Global Toleration labels for all deployment. +tolerations: [] +# -- Global Affinity settings for all deployment. +affinity: {} migrate: # -- Whether to install the PostHog migrate job or not. enabled: true - events: # -- Whether to install the PostHog events stack or not. enabled: true + podAnnotations: + # Uncomment these lines if you want Prometheus server to scrape metrics. + # prometheus.io/scrape: "true" + # prometheus.io/path: /metrics + # prometheus.io/port: "8001" + # -- Count of events pods to run. This setting is ignored if `events.hpa.enabled` is set to `true`. replicacount: 1 @@ -66,6 +77,17 @@ events: # for configuration options behavior: + # -- Resource limits for events service. + resources: + {} + + # -- Node labels for events stack deployment. + nodeSelector: {} + # -- Toleration labels for events stack deployment. + tolerations: [] + # -- Affinity settings for events stack deployment. + affinity: {} + # -- Container security context for the events stack HorizontalPodAutoscaler. securityContext: enabled: false @@ -1197,6 +1219,8 @@ clickhouse: # -- Image pull policy pullPolicy: IfNotPresent + # -- Node labels for clickhouse pod assignment + nodeSelector: {} # -- Toleration labels for clickhouse pod assignment tolerations: [] # -- Affinity settings for clickhouse pod