From b6f1438d2e81e85c647339127c8ddcf18b4db95c Mon Sep 17 00:00:00 2001 From: Yoshihiko Kato Date: Wed, 10 Jul 2024 10:37:58 +0900 Subject: [PATCH] Add Database ValueFrom --- charts/langfuse/templates/_helpers.tpl | 106 +++++++++++++++++- charts/langfuse/templates/deployment.yaml | 16 +-- .../templates/nextauth-configmap.yaml | 12 ++ .../langfuse/templates/nextauth-secret.yaml | 6 +- .../templates/postgresql-configmap.yaml | 22 ++++ .../langfuse/templates/postgresql-secret.yaml | 3 +- charts/langfuse/templates/salt-secret.yaml | 13 +++ charts/langfuse/values.yaml | 42 ++++++- 8 files changed, 204 insertions(+), 16 deletions(-) create mode 100644 charts/langfuse/templates/nextauth-configmap.yaml create mode 100644 charts/langfuse/templates/postgresql-configmap.yaml create mode 100644 charts/langfuse/templates/salt-secret.yaml diff --git a/charts/langfuse/templates/_helpers.tpl b/charts/langfuse/templates/_helpers.tpl index f839f24..23a6ebe 100644 --- a/charts/langfuse/templates/_helpers.tpl +++ b/charts/langfuse/templates/_helpers.tpl @@ -69,6 +69,20 @@ Create the name of the secret for nextauth {{- printf "%s-nextauth" (include "langfuse.fullname" .) -}} {{- end }} +{{/* +Create the name of the configmap for nextauth +*/}} +{{- define "langfuse.nextauthConfigMapName" -}} +{{- printf "%s-nextauth" (include "langfuse.fullname" .) -}} +{{- end }} + +{{/* +Create the name of the secret for salt +*/}} +{{- define "langfuse.saltSecretName" -}} +{{- printf "%s-salt" (include "langfuse.fullname" .) -}} +{{- end }} + {{/* Create the name of the secret for postgresql if we use an external database */}} @@ -85,4 +99,94 @@ Return PostgreSQL fullname {{- else }} {{- printf "%s-postgresql" (include "langfuse.fullname" .) -}} {{- end }} -{{- end }} \ No newline at end of file +{{- end }} + +{{/* +Create the postgresqlConfigMapName +*/}} +{{- define "langfuse.postgresqlConfigMapName" -}} +{{- printf "%s-postgresql" (include "langfuse.fullname" .) -}} +{{- end }} + +{{/* +Create the valueFrom json for DATABASE_HOST +*/}} +{{- define "langfuse.postgresql.databaseHost.valueFrom" -}} +{{- if .Values.postgresql.deploy -}} +configMapRef: + name: {{ include "langfuse.postgresqlConfigMapName" . }} + key: postgres-database +{{- else if .Values.langfuse.postgresql.databaseHost.valueFrom }} +{{- toYaml .Values.langfuse.postgresql.databaseHost.valueFrom }} +{{- else -}} +configMapRef: + name: {{ include "langfuse.postgresqlConfigMapName" . }} + key: postgres-database +{{- end }} +{{- end }} + +{{/* +Create the valueFrom json for DATABASE_USERNAME +*/}} +{{- define "langfuse.postgresql.auth.username.valueFrom" -}} +{{- if .Values.postgresql.deploy -}} +configMapRef: + name: {{ include "langfuse.postgresqlConfigMapName" . }} + key: postgres-username +{{- else if .Values.langfuse.postgresql.auth.username.valueFrom }} +{{- toYaml .Values.langfuse.postgresql.auth.username.valueFrom }} +{{- else -}} +configMapRef: + name: {{ include "langfuse.postgresqlConfigMapName" . }} + key: postgres-username +{{- end }} +{{- end }} + +{{/* +Create the valueFrom json for DATABASE_PASSWORD +*/}} +{{- define "langfuse.postgresql.auth.password.valueFrom" -}} +{{- if .Values.postgresql.deploy -}} +secretRef: + name: {{ include "langfuse.postgresqlSecretName" . }} + key: postgres-password +{{- else if .Values.langfuse.postgresql.auth.password.valueFrom }} +{{- toYaml .Values.langfuse.postgresql.auth.password.valueFrom }} +{{- else -}} +configMapRef: + name: {{ include "langfuse.postgresqlSecretName" . }} + key: postgres-password +{{- end }} +{{- end }} + +{{/* +Create the valueFrom json for DATABASE_NAME +*/}} +{{- define "langfuse.postgresql.auth.database.valueFrom" -}} +{{- if .Values.postgresql.deploy -}} +configMapRef: + name: {{ include "langfuse.postgresqlConfigMapName" . }} + key: postgres-database +{{- else if .Values.langfuse.postgresql.auth.database.valueFrom }} +{{- toYaml .Values.langfuse.postgresql.auth.database.valueFrom }} +{{- else -}} +configMapRef: + name: {{ include "langfuse.postgresqlConfigMapName" . }} + key: postgres-database +{{- end }} +{{- end }} + + + +{{/* +Create the valueFrom json for SALT +*/}} +{{- define "langfuse.salt.valueFrom" -}} +{{- if .Values.langfuse.salt.valueFrom }} +{{- toYaml .Values.langfuse.salt.valueFrom }} +{{- else -}} +secretRef: + name: {{ include "langfuse.saltSecretName" . }} + key: salt +{{- end }} +{{- end }} diff --git a/charts/langfuse/templates/deployment.yaml b/charts/langfuse/templates/deployment.yaml index a3a1b22..59db04d 100644 --- a/charts/langfuse/templates/deployment.yaml +++ b/charts/langfuse/templates/deployment.yaml @@ -37,16 +37,13 @@ spec: - name: NODE_ENV value: {{ .Values.langfuse.nodeEnv | quote }} - name: DATABASE_USERNAME - value: {{ .Values.postgresql.auth.username | quote }} + valueFrom: {{ include "langfuse.postgresql.auth.username.valueFrom" . | nindent 16 }} - name: DATABASE_PASSWORD - valueFrom: - secretKeyRef: - name: {{ include "langfuse.postgresql.fullname" . }} - key: postgres-password + valueFrom: {{ include "langfuse.postgresql.auth.password.valueFrom" . | nindent 16 }} - name: DATABASE_HOST value: {{ .Values.postgresql.deploy | ternary (include "langfuse.postgresql.fullname" . | quote) (.Values.postgresql.host | quote) }} - name: DATABASE_NAME - value: {{ .Values.postgresql.auth.database | quote }} + valueFrom: {{ include "langfuse.postgresql.auth.database.valueFrom" . | nindent 16 }} {{- if not .Values.postgresql.deploy }} {{- if .Values.postgresql.directUrl }} - name: DIRECT_URL @@ -64,14 +61,17 @@ spec: {{- end }} {{- end }} - name: NEXTAUTH_URL - value: {{ .Values.langfuse.nextauth.url | quote }} + valueFrom: + configMapRef: + name: {{ include "langfuse.postgresqlConfigMapName" . }} + key: nextauth-url - name: NEXTAUTH_SECRET valueFrom: secretKeyRef: name: {{ include "langfuse.nextauthSecretName" . }} key: nextauth-secret - name: SALT - value: {{ .Values.langfuse.salt | quote }} + valueFrom: {{ include "langfuse.salt.valueFrom" . | nindent 16 }} - name: TELEMETRY_ENABLED value: {{ .Values.langfuse.telemetryEnabled | quote }} - name: NEXT_PUBLIC_SIGN_UP_DISABLED diff --git a/charts/langfuse/templates/nextauth-configmap.yaml b/charts/langfuse/templates/nextauth-configmap.yaml new file mode 100644 index 0000000..0a039fb --- /dev/null +++ b/charts/langfuse/templates/nextauth-configmap.yaml @@ -0,0 +1,12 @@ +{{- if (not .Values.langfuse.nextauth.url.valueFrom) }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "langfuse.nextauthConfigMapName" . }} + labels: + {{- include "langfuse.labels" . | nindent 4 }} +data: + {{- if not .Values.langfuse.nextauth.url.valueFrom }} + url: {{ .Values.langfuse.nextauth.url.value | toString | quote }} + {{- end }} +{{- end }} diff --git a/charts/langfuse/templates/nextauth-secret.yaml b/charts/langfuse/templates/nextauth-secret.yaml index fa2953b..9ecbf2c 100644 --- a/charts/langfuse/templates/nextauth-secret.yaml +++ b/charts/langfuse/templates/nextauth-secret.yaml @@ -1,3 +1,4 @@ +{{- if (not .Values.langfuse.nextauth.secret.valueFrom) }} apiVersion: v1 kind: Secret metadata: @@ -6,4 +7,7 @@ metadata: {{- include "langfuse.labels" . | nindent 4 }} type: Opaque data: - nextauth-secret: {{ .Values.langfuse.nextauth.secret | toString | b64enc }} \ No newline at end of file + {{- if not .Values.langfuse.nextauth.secret.valueFrom }} + nextauth-secret: {{ .Values.langfuse.nextauth.secret.value | toString | b64enc }} + {{- end }} +{{- end }} diff --git a/charts/langfuse/templates/postgresql-configmap.yaml b/charts/langfuse/templates/postgresql-configmap.yaml new file mode 100644 index 0000000..12da8ed --- /dev/null +++ b/charts/langfuse/templates/postgresql-configmap.yaml @@ -0,0 +1,22 @@ +{{- if (or (not .Values.langfuse.postgresql.auth.username.valueFrom) (not .Values.langfuse.postgresql.auth.database.valueFrom) (not .Values.langfuse.postgresql.host.valueFrom)) }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "langfuse.postgresqlConfigMapName" . }} + labels: + {{- include "langfuse.labels" . | nindent 4 }} +data: + {{- if not .Values.langfuse.postgresql.auth.username.valueFrom }} + postgres-username: {{ .Values.langfuse.postgresql.auth.username.value | toString | quote }} + {{- end }} + {{- if not .Values.langfuse.postgresql.auth.database.valueFrom }} + postgres-database: {{ .Values.langfuse.postgresql.auth.database.value | toString | quote }} + {{- end }} + {{- if not .Values.langfuse.postgresql.host.valueFrom }} + {{- if .Values.langfuse.postgresql.host }} + postgres-database: {{ .Values.langfuse.postgresql.auth.database.value | toString | quote }} + {{- else }} + postgres-database: "" + {{- end }} + {{- end }} +{{- end }} diff --git a/charts/langfuse/templates/postgresql-secret.yaml b/charts/langfuse/templates/postgresql-secret.yaml index 3494bc1..4b77721 100644 --- a/charts/langfuse/templates/postgresql-secret.yaml +++ b/charts/langfuse/templates/postgresql-secret.yaml @@ -14,4 +14,5 @@ data: {{- if .Values.postgresql.shadowDatabaseUrl }} postgres-shadow-database-url: {{ .Values.postgresql.shadowDatabaseUrl | toString | b64enc | quote }} {{- end }} -{{- end }} \ No newline at end of file + +{{- end }} diff --git a/charts/langfuse/templates/salt-secret.yaml b/charts/langfuse/templates/salt-secret.yaml new file mode 100644 index 0000000..37ded21 --- /dev/null +++ b/charts/langfuse/templates/salt-secret.yaml @@ -0,0 +1,13 @@ +{{- if (not .Values.langfuse.salt.valueFrom) }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "langfuse.saltSecretName" . }} + labels: + {{- include "langfuse.labels" . | nindent 4 }} +type: Opaque +data: + {{- if not .Values.langfuse.salt.valueFrom }} + nextauth-secret: {{ .Values.langfuse.salt.value | toString | b64enc }} + {{- end }} +{{- end }} diff --git a/charts/langfuse/values.yaml b/charts/langfuse/values.yaml index 7bd75fd..263a0be 100644 --- a/charts/langfuse/values.yaml +++ b/charts/langfuse/values.yaml @@ -12,12 +12,44 @@ fullnameOverride: "" langfuse: nodeEnv: production nextauth: - url: http://localhost:3000 - secret: changeme - salt: changeme + url: + value: http://localhost:3000 + valueFrom: {} + secret: + value: changeme + valueFrom: {} + salt: + value: changeme + valueFrom: {} + postgresql: + host: + value: "" + valueFrom: {} + auth: + username: + value: postgres + valueFrom: + configMapRef: + name: langfuse + key: postgres-username + password: + value: postgres + valueFrom: + secretRef: + name: langfuse + key: postgres-password + database: + value: postgres_langfuse + valueFrom: + configMapRef: + name: langfuse + key: postgres-database + directURL: "" + shadowDatabaseUrl: "" telemetryEnabled: True nextPublicSignUpDisabled: False enableExperimentalFeatures: False + additionalEnv: [] serviceAccount: create: true @@ -53,9 +85,9 @@ postgresql: username: postgres password: postgres database: postgres_langfuse - deploy: true + deploy: false architecture: standalone primary: service: ports: - postgresql: 5432 \ No newline at end of file + postgresql: 5432