diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl index 0e5c91e..0aee59a 100644 --- a/templates/_helpers.tpl +++ b/templates/_helpers.tpl @@ -72,3 +72,49 @@ Define the name of the secret to use {{- template "plausible-analytics.fullname" . -}} {{- end -}} {{- end -}} + +{{/* +Generate the PostgreSQL service name +*/}} +{{- define "plausible-analytics.postgresql.serviceName" -}} +{{- if .Values.postgresql.enabled -}} +{{- printf "%s-postgresql" (include "plausible-analytics.fullname" .) -}} +{{- else -}} +{{- required "A PostgreSQL service name is required when postgresql.enabled is false" .Values.postgresql.externalServiceName -}} +{{- end -}} +{{- end -}} + +{{/* +Generate the ClickHouse service name +*/}} +{{- define "plausible-analytics.clickhouse.serviceName" -}} +{{- if .Values.clickhouse.enabled -}} +{{- printf "%s-clickhouse" (include "plausible-analytics.fullname" .) -}} +{{- else -}} +{{- required "A ClickHouse service name is required when clickhouse.enabled is false" .Values.clickhouse.externalServiceName -}} +{{- end -}} +{{- end -}} + +{{/* +Generate the default PostgreSQL database URL +*/}} +{{- define "plausible-analytics.postgresql.defaultURL" -}} +{{- $serviceName := include "plausible-analytics.postgresql.serviceName" . -}} +{{- $username := .Values.postgresql.auth.username | default "postgres" -}} +{{- $password := .Values.postgresql.auth.password | default "postgres" -}} +{{- $database := .Values.postgresql.auth.database | default "plausible_db" -}} +{{- $port := .Values.postgresql.port | default 5432 -}} +{{- printf "postgres://%s:%s@%s:%v/%s" $username $password $serviceName $port $database -}} +{{- end -}} + +{{/* +Generate the default ClickHouse database URL +*/}} +{{- define "plausible-analytics.clickhouse.defaultURL" -}} +{{- $serviceName := include "plausible-analytics.clickhouse.serviceName" . -}} +{{- $username := .Values.clickhouse.auth.username | default "clickhouse" -}} +{{- $password := .Values.clickhouse.auth.password | default "password" -}} +{{- $database := .Values.clickhouse.auth.database | default "plausible_events_db" -}} +{{- $port := 8123 -}} +{{- printf "http://%s:%s@%s:%v/%s" $username $password $serviceName $port $database -}} +{{- end -}} diff --git a/templates/secret.yaml b/templates/secret.yaml index a3ee356..33b386e 100644 --- a/templates/secret.yaml +++ b/templates/secret.yaml @@ -16,9 +16,13 @@ data: TOTP_VAULT_KEY: {{ .Values.totpVaultKey | toString | b64enc }} {{- if .Values.databaseURL }} DATABASE_URL: {{ .Values.databaseURL | toString | b64enc }} + {{- else }} + DATABASE_URL: {{ include "plausible-analytics.postgresql.defaultURL" . | toString | b64enc }} {{- end }} {{- if .Values.clickhouseDatabaseURL }} CLICKHOUSE_DATABASE_URL: {{ .Values.clickhouseDatabaseURL | toString | b64enc }} + {{- else }} + CLICKHOUSE_DATABASE_URL: {{ include "plausible-analytics.clickhouse.defaultURL" . | toString | b64enc }} {{- end }} {{- if .Values.mailer.enabled }} {{- if eq .Values.mailer.adapter "Bamboo.Mua" }} diff --git a/values.yaml b/values.yaml index 6abbb01..fea8e7a 100644 --- a/values.yaml +++ b/values.yaml @@ -19,12 +19,14 @@ logFailedLoginAttempts: false # Controls whether to log warnings about failed l ## Plausible require a Postgres and Clickhouse database ### The URL to the Postgres Database Connection String see -> https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING -databaseURL: "postgres://postgres:postgres@plausible-analytics-postgresql:5432/plausible_db" +### If left empty, it will be automatically generated using the chart's PostgreSQL configuration +databaseURL: "" ### CA certificate for the database connection in PEM format. If not provided, the database connection will not use SSL. databaseCA: null ### The URL Connection String to clickhouse DB see -> https://clickhouse.tech/docs/en/interfaces/http/ -clickhouseDatabaseURL: "http://clickhouse:password@plausible-analytics-clickhouse:8123/plausible_events_db" +### If left empty, it will be automatically generated using the chart's ClickHouse configuration +clickhouseDatabaseURL: "" clickhouseFlushIntervalMS: "" clickhouseMaxBufferSize: "" @@ -103,6 +105,8 @@ postgresql: ## If true, install the Postgresql chart ## ref: https://github.com/bitnami/charts/tree/main/bitnami/postgresql enabled: true + ## External PostgreSQL service name (used when postgresql.enabled is false) + # externalServiceName: "my-external-postgresql" global: security: allowInsecureImages: true @@ -135,6 +139,8 @@ clickhouse: ## If true, install the Clickhouse chart ## ref: https://github.com/bitnami/charts/tree/main/bitnami/clickhouse enabled: true + ## External ClickHouse service name (used when clickhouse.enabled is false) + # externalServiceName: "my-external-clickhouse" global: security: allowInsecureImages: true