Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions charts/portkey-gateway/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -360,21 +360,28 @@ Common Environment Env as Map
{{/*
mcp.serverMode
→ Returns string
Reads SERVER_MODE from the K8s Secret via lookup when vault injection
or existingSecret is used. Falls back to environment.data if the secret
is not yet available.
*/}}
{{- define "mcp.serverMode" -}}
{{- $env := (include "portkeyenterprise.commonEnvMap" . | fromYaml) -}}
{{- $serverMode := "" -}}
{{- if hasKey $env "SERVER_MODE" -}}
{{- $entry := index $env "SERVER_MODE" -}}
{{- if hasKey $entry "value" -}}
{{- $serverMode = (index $entry "value") | toString -}}
{{- else -}}
{{- $serverMode = (index .Values.environment.data "SERVER_MODE") | default "" | toString -}}
{{- if .Values.useVaultInjection -}}
{{- $secretName := .Values.vaultConfig.kubernetesSecret | default .Chart.Name -}}
{{- $secret := lookup "v1" "Secret" .Release.Namespace $secretName -}}
{{- if and $secret $secret.data (hasKey $secret.data "SERVER_MODE") -}}
{{- $serverMode = index $secret.data "SERVER_MODE" | b64dec | toString | trim -}}
{{- end -}}
{{- else -}}
{{- $serverMode = (index .Values.environment.data "SERVER_MODE") | default "" | toString -}}
{{- else if and (not .Values.environment.create) .Values.environment.existingSecret -}}
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existingSecret branch (line 375) uses a stricter condition — and (not .Values.environment.create) .Values.environment.existingSecret — compared to the existing portkeyenterprise.commonEnvMap function which uses simply else if .Values.environment.existingSecret (line 256). While the resulting behavior is functionally equivalent for SERVER_MODE (since when create=true, the chart-managed secret's value equals environment.data["SERVER_MODE"]), the inconsistency could cause confusion during maintenance. More importantly, this means when someone sets environment.create: true as an override (i.e., the default) together with useVaultInjection: false, the lookup of the chart-managed secret is skipped entirely. Since that managed secret's SERVER_MODE value is sourced directly from environment.data["SERVER_MODE"], the fallback is semantically correct — but the approach is asymmetric with how other functions handle the same conditions. Consider simplifying the condition to just else if .Values.environment.existingSecret (removing the not .Values.environment.create guard) to be consistent with the rest of the helpers.

Suggested change
{{- else if and (not .Values.environment.create) .Values.environment.existingSecret -}}
{{- else if .Values.environment.existingSecret -}}

Copilot uses AI. Check for mistakes.
{{- $secret := lookup "v1" "Secret" .Release.Namespace .Values.environment.existingSecret -}}
{{- if and $secret $secret.data (hasKey $secret.data "SERVER_MODE") -}}
{{- $serverMode = index $secret.data "SERVER_MODE" | b64dec | toString | trim -}}
{{- end -}}
{{- end -}}
{{- if eq $serverMode "" -}}
{{- $serverMode = (index .Values.environment.data "SERVER_MODE") | default "" | toString | trim -}}
{{- end -}}
{{- $serverMode | trim | toString -}}
{{- $serverMode -}}
{{- end -}}

{{/*
Expand Down