Skip to content

fix(helm): support omitting image.registry in grafana-mcp chart#2125

Merged
EItanya merged 1 commit into
kagent-dev:mainfrom
michaelspinks:fix/grafana-mcp-image-empty-registry
Jul 1, 2026
Merged

fix(helm): support omitting image.registry in grafana-mcp chart#2125
EItanya merged 1 commit into
kagent-dev:mainfrom
michaelspinks:fix/grafana-mcp-image-empty-registry

Conversation

@michaelspinks

Copy link
Copy Markdown
Contributor

What

Make the grafana-mcp chart render a valid image reference when image.registry is left empty, so the registry can be omitted (e.g. to pull from a mirror or let the runtime resolve the default registry) without producing a leading-slash, unpullable reference.

Why

The image is built inline in templates/deployment.yaml:

image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag }}"

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:

/grafana:latest     # 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:

  • 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; grafana-mcp silently breaks with ImagePullBackOff, which reads like a bug.

Note: the default registry: mcp is intentional and unchanged — mcp/grafana resolves to docker.io/mcp/grafana (Docker Hub's mcp namespace). This PR only makes an empty registry valid; the default path still renders mcp/grafana:latest.
This is the same 2-segment registry/repository:tag leading-slash shape as the querydoc chart (#2124), and distinct from the bundled-PostgreSQL registry//name:tag double-slash bug (#2120), which uses a 3-segment shape. All fixed independently.

Fix

Introduce a grafana-mcp.image helper (the chart currently has none) that builds the path from non-empty segments via compact + join, and call it from the deployment:

{{- define "grafana-mcp.image" -}}
{{- $img := .Values.image -}}
{{- $parts := compact (list $img.registry $img.repository) -}}
{{- printf "%s:%s" (join "/" $parts) $img.tag -}}
{{- end -}}
# templates/deployment.yaml
image: "{{ include "grafana-mcp.image" . }}"

Rendered results:

registry repository tag result
mcp grafana latest mcp/grafana:latest (unchanged)
"" grafana latest grafana:latest (fixed)

Tests

Added two cases to helm/tools/grafana-mcp/tests/deployment_test.yaml (developed test-first): a default-image regression guard (the suite had no image assertion), and the empty-registry path.

  - it: should render the default container image
    template: deployment.yaml
    asserts:
      - equal:
          path: spec.template.spec.containers[0].image
          value: mcp/grafana:latest

  - it: should omit empty registry segment in image
    template: deployment.yaml
    set:
      image:
        registry: ""
    asserts:
      - equal:
          path: spec.template.spec.containers[0].image
          value: grafana:latest
      - notMatchRegex:
          path: spec.template.spec.containers[0].image
          pattern: "^/"

The empty-registry test fails without this change (/grafana:latest) and passes with it — revert the deployment.yaml/_helpers.tpl hunks to reproduce.

How to verify

make helm-tools                                       # generate grafana-mcp Chart.yaml
helm unittest helm/tools/grafana-mcp                  # full suite green (incl. new cases)
helm lint helm/tools/grafana-mcp

# test-independent reproduction:
helm template t helm/tools/grafana-mcp --set image.registry="" | grep image:
# before: /grafana:latest
# after:  grafana:latest

Scope

Limited to the grafana-mcp chart's image construction. Empty repository is not made valid here — omitting it leaves no image to pull. This PR only makes image.registry optional.

Checklist

  • Commit is DCO signed-off (git commit -s).
  • helm unittest helm/tools/grafana-mcp green; helm lint helm/tools/grafana-mcp clean.
  • Default image still renders mcp/grafana:latest (regression guard).
  • Diff limited to templates/_helpers.tpl, templates/deployment.yaml, and tests/deployment_test.yaml (generated chart files excluded).
  • Test fails without the fix, passes with it.

Signed-off-by: Mike Spinks <mikespinks@gmail.com>
Copilot AI review requested due to automatic review settings July 1, 2026 10:45
@github-actions github-actions Bot added the bug Something isn't working label Jul 1, 2026

Copilot AI left a comment

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.

Pull request overview

Updates the helm/tools/grafana-mcp Helm chart to render a valid container image reference when image.registry is explicitly set to an empty string, preventing invalid leading-slash image values that cause ImagePullBackOff.

Changes:

  • Introduced a grafana-mcp.image helper that builds the image path by joining only non-empty segments and appending the tag.
  • Updated the Deployment template to use the new helper for the container image field.
  • Added Helm unittest cases to guard the default image value and verify the empty-registry behavior (including a no-leading-slash check).

Reviewed changes

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

File Description
helm/tools/grafana-mcp/templates/_helpers.tpl Adds grafana-mcp.image helper to compose image references without empty path segments.
helm/tools/grafana-mcp/templates/deployment.yaml Switches the Deployment container image field to use the new helper.
helm/tools/grafana-mcp/tests/deployment_test.yaml Adds regression + empty-registry Helm unittest assertions for the rendered image field.

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

@EItanya EItanya merged commit aee7c8c into kagent-dev:main Jul 1, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants