Skip to content

fix(helm): use root context $ in tpl() inside with blocks#744

Merged
Cali0707 merged 2 commits into
containers:mainfrom
shyoon-devops:fix/helm-tpl-context-in-with-blocks
Feb 5, 2026
Merged

fix(helm): use root context $ in tpl() inside with blocks#744
Cali0707 merged 2 commits into
containers:mainfrom
shyoon-devops:fix/helm-tpl-context-in-with-blocks

Conversation

@shyoon-devops

@shyoon-devops shyoon-devops commented Feb 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #743

Problem

Inside {{- with .Values.xxx }}, the dot . is the current value (e.g. array or nested object). Using tpl (toYaml .) . passes that value as the template context, but tpl expects the root context (chartutil.Values). This causes:

  • wrong type for value; expected chartutil.Values; got []interface {} when e.g. imagePullSecrets is set
  • Similar errors for livenessProbe, readinessProbe, etc. when default values are rendered

Solution

Use the root context $ as the second argument to tpl wherever it is used inside a with block, so that any template expressions in the YAML string are evaluated against the full chart context.

Change: Replace all occurrences of tpl (toYaml .) . with tpl (toYaml .) $ in charts/kubernetes-mcp-server/templates/deployment.yaml (only in the lines that are inside {{- with ... }} blocks).

Lines updated (inside with blocks):

  • podAnnotations
  • podLabels
  • imagePullSecrets
  • livenessProbe
  • readinessProbe
  • resources
  • extraVolumeMounts
  • extraContainers
  • extraVolumes
  • nodeSelector
  • affinity
  • tolerations

The existing tpl (toYaml (default ...)) . usages that are outside with blocks are left unchanged (. is correct there).

Inside {{- with .Values.xxx }}, the dot . is the current value (e.g. array
or nested object). Using tpl (toYaml .) . passes that value as the template
context, but tpl expects the root context (chartutil.Values). This causes
'wrong type for value; expected chartutil.Values; got []interface {}' when
imagePullSecrets, livenessProbe, readinessProbe, etc. are set.

Use the root context $ as the second argument to tpl wherever it is used
inside a with block, so template expressions in the YAML string are
evaluated against the full chart context. The tpl (toYaml (default ...)) .
usages outside with blocks are left unchanged.

Signed-off-by: sh.yoon <sh.yoon.devops@gmail.com>
@manusa
manusa force-pushed the fix/helm-tpl-context-in-with-blocks branch from 550d996 to 09779d1 Compare February 5, 2026 15:36
@manusa manusa added this to the 0.1.0 milestone Feb 5, 2026
The same issue fixed in deployment.yaml also exists in
serviceaccount.yaml: using tpl (toYaml .) . inside a with block
fails when the value contains template expressions, because .
refers to the current value instead of the root chart context.

This commit:
- Changes . to $ in serviceaccount.yaml tpl call
- Adds serviceAccount.annotations test case to ci/tpl-test-values.yaml

Signed-off-by: Marc Nuri <marc@marcnuri.com>
@manusa
manusa force-pushed the fix/helm-tpl-context-in-with-blocks branch from 9fdd5b8 to 73a2e29 Compare February 5, 2026 15:42

@manusa manusa left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thx!

I rebased on top of main to have the checks provided in the pipeline implemented in #745

Also added another fix for serviceaccount.yaml that was missing.

We should merge this ASAP to avoid having a failing pipeline on main.

@Cali0707 Cali0707 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@Cali0707
Cali0707 merged commit dd57a9f into containers:main Feb 5, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

helm chart: tpl wrong context in with blocks causes "expected chartutil.Values; got []interface {}"

3 participants