Skip to content

feat(helm): add openai.secretRef support to querydoc sub-chart#1911

Open
TOMOFUMI-KONDO wants to merge 1 commit into
kagent-dev:mainfrom
TOMOFUMI-KONDO:feat/querydoc-secret-ref
Open

feat(helm): add openai.secretRef support to querydoc sub-chart#1911
TOMOFUMI-KONDO wants to merge 1 commit into
kagent-dev:mainfrom
TOMOFUMI-KONDO:feat/querydoc-secret-ref

Conversation

@TOMOFUMI-KONDO
Copy link
Copy Markdown
Contributor

Overview

Add openai.secretRef to the querydoc sub-chart, mirroring the pattern already supported by the grafana-mcp sub-chart. When set, the chart skips rendering its own Secret and instead points the Deployment's envFrom.secretRef.name at the user-supplied Secret.

Changes

Precedence logic for openai.secretRef vs openai.apiKey

apiKey secretRef Result
set unset Chart renders Secret (existing behavior unchanged)
unset set No chart Secret; Deployment references user Secret
set set secretRef wins; no chart Secret
unset unset No Secret, no secretRef in envFrom (existing behavior)

Template changes

  • templates/secret.yaml: guard changed from {{- if .Values.openai.apiKey }} to {{- if and .Values.openai.apiKey (not .Values.openai.secretRef) }}
  • templates/deployment.yaml:
    • envFrom guard widened to {{- if or .Values.openai.apiKey .Values.openai.secretRef }}
    • Secret name resolved via {{ .Values.openai.secretRef | default (include "querydoc.fullname" .) | quote }}
    • checksum/secret annotation tightened to only appear when the chart owns the Secret

Values

openai.secretRef: "" added (commented out) to both helm/tools/querydoc/values.yaml and the parent helm/kagent/values.yaml.

Tests

  • tests/secret_test.yaml (new): covers the four-row precedence table for Secret creation
  • tests/deployment_test.yaml: added secret.yaml to the rendered templates list (needed for include-based checksum), plus four new cases covering envFrom and checksum/secret annotation behavior for each combination

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>
Copilot AI review requested due to automatic review settings May 24, 2026 08:08
@github-actions github-actions Bot added the enhancement New feature or request label May 24, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds support for referencing an existing Kubernetes Secret for the Querydoc OpenAI API key, avoiding chart-managed Secret creation when openai.secretRef is provided.

Changes:

  • Documented openai.secretRef in chart values (Querydoc + kagent umbrella values).
  • Updated Helm templates to (a) not render a Secret when secretRef is set and (b) mount either chart-owned or external Secret into the Deployment.
  • Added helm-unittest coverage for Secret rendering and Deployment envFrom/annotations behavior.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
helm/tools/querydoc/values.yaml Documents openai.secretRef as an alternative to inline apiKey.
helm/tools/querydoc/templates/secret.yaml Only renders chart-owned Secret when apiKey is set and no secretRef is provided.
helm/tools/querydoc/templates/deployment.yaml References external Secret when secretRef is set; only sets checksum/secret for chart-owned Secret.
helm/tools/querydoc/tests/secret_test.yaml Adds tests for Secret rendering precedence rules (secretRef wins).
helm/tools/querydoc/tests/deployment_test.yaml Adds tests for envFrom + checksum/secret behavior with apiKey vs secretRef.
helm/kagent/values.yaml Surfaces querydoc.openai.secretRef in the umbrella chart values.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

templates:
- deployment.yaml
- configmap.yaml
- secret.yaml
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

All of the tests in this file have template: key, and in addition secret.yaml template target is required to test the behavior of include function in the deployment spec.

Comment on lines +17 to 19
{{- if and .Values.openai.apiKey (not .Values.openai.secretRef) }}
checksum/secret: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}
{{- end }}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think that it's outside the scope of this PR.

Comment on lines +49 to 52
{{- if or .Values.openai.apiKey .Values.openai.secretRef }}
- secretRef:
name: {{ include "querydoc.fullname" . }}
name: {{ .Values.openai.secretRef | default (include "querydoc.fullname" .) | quote }}
{{- end }}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think that it's outside the scope of this PR.

@TOMOFUMI-KONDO
Copy link
Copy Markdown
Contributor Author

@EItanya @ilackarms @yuval-k @supreme-gg-gg @iplay88keys @jmhbh
Hello. I'd appreciate it if you could review this PR when you have time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Helm: support openai.secretRef in querydoc sub-chart

2 participants