Skip to content

fix: stringify non-string map keys in values files - #2899

Merged
yxxhero merged 1 commit into
helmfile:mainfrom
lbarrosby:fix/stringify-non-string-map-keys
Nov 15, 2026
Merged

yxxhero merged 1 commit into
helmfile:mainfrom
lbarrosby:fix/stringify-non-string-map-keys

Conversation

@lbarrosby

Copy link
Copy Markdown
Contributor

maputil.CastKeysToStrings returns an error for any map key that is not a string. YAML keys such as 404: or true: decode to int/bool, so an environment values file like this:

errorPages:
  404: not-found
  503: unavailable

fails to load:

unexpected type of key in map: expected string, got int: value=404, map=map[404:not-found 503:unavailable]

Helm accepts the same file and turns the keys into strings. Helmfile itself already does that in maputil.DeepCopyMap, whose doc comment says it normalises map[any]any keys "matching CastKeysToStrings", but CastKeysToStrings errors out instead.

This makes CastKeysToStrings stringify non-string keys with fmt.Sprintf("%v", k), the same way deepCopyValue does. The function is used for environment values, environment secrets, release values and fromYaml.

Tests:

  • TestMapUtil_NonStringKeys in pkg/maputil decodes the YAML above (plus a true: key) with yaml v3 and checks the result. It fails without the change with the error above.
  • TestEnvValsLoad_NonStringKeys in pkg/state loads testdata/values.10.yaml through LoadEnvironmentValues.
  • go test ./pkg/maputil/ and go test ./pkg/state/ -run TestEnvValsLoad pass, and gofmt -l is clean.

YAML keys such as 404 or true decode to int or bool, and
CastKeysToStrings rejected them with 'unexpected type of key in map',
so a values file Helm accepts could not be loaded as environment values.
Convert such keys with fmt.Sprintf like DeepCopyMap already does.

Signed-off-by: Lucas Barros <[email protected]>
@yxxhero
yxxhero merged commit d61fc7d into helmfile:main Nov 15, 2026
17 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.

2 participants