Skip to content
Open
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion helm/kagent/templates/modelconfig-secret.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{{- if .Values.providers }}
{{- $dot := . }}
{{- $model := index $dot.Values.providers $dot.Values.providers.default }}
{{- $defaultProvider := .Values.providers.default | default "openAI" }}
{{- if hasKey .Values.providers $defaultProvider }}
{{- $model := index .Values.providers $defaultProvider }}
{{- if and $model.apiKeySecretRef $model.apiKey }}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Won't this line already disable the rendering if these aren't set?

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.

The problem is that if providers.default points to a missing key, index returns nil.
Setting providers: {} value returns when trying to template:

Error: template: kagent/templates/modelconfig-secret.yaml:2:14: executing "kagent/templates/modelconfig-secret.yaml" at <index $dot.Values.providers $dot.Values.providers.default>: error calling index: value is nil; should be of type string

The check is necessary to prevent Helm from crashing.

---
apiVersion: v1
Expand All @@ -13,3 +16,5 @@ type: Opaque
data:
{{ $model.apiKeySecretKey | default (printf "%s_API_KEY" $model.provider | upper) }}: {{ $model.apiKey | b64enc }}
{{- end }}
{{- end }}
{{- end }}
4 changes: 3 additions & 1 deletion helm/kagent/templates/modelconfig.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.providers }}
{{- $dot := . }}
{{- $defaultProvider := .Values.providers.default | default "openAI" }}
{{- if hasKey .Values.providers $defaultProvider | not }}
Expand Down Expand Up @@ -31,7 +32,8 @@ spec:
{{- toYaml $model.tls | nindent 4 }}
{{- end }}
{{- if $model.config }}
{{ $dot.Values.providers.default }}:
{{ $defaultProvider }}:
{{- toYaml $model.config | nindent 4 }}
{{- end }}
{{- end }}
{{- end }}
8 changes: 7 additions & 1 deletion helm/kagent/tests/modelconfig-secret_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,10 @@ tests:
asserts:
- equal:
path: metadata.namespace
value: custom-namespace
value: custom-namespace
- it: should not render secret when providers is set to null
set:
providers: null
asserts:
- hasDocuments:
count: 0
7 changes: 7 additions & 0 deletions helm/kagent/tests/modelconfig_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,10 @@ tests:
- equal:
path: metadata.namespace
value: custom-namespace

- it: should not render modelconfig when providers is set to null
set:
providers: null
asserts:
- hasDocuments:
count: 0
Loading