From 44659ac9a7cf2c56ff39d93e8e0deb089e1a6d4d Mon Sep 17 00:00:00 2001 From: Laurence Gill Date: Wed, 7 Jun 2023 13:18:45 +0100 Subject: [PATCH] Implement serviceAccount support for clickhouse pod --- charts/posthog/ALL_VALUES.md | 4 ++++ charts/posthog/templates/_helpers.tpl | 6 ++++++ .../templates/clickhouse-serviceaccount.yaml | 12 ++++++++++++ charts/posthog/templates/clickhouse_instance.yaml | 5 +++++ charts/posthog/values.yaml | 13 +++++++++++++ 5 files changed, 40 insertions(+) create mode 100644 charts/posthog/templates/clickhouse-serviceaccount.yaml diff --git a/charts/posthog/ALL_VALUES.md b/charts/posthog/ALL_VALUES.md index 5d292cdc9..79ea3c219 100644 --- a/charts/posthog/ALL_VALUES.md +++ b/charts/posthog/ALL_VALUES.md @@ -620,7 +620,11 @@ The following table lists the configurable parameters of the PostHog chart and t | clickhouse.image.tag | string | `"22.8.11.15"` | ClickHouse image tag. Note: PostHog does not support all versions of ClickHouse. Please override the default only if you know what you are doing. | | clickhouse.image.pullPolicy | string | `"IfNotPresent"` | Image pull policy | | clickhouse.image.pullSecrets | list | `[]` | | +| clickhouse.serviceAccount.create | bool | `false` | serviceAccount should be created - boolean | +| clickhouse.serviceAccount.name | string | `nil` | name of the serviceAccount | +| clickhouse.serviceAccount.annotations | object | `{}` | Configures annotation for the serviceAccount | | clickhouse.tolerations | list | `[]` | Toleration labels for clickhouse pod assignment | +| clickhouse.serviceAccountName | string | `""` | Override serviceAccountName for clickhouse pod Note: this will override serviceAccount.name if both are set | | clickhouse.affinity | object | `{}` | Affinity settings for clickhouse pod | | clickhouse.resources | object | `{}` | Clickhouse resource requests/limits. See more at http://kubernetes.io/docs/user-guide/compute-resources/ | | clickhouse.securityContext.enabled | bool | `true` | | diff --git a/charts/posthog/templates/_helpers.tpl b/charts/posthog/templates/_helpers.tpl index 55177d20f..8db801da1 100644 --- a/charts/posthog/templates/_helpers.tpl +++ b/charts/posthog/templates/_helpers.tpl @@ -178,6 +178,12 @@ Create the name of the service account to use {{- end -}} {{- end -}} +{{- define "posthog.clickhouse.serviceAccount" -}} +{{- if .Values.clickhouse.serviceAccount.create -}} + {{ default "clickhouse-serviceaccount" .Values.clickhouse.serviceAccount.name }} +{{- end -}} +{{- end -}} + {{- define "posthog.helmOperation" -}} {{- if .Release.IsUpgrade -}} upgrade diff --git a/charts/posthog/templates/clickhouse-serviceaccount.yaml b/charts/posthog/templates/clickhouse-serviceaccount.yaml new file mode 100644 index 000000000..5c79df920 --- /dev/null +++ b/charts/posthog/templates/clickhouse-serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.clickhouse.enabled }} +{{- if .Values.clickhouse.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ template "posthog.clickhouse.serviceAccount" . }} + labels: {{- include "_snippet-metadata-labels-common" . | nindent 4 }} + {{- if .Values.clickhouse.serviceAccount.annotations }} + annotations: {{ toYaml .Values.clickhouse.serviceAccount.annotations | nindent 4 }} + {{- end }} +{{- end -}} +{{- end -}} diff --git a/charts/posthog/templates/clickhouse_instance.yaml b/charts/posthog/templates/clickhouse_instance.yaml index f39529ac4..de4aa6803 100644 --- a/charts/posthog/templates/clickhouse_instance.yaml +++ b/charts/posthog/templates/clickhouse_instance.yaml @@ -71,6 +71,11 @@ spec: podDistribution: {{ toYaml .Values.clickhouse.podDistribution | nindent 12 }} {{- end}} spec: + {{- if .Values.clickhouse.serviceAccountName }} + serviceAccountName: {{ toYaml .Values.clickhouse.serviceAccountName | nindent 12 }} + {{- else if .Values.clickhouse.serviceAccount.create }} + serviceAccountName: {{ template "posthog.clickhouse.serviceAccount" . }} + {{- end }} {{- if .Values.clickhouse.affinity }} affinity: {{ toYaml .Values.clickhouse.affinity | nindent 12 }} {{- end }} diff --git a/charts/posthog/values.yaml b/charts/posthog/values.yaml index f9cd686b0..628ce0148 100644 --- a/charts/posthog/values.yaml +++ b/charts/posthog/values.yaml @@ -1732,8 +1732,21 @@ clickhouse: ## pullSecrets: [] + serviceAccount: + # -- Alternative serviceAccount for clickhouse pod to use + # @default autogenerated by posthog.serviceAccount + # -- serviceAccount should be created - boolean + create: false + # -- name of the serviceAccount + name: + # -- Configures annotation for the serviceAccount + annotations: {} + # -- Toleration labels for clickhouse pod assignment tolerations: [] + # -- Override serviceAccountName for clickhouse pod + # Note: this will override serviceAccount.name if both are set + serviceAccountName: "" # -- Affinity settings for clickhouse pod affinity: {} # -- Clickhouse resource requests/limits. See more at http://kubernetes.io/docs/user-guide/compute-resources/