Skip to content

Commit 96b4ef9

Browse files
feat(helm): add openai.secretRef support to querydoc sub-chart
Mirrors the existing grafana-mcp pattern: when `openai.secretRef` is set, the chart skips rendering its own Secret and points the Deployment's `envFrom.secretRef.name` at the user-supplied Secret instead. Precedence rules: - `secretRef` set → no chart-owned Secret; Deployment references the external Secret by name - `apiKey` set, no `secretRef` → chart creates the Secret (existing behavior unchanged) - Neither set → no Secret, no secretRef in envFrom (existing behavior) - Both set → `secretRef` wins; no chart-owned Secret This allows operators to manage the OpenAI API key via External Secrets, sealed-secrets, or manual `kubectl create secret` without workarounds such as placeholder values and ArgoCD ignoreDifferences blocks. Added secret_test.yaml covering the four-row precedence table, and extended deployment_test.yaml with envFrom/checksum-annotation cases for each combination. Signed-off-by: TOMOFUMI-KONDO <ugax2kontomo0314@gmail.com>
1 parent f95167b commit 96b4ef9

6 files changed

Lines changed: 102 additions & 4 deletions

File tree

helm/kagent/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ querydoc:
556556
memory: 512Mi
557557
openai:
558558
apiKey: ""
559+
# secretRef: "" # Name of existing Secret containing OPENAI_API_KEY. Takes precedence over apiKey.
559560

560561
# ==============================================================================
561562
# OAUTH2-PROXY CONFIGURATION (Optional)

helm/tools/querydoc/templates/deployment.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ spec:
1414
metadata:
1515
annotations:
1616
checksum/configmap: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
17-
{{- if .Values.openai.apiKey }}
17+
{{- if and .Values.openai.apiKey (not .Values.openai.secretRef) }}
1818
checksum/secret: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}
1919
{{- end }}
2020
labels:
@@ -46,9 +46,9 @@ spec:
4646
envFrom:
4747
- configMapRef:
4848
name: {{ include "querydoc.fullname" . }}
49-
{{- if .Values.openai.apiKey }}
49+
{{- if or .Values.openai.apiKey .Values.openai.secretRef }}
5050
- secretRef:
51-
name: {{ include "querydoc.fullname" . }}
51+
name: {{ .Values.openai.secretRef | default (include "querydoc.fullname" .) | quote }}
5252
{{- end }}
5353
ports:
5454
- name: http

helm/tools/querydoc/templates/secret.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if .Values.openai.apiKey }}
1+
{{- if and .Values.openai.apiKey (not .Values.openai.secretRef) }}
22
apiVersion: v1
33
kind: Secret
44
metadata:

helm/tools/querydoc/tests/deployment_test.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ suite: test querydoc deployment
22
templates:
33
- deployment.yaml
44
- configmap.yaml
5+
- secret.yaml
56
tests:
67
- it: should render deployment with default values
78
template: deployment.yaml
@@ -163,3 +164,57 @@ tests:
163164
value: AI
164165
effect: NoSchedule
165166
operator: Equal
167+
168+
- it: should not include secretRef by default
169+
template: deployment.yaml
170+
asserts:
171+
- equal:
172+
path: spec.template.spec.containers[0].envFrom
173+
value:
174+
- configMapRef:
175+
name: RELEASE-NAME-querydoc
176+
- notExists:
177+
path: spec.template.metadata.annotations.checksum/secret
178+
179+
- it: should reference chart-owned Secret when only openai.apiKey is set
180+
template: deployment.yaml
181+
set:
182+
openai:
183+
apiKey: foo
184+
asserts:
185+
- contains:
186+
path: spec.template.spec.containers[0].envFrom
187+
content:
188+
secretRef:
189+
name: RELEASE-NAME-querydoc
190+
- exists:
191+
path: spec.template.metadata.annotations.checksum/secret
192+
193+
- it: should reference external Secret when openai.secretRef is set
194+
template: deployment.yaml
195+
set:
196+
openai:
197+
secretRef: my-secret
198+
asserts:
199+
- contains:
200+
path: spec.template.spec.containers[0].envFrom
201+
content:
202+
secretRef:
203+
name: my-secret
204+
- notExists:
205+
path: spec.template.metadata.annotations.checksum/secret
206+
207+
- it: secretRef should win over apiKey when both are set
208+
template: deployment.yaml
209+
set:
210+
openai:
211+
apiKey: foo
212+
secretRef: my-secret
213+
asserts:
214+
- contains:
215+
path: spec.template.spec.containers[0].envFrom
216+
content:
217+
secretRef:
218+
name: my-secret
219+
- notExists:
220+
path: spec.template.metadata.annotations.checksum/secret
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
suite: test querydoc secret
2+
templates:
3+
- secret.yaml
4+
tests:
5+
- it: should not render a Secret with default values
6+
asserts:
7+
- hasDocuments:
8+
count: 0
9+
10+
- it: should render a Secret when openai.apiKey is set
11+
set:
12+
openai:
13+
apiKey: foo
14+
asserts:
15+
- hasDocuments:
16+
count: 1
17+
- isKind:
18+
of: Secret
19+
- equal:
20+
path: metadata.name
21+
value: RELEASE-NAME-querydoc
22+
- equal:
23+
path: data.OPENAI_API_KEY
24+
value: Zm9v # `foo` base64 encoded
25+
26+
- it: should not render a Secret when openai.secretRef is set
27+
set:
28+
openai:
29+
secretRef: my-secret
30+
asserts:
31+
- hasDocuments:
32+
count: 0
33+
34+
- it: should not render a Secret when both apiKey and secretRef are set (secretRef wins)
35+
set:
36+
openai:
37+
apiKey: foo
38+
secretRef: my-secret
39+
asserts:
40+
- hasDocuments:
41+
count: 0

helm/tools/querydoc/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ config:
5252
# Secret configuration
5353
openai:
5454
apiKey: ""
55+
# secretRef: "" # Name of existing Secret containing OPENAI_API_KEY. Takes precedence over apiKey.
5556

5657
# OTEL configuration
5758
otel:

0 commit comments

Comments
 (0)