The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(helm): reuse the generated master key Secret on helm upgrade (#39219)
devin-ai-integration[bot]b0041f32a2d7
diff --git a/helm/litellm-helm/README.md b/helm/litellm-helm/README.mdindex b242373de5d..bf4089404db 100644--- a/helm/litellm-helm/README.md+++ b/helm/litellm-helm/README.md@@ -26,7 +26,7 @@ If `db.useStackgresOperator` is used (not yet implemented):| `replicaCount` | The number of LiteLLM Proxy pods to be deployed | `1` || `masterkeySecretName` | The name of the Kubernetes Secret that contains the Master API Key for LiteLLM. If not specified, use the generated secret name. | N/A || `masterkeySecretKey` | The key within the Kubernetes Secret that contains the Master API Key for LiteLLM. If not specified, use `masterkey` as the key. | N/A |-| `masterkey` | The Master API Key for LiteLLM. If not specified, a random key in the `sk-...` format is generated. | N/A |+| `masterkey` | The Master API Key for LiteLLM. If not specified, a random key in the `sk-...` format is generated on first install and reused on upgrades. | N/A || `environmentSecrets` | An optional array of Secret object names. The keys and values in these secrets will be presented to the LiteLLM proxy pod as environment variables. See below for an example Secret object. | `[]` || `environmentConfigMaps` | An optional array of ConfigMap object names. The keys and values in these configmaps will be presented to the LiteLLM proxy pod as environment variables. See below for an example Secret object. | `[]` || `image.repository` | LiteLLM Proxy image repository | `ghcr.io/berriai/litellm` |@@ -212,6 +212,8 @@ service, the **Proxy Endpoint** should be set to `http://<RELEASE>-litellm:4000`The **Proxy Key** is the value specified for `masterkey` or, if a `masterkey`was not provided to the helm command line, the `masterkey` is a randomlygenerated string in the `sk-...` format stored in the `<RELEASE>-litellm-masterkey` Kubernetes Secret.+The key is generated once on the first install; later `helm upgrade` runs reuse the+value already in that Secret, so upgrading never rotates the master key.```bashkubectl -n litellm get secret <RELEASE>-litellm-masterkey -o jsonpath="{.data.masterkey}"diff --git a/helm/litellm-helm/templates/secret-masterkey.yaml b/helm/litellm-helm/templates/secret-masterkey.yamlindex 7c8560cc2cc..60ab4e74c6b 100644--- a/helm/litellm-helm/templates/secret-masterkey.yaml+++ b/helm/litellm-helm/templates/secret-masterkey.yaml@@ -1,9 +1,11 @@{{- if not .Values.masterkeySecretName }}-{{ $masterkey := (.Values.masterkey | default (printf "sk-%s" (randAlphaNum 18))) }}+{{- $secretName := printf "%s-masterkey" (include "litellm.fullname" .) }}+{{- $existing := lookup "v1" "Secret" .Release.Namespace $secretName }}+{{- $masterkey := .Values.masterkey | default (dig "data" "masterkey" "" $existing | b64dec) | default (printf "sk-%s" (randAlphaNum 18)) }}apiVersion: v1kind: Secretmetadata:- name: {{ include "litellm.fullname" . }}-masterkey+ name: {{ $secretName }}data:masterkey: {{ $masterkey | b64enc }}type: Opaquediff --git a/helm/litellm-helm/tests/masterkey-secret_tests.yaml b/helm/litellm-helm/tests/masterkey-secret_tests.yamlindex bbbade9d802..296f26755b8 100644--- a/helm/litellm-helm/tests/masterkey-secret_tests.yaml+++ b/helm/litellm-helm/tests/masterkey-secret_tests.yaml@@ -15,6 +15,53 @@ tests:# Note: The masterkey is generated as "sk-<18-random-chars>" in plain text,# but stored as base64 encoded in Kubernetes secret (requirement).# "sk-" base64 encodes to "c2st", so we check for "^c2st" pattern.+ - it: should reuse the master key already stored in the cluster instead of generating a new one on upgrade+ template: secret-masterkey.yaml+ set:+ masterkeySecretName: ""+ kubernetesProvider:+ scheme:+ "v1/Secret":+ gvr:+ version: "v1"+ resource: "secrets"+ namespaced: true+ objects:+ - kind: Secret+ apiVersion: v1+ metadata:+ name: RELEASE-NAME-litellm-masterkey+ namespace: NAMESPACE+ data:+ masterkey: c2stZXhpc3Rpbmcta2V5+ asserts:+ - equal:+ path: data.masterkey+ value: c2stZXhpc3Rpbmcta2V5+ - it: should let an explicit masterkey value override the one already stored in the cluster+ template: secret-masterkey.yaml+ set:+ masterkeySecretName: ""+ masterkey: sk-explicit+ kubernetesProvider:+ scheme:+ "v1/Secret":+ gvr:+ version: "v1"+ resource: "secrets"+ namespaced: true+ objects:+ - kind: Secret+ apiVersion: v1+ metadata:+ name: RELEASE-NAME-litellm-masterkey+ namespace: NAMESPACE+ data:+ masterkey: c2stZXhpc3Rpbmcta2V5+ asserts:+ - equal:+ path: data.masterkey+ value: c2stZXhwbGljaXQ=- it: should not create a secret if masterkeySecretName is settemplate: secret-masterkey.yamlset: