Skip to content

Commit 13fb436

Browse files
fix(helm): support omitting image.registry in querydoc chart (kagent-dev#2124)
## What Make the querydoc (doc2vec) chart render a valid image reference when `image.registry` is left empty, so the registry can be omitted (e.g. to pull from Docker Hub or a mirror) without producing a leading-slash, unpullable reference. ## Why The image is built inline in `templates/deployment.yaml`: ```gotemplate image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" ``` The `/` between registry and repository is written unconditionally. If `image.registry` is set to `""`, the result has a leading slash and is not a valid image reference, so the pod enters `ImagePullBackOff`: ``` /kagent-dev/doc2vec/mcp:1.1.10 # invalid reference ``` There is currently no way to omit the registry and let the container runtime resolve the repository against its default registry / a configured mirror. Omitting the registry is a configuration users legitimately need: - **Docker Hub.** A bare `org/image` reference resolves to Docker Hub, so users mirroring the image there want `kagent-dev/doc2vec/mcp:tag`, not `ghcr.io/...`. - **Air-gapped / mirrored environments.** Registry mirrors are configured at the container runtime, which rewrites the host — so chart values should carry only `repository:tag`. - **Registry rewriting.** Admission controllers (e.g. Kyverno) prepend an internal registry, so users leave `registry: ""`. - **Consistency.** Other charts let you omit the registry; querydoc silently breaks with `ImagePullBackOff`, which reads like a bug. > Note: this is a different issue from the bundled-PostgreSQL `registry//name:tag` > double-slash bug (kagent-dev#2120). That helper uses a 3-segment `registry/repository/name:tag` > shape; querydoc uses a 2-segment `registry/repository:tag` shape with no separate > image name, so the failure here is a leading slash from an empty registry, not a > double slash from an empty repository. They are fixed independently. ## Fix Introduce a `querydoc.image` helper (the chart currently has none) that builds the path from non-empty segments via `compact` + `join`, and call it from the deployment: ```gotemplate {{- define "querydoc.image" -}} {{- $img := .Values.image -}} {{- $parts := compact (list $img.registry $img.repository) -}} {{- printf "%s:%s" (join "/" $parts) ($img.tag | default .Chart.AppVersion) -}} {{- end -}} ``` ```gotemplate # templates/deployment.yaml image: "{{ include "querydoc.image" . }}" ``` Rendered results: | registry | repository | tag | result | |---|---|---|---| | `ghcr.io` | `kagent-dev/doc2vec/mcp` | `1.1.10` | `ghcr.io/kagent-dev/doc2vec/mcp:1.1.10` (unchanged) | | `ghcr.io` | `kagent-dev/doc2vec/mcp` | `v2.0.0` | `ghcr.io/kagent-dev/doc2vec/mcp:v2.0.0` (unchanged) | | `""` | `kagent-dev/doc2vec/mcp` | `1.1.10` | `kagent-dev/doc2vec/mcp:1.1.10` (fixed) | ## Tests Added one case to `helm/tools/querydoc/tests/deployment_test.yaml` for the empty-registry path (developed test-first). The existing "should have correct container image" and "should use custom image tag when set" tests already guard the default and custom-tag paths, so no regression test was duplicated. ```yaml - it: should omit empty registry segment in image template: deployment.yaml set: image: registry: "" asserts: - equal: path: spec.template.spec.containers[0].image value: kagent-dev/doc2vec/mcp:1.1.10 - notMatchRegex: path: spec.template.spec.containers[0].image pattern: "^/" ``` The test fails without this change (`/kagent-dev/doc2vec/mcp:1.1.10`) and passes with it — revert the `deployment.yaml`/`_helpers.tpl` hunks to reproduce. ## How to verify ```bash make helm-tools # generate querydoc Chart.yaml helm unittest helm/tools/querydoc # full suite green (incl. new case) helm lint helm/tools/querydoc # test-independent reproduction: helm template t helm/tools/querydoc --set image.registry="" | grep image: # before: /kagent-dev/doc2vec/mcp:1.1.10 # after: kagent-dev/doc2vec/mcp:1.1.10 ``` ## Scope Limited to the querydoc chart's image construction. Empty `repository` is not made valid here, because the repository carries the full image path and there is no separate image-name segment — omitting it leaves no image to pull. This PR only makes `image.registry` optional. ## Checklist - [x] Commit is DCO signed-off (`git commit -s`). - [x] `helm unittest helm/tools/querydoc` green; `helm lint helm/tools/querydoc` clean. - [x] Diff limited to `templates/_helpers.tpl`, `templates/deployment.yaml`, and `tests/deployment_test.yaml` (generated chart files excluded). - [x] Test fails without the fix, passes with it. Signed-off-by: Mike Spinks <mikespinks@gmail.com>
1 parent aee7c8c commit 13fb436

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

helm/tools/querydoc/templates/_helpers.tpl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,12 @@ Create the querydoc server URL
6767
{{- define "querydoc.serverUrl" -}}
6868
{{- printf "http://%s.%s:%d/mcp" (include "querydoc.fullname" .) .Release.Namespace (.Values.service.port | int) }}
6969
{{- end }}
70+
71+
{{/*
72+
Constructs the full image reference from registry/repository/tag for querydoc image
73+
*/}}
74+
{{- define "querydoc.image" -}}
75+
{{- $img := .Values.image -}}
76+
{{- $parts := compact (list $img.registry $img.repository) -}}
77+
{{- printf "%s:%s" (join "/" $parts) ($img.tag | default .Chart.AppVersion) -}}
78+
{{- end }}

helm/tools/querydoc/templates/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ spec:
3939
securityContext:
4040
{{- toYaml . | nindent 12 }}
4141
{{- end }}
42-
image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
42+
image: {{ include "querydoc.image" . }}
4343
imagePullPolicy: {{ .Values.image.pullPolicy | default "IfNotPresent" }}
4444
resources:
4545
{{- toYaml .Values.resources | nindent 12 }}

helm/tools/querydoc/tests/deployment_test.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@ tests:
4747
path: spec.template.spec.containers[0].image
4848
value: ghcr.io/kagent-dev/doc2vec/mcp:v2.0.0
4949

50+
- it: should omit empty registry segment in image
51+
template: deployment.yaml
52+
set:
53+
image:
54+
registry: ""
55+
asserts:
56+
- equal:
57+
path: spec.template.spec.containers[0].image
58+
value: kagent-dev/doc2vec/mcp:1.1.10
59+
- notMatchRegex:
60+
path: spec.template.spec.containers[0].image
61+
pattern: "^/" # no leading slash
62+
5063
- it: should have correct service account name
5164
template: deployment.yaml
5265
asserts:

0 commit comments

Comments
 (0)