Skip to content

Commit

Permalink
Merge pull request #164 from langchain-ai/brian/ls-2216-prevent-dupli…
Browse files Browse the repository at this point in the history
…cate-env-vars

feat: prevent duplicate env var keys
  • Loading branch information
bvs-langchain authored Oct 28, 2024
2 parents f894a51 + ef0030f commit a4ef7ae
Show file tree
Hide file tree
Showing 14 changed files with 172 additions and 119 deletions.
2 changes: 1 addition & 1 deletion charts/langsmith/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ maintainers:
email: [email protected]
description: Helm chart to deploy the langsmith application and all services it depends on.
type: application
version: 0.7.10
version: 0.7.11
appVersion: "0.7.45"
2 changes: 1 addition & 1 deletion charts/langsmith/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# langsmith

![Version: 0.7.10](https://img.shields.io/badge/Version-0.7.10-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.7.45](https://img.shields.io/badge/AppVersion-0.7.45-informational?style=flat-square)
![Version: 0.7.11](https://img.shields.io/badge/Version-0.7.11-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.7.45](https://img.shields.io/badge/AppVersion-0.7.45-informational?style=flat-square)

Helm chart to deploy the langsmith application and all services it depends on.

Expand Down
56 changes: 51 additions & 5 deletions charts/langsmith/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,32 @@ the user or some other secret provisioning mechanism
{{- end }}
{{- end }}

{{/* Include these env vars if they aren't defined in .Values.commonEnv */}}
{{- define "langsmith.conditionalEnvVars" -}}
- name: X_SERVICE_AUTH_JWT_SECRET
valueFrom:
secretKeyRef:
name: {{ include "langsmith.secretsName" . }}
key: api_key_salt
{{- end }}
{{- define "langsmith.conditionalEnvVarsResolved" -}}
{{- $commonEnvKeys := list -}}
{{- range $i, $commonEnvVar := .Values.commonEnv -}}
{{- $commonEnvKeys = append $commonEnvKeys $commonEnvVar.name -}}
{{- end -}}
{{- $resolvedEnvVars := list -}}
{{- range $i, $envVar := include "langsmith.conditionalEnvVars" . | fromYamlArray }}
{{- if not (has $envVar.name $commonEnvKeys) }}
{{- $resolvedEnvVars = append $resolvedEnvVars $envVar -}}
{{- end }}
{{- end }}
{{- if gt (len $resolvedEnvVars) 0 -}}
{{ $resolvedEnvVars | toYaml }}
{{- end -}}
{{- end }}
{{/*
Template containing common environment variables that are used by several services.
Expand Down Expand Up @@ -227,11 +253,6 @@ Template containing common environment variables that are used by several servic
value: http://{{- include "langsmith.fullname" . }}-{{.Values.platformBackend.name}}:{{ .Values.platformBackend.service.port }}
- name: SMITH_BACKEND_ENDPOINT
value: http://{{- include "langsmith.fullname" . }}-{{.Values.backend.name}}:{{ .Values.backend.service.port }}
- name: X_SERVICE_AUTH_JWT_SECRET
valueFrom:
secretKeyRef:
name: {{ include "langsmith.secretsName" . }}
key: api_key_salt
{{- if .Values.config.ttl.enabled }}
- name: FF_TRACE_TIERS_ENABLED
value: {{ .Values.config.ttl.enabled | quote }}
Expand Down Expand Up @@ -268,6 +289,7 @@ Template containing common environment variables that are used by several servic
{{- end }}
- name: FF_CH_SEARCH_ENABLED
value: {{ .Values.config.blobStorage.chSearchEnabled | quote }}
{{ include "langsmith.conditionalEnvVarsResolved" . }}
{{- end }}
{{- define "backend.serviceAccountName" -}}
Expand Down Expand Up @@ -333,3 +355,27 @@ Template containing common environment variables that are used by several servic
{{ default "default" .Values.redis.serviceAccount.name }}
{{- end -}}
{{- end -}}
{{/* Fail on duplicate keys in the inputted list of environment variables */}}
{{- define "langsmith.detectDuplicates" -}}
{{- $inputList := . -}}
{{- $keyCounts := dict -}}
{{- $duplicates := list -}}
{{- range $i, $val := $inputList }}
{{- $key := $val.name -}}
{{- if hasKey $keyCounts $key }}
{{- $_ := set $keyCounts $key (add (get $keyCounts $key) 1) -}}
{{- else }}
{{- $_ := set $keyCounts $key 1 -}}
{{- end }}
{{- if gt (get $keyCounts $key) 1 }}
{{- $duplicates = append $duplicates $key -}}
{{- end }}
{{- end }}
{{- if gt (len $duplicates) 0 }}
{{ fail (printf "Duplicate keys detected: %v" $duplicates) }}
{{- end }}
{{- end -}}
21 changes: 12 additions & 9 deletions charts/langsmith/templates/backend/auth-bootstrap.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
{{- define "authBootstrapEnvVars" -}}
- name: INITIAL_ORG_ADMIN_EMAIL
value: {{ .Values.config.basicAuth.initialOrgAdminEmail }}
- name: INITIAL_ORG_ADMIN_PASSWORD
valueFrom:
secretKeyRef:
name: {{ include "langsmith.secretsName" . }}
key: initial_org_admin_password
{{- end -}}
{{- if .Values.config.basicAuth.enabled }}
{{- $envVars := concat (include "langsmith.commonEnv" . | fromYamlArray) (include "authBootstrapEnvVars" . | fromYamlArray) .Values.backend.authBootstrap.extraEnv -}}
{{- include "langsmith.detectDuplicates" $envVars -}}
apiVersion: batch/v1
kind: Job
metadata:
Expand Down Expand Up @@ -47,15 +58,7 @@ spec:
{{- toYaml . | nindent 12 }}
{{- end }}
env:
{{- include "langsmith.commonEnv" . | nindent 12 }}
- name: INITIAL_ORG_ADMIN_EMAIL
value: {{ .Values.config.basicAuth.initialOrgAdminEmail }}
- name: INITIAL_ORG_ADMIN_PASSWORD
valueFrom:
secretKeyRef:
name: {{ include "langsmith.secretsName" . }}
key: initial_org_admin_password
{{- with .Values.backend.authBootstrap.extraEnv }}
{{- with $envVars }}
{{- toYaml . | nindent 12 }}
{{- end }}
envFrom:
Expand Down
5 changes: 3 additions & 2 deletions charts/langsmith/templates/backend/clickhouse-migrations.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{{- if .Values.backend.clickhouseMigrations.enabled }}
{{- $envVars := concat (include "langsmith.commonEnv" . | fromYamlArray) .Values.backend.clickhouseMigrations.extraEnv -}}
{{- include "langsmith.detectDuplicates" $envVars -}}
apiVersion: batch/v1
kind: Job
metadata:
Expand Down Expand Up @@ -47,8 +49,7 @@ spec:
{{- toYaml . | nindent 12 }}
{{- end }}
env:
{{- include "langsmith.commonEnv" . | nindent 12 }}
{{- with .Values.backend.clickhouseMigrations.extraEnv }}
{{- with $envVars }}
{{- toYaml . | nindent 12 }}
{{- end }}
envFrom:
Expand Down
22 changes: 11 additions & 11 deletions charts/langsmith/templates/backend/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
{{- define "backendEnvVars" -}}
- name: PORT
value: {{ .Values.backend.containerPort | quote }}
{{- with .Values.ingress.subdomain }}
- name: DOCS_PREFIX
value: /{{ . }}/api
{{- end }}
{{- end -}}
{{- $envVars := concat .Values.commonEnv (include "langsmith.commonEnv" . | fromYamlArray) (include "backendEnvVars" . | fromYamlArray) .Values.backend.deployment.extraEnv -}}
{{- include "langsmith.detectDuplicates" $envVars -}}
apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down Expand Up @@ -50,19 +60,9 @@ spec:
{{- toYaml . | nindent 12 }}
{{- end }}
env:
{{- include "langsmith.commonEnv" . | nindent 12 }}
- name: PORT
value: {{ .Values.backend.containerPort | quote }}
{{- with .Values.ingress.subdomain }}
- name: DOCS_PREFIX
value: /{{ . }}/api
{{- end }}
{{- with .Values.backend.deployment.extraEnv }}
{{- with $envVars }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.commonEnv }}
{{ toYaml . | nindent 12 }}
{{- end }}
envFrom:
- configMapRef:
name: {{ include "langsmith.fullname" . }}-config
Expand Down
5 changes: 3 additions & 2 deletions charts/langsmith/templates/backend/postgres-migrations.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{{- if .Values.backend.migrations.enabled }}
{{- $envVars := concat (include "langsmith.commonEnv" . | fromYamlArray) .Values.backend.migrations.extraEnv -}}
{{- include "langsmith.detectDuplicates" $envVars -}}
apiVersion: batch/v1
kind: Job
metadata:
Expand Down Expand Up @@ -47,8 +49,7 @@ spec:
{{- toYaml . | nindent 12 }}
{{- end }}
env:
{{- include "langsmith.commonEnv" . | nindent 12 }}
{{- with .Values.backend.migrations.extraEnv }}
{{- with $envVars }}
{{- toYaml . | nindent 12 }}
{{- end }}
envFrom:
Expand Down
41 changes: 21 additions & 20 deletions charts/langsmith/templates/clickhouse/stateful-set.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
{{- define "clickhouseEnvVars" -}}
- name: CLICKHOUSE_DB
valueFrom:
secretKeyRef:
name: {{ include "langsmith.clickhouseSecretsName" . }}
key: clickhouse_db
- name: CLICKHOUSE_USER
valueFrom:
secretKeyRef:
name: {{ include "langsmith.clickhouseSecretsName" . }}
key: clickhouse_user
- name: CLICKHOUSE_PASSWORD
valueFrom:
secretKeyRef:
name: {{ include "langsmith.clickhouseSecretsName" . }}
key: clickhouse_password
{{- end -}}
{{- if not .Values.clickhouse.external.enabled }}
{{- $envVars := concat .Values.commonEnv (include "clickhouseEnvVars" . | fromYamlArray) .Values.clickhouse.statefulSet.extraEnv -}}
{{- include "langsmith.detectDuplicates" $envVars -}}
apiVersion: apps/v1
kind: StatefulSet
metadata:
Expand Down Expand Up @@ -49,26 +68,8 @@ spec:
{{- toYaml . | nindent 12 }}
{{- end }}
env:
- name: CLICKHOUSE_DB
valueFrom:
secretKeyRef:
name: {{ include "langsmith.clickhouseSecretsName" . }}
key: clickhouse_db
- name: CLICKHOUSE_USER
valueFrom:
secretKeyRef:
name: {{ include "langsmith.clickhouseSecretsName" . }}
key: clickhouse_user
- name: CLICKHOUSE_PASSWORD
valueFrom:
secretKeyRef:
name: {{ include "langsmith.clickhouseSecretsName" . }}
key: clickhouse_password
{{- with .Values.clickhouse.statefulSet.extraEnv }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.commonEnv }}
{{ toYaml . | nindent 12 }}
{{- with $envVars }}
{{- toYaml . | nindent 12 }}
{{- end }}
ports:
- name: ch
Expand Down
41 changes: 21 additions & 20 deletions charts/langsmith/templates/frontend/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
{{- define "frontendEnvVars" -}}
{{- if .Values.config.oauth.enabled }}
- name: VITE_OAUTH_CLIENT_ID
valueFrom:
secretKeyRef:
key: oauth_client_id
name: {{ include "langsmith.secretsName" .}}
- name: VITE_OAUTH_ISSUER_URL
valueFrom:
secretKeyRef:
key: oauth_issuer_url
name: {{ include "langsmith.secretsName" .}}
{{- end }}
{{- if .Values.ingress.subdomain }}
- name: VITE_SUBDOMAIN
value: {{ .Values.ingress.subdomain }}
{{- end }}
{{- end -}}
{{- $envVars := concat .Values.commonEnv (include "frontendEnvVars" . | fromYamlArray) .Values.frontend.deployment.extraEnv -}}
{{- include "langsmith.detectDuplicates" $envVars -}}
apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down Expand Up @@ -50,26 +70,7 @@ spec:
{{- toYaml . | nindent 12 }}
{{- end }}
env:
{{- if .Values.config.oauth.enabled }}
- name: VITE_OAUTH_CLIENT_ID
valueFrom:
secretKeyRef:
key: oauth_client_id
name: {{ include "langsmith.secretsName" .}}
- name: VITE_OAUTH_ISSUER_URL
valueFrom:
secretKeyRef:
key: oauth_issuer_url
name: {{ include "langsmith.secretsName" .}}
{{- end }}
{{- with .Values.frontend.deployment.extraEnv }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- if .Values.ingress.subdomain }}
- name: VITE_SUBDOMAIN
value: {{ .Values.ingress.subdomain }}
{{- end }}
{{- with .Values.commonEnv }}
{{- with $envVars }}
{{ toYaml . | nindent 12 }}
{{- end }}
envFrom:
Expand Down
18 changes: 11 additions & 7 deletions charts/langsmith/templates/platform-backend/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
{{- define "platformBackendEnvVars" -}}
- name: PORT
value: {{ .Values.platformBackend.containerPort | quote }}
{{- with .Values.ingress.subdomain }}
- name: DOCS_PREFIX
value: /{{ . }}/api
{{- end }}
{{- end -}}
{{- $envVars := concat .Values.commonEnv (include "langsmith.commonEnv" . | fromYamlArray) (include "platformBackendEnvVars" . | fromYamlArray) .Values.platformBackend.deployment.extraEnv -}}
{{- include "langsmith.detectDuplicates" $envVars -}}
apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down Expand Up @@ -50,13 +60,7 @@ spec:
{{- toYaml . | nindent 12 }}
{{- end }}
env:
{{- include "langsmith.commonEnv" . | nindent 12 }}
- name: PORT
value: {{ .Values.platformBackend.containerPort | quote }}
{{- with .Values.platformBackend.deployment.extraEnv }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.commonEnv }}
{{- with $envVars }}
{{ toYaml . | nindent 12 }}
{{- end }}
envFrom:
Expand Down
10 changes: 3 additions & 7 deletions charts/langsmith/templates/playground/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{{- $envVars := concat .Values.commonEnv .Values.playground.deployment.extraEnv -}}
{{- include "langsmith.detectDuplicates" $envVars -}}
apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down Expand Up @@ -51,13 +53,7 @@ spec:
{{- end }}
{{- if or .Values.playground.deployment.extraEnv .Values.commonEnv }}
env:
{{- with .Values.playground.deployment.extraEnv}}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.commonEnv}}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- end }}
{{- end }}
image: "{{ .Values.images.playgroundImage.repository }}:{{ .Values.images.playgroundImage.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.images.playgroundImage.pullPolicy }}
ports:
Expand Down
Loading

0 comments on commit a4ef7ae

Please sign in to comment.