Skip to content

fix: HelmChart/KustomizationRef template values containing quoted string function arguments#501

Merged
gianlucam76 merged 1 commit into
projectsveltos:mainfrom
gianlucam76:templating
Jul 7, 2026
Merged

fix: HelmChart/KustomizationRef template values containing quoted string function arguments#501
gianlucam76 merged 1 commit into
projectsveltos:mainfrom
gianlucam76:templating

Conversation

@gianlucam76

Copy link
Copy Markdown
Member

EventTrigger HelmChart and KustomizationRef fields (values, releaseName, path, etc.) are meant to support Go templates so they can be customized per matching resource. Under the hood, before this fix, event-manager instantiated these by serializing the whole HelmChart (or KustomizationRef) struct to JSON, running the JSON text through the template engine, and parsing the result back.

That approach breaks as soon as a template action uses a quoted string as a function argument, which is a completely normal thing to do. for example stripping a suffix from a resource name with {{ .Resource.metadata.name | replace "-control-plane" "" }}. JSON-encoding the struct escapes those quotes to " before the template engine ever sees them, so the parser chokes with an error like unexpected "\" in operand, and the whole EventTrigger fails to produce a ClusterProfile.

The same pattern also affected destinationCluster templating.

HelmChart, KustomizationRef, and DestinationCluster fields are now instantiated individually, one field at a time, instead of being bundled into a single JSON blob and templated together. Each field's raw template text goes straight into the template engine, so quoted arguments to functions like replace are no longer mangled. This also happens to make it cheaper to instantiate since we don't have to eventually decode a resulting JSON string.

Because each field is now templated independently rathernt, templates that relied on rendering across multiplefields at once, e.g. defining something in one field and expecting it visible to another via shared JSON context, no longer work that way, since there was never a supported mechanism for that and Standalone template expressions within a single field are unaffected and continue to work.

…ing function arguments

EventTrigger HelmChart and KustomizationRef fields (values, releaseName, path, etc.)
are meant to support Go templates so they can be customized per matching resource.
Under the hood, before this fix, event-manager instantiated these by serializing the
whole HelmChart (or KustomizationRef) struct to JSON, running the JSON text through
the template engine, and parsing the result back.

That approach breaks as soon as a template action uses a quoted string as a function
argument, which is a completely normal thing to do. for example stripping a suffix
from a resource name with `{{ .Resource.metadata.name | replace "-control-plane" "" }}`.
JSON-encoding the struct escapes those quotes to \" before the template engine ever sees
them, so the parser chokes with an error like unexpected "\\" in operand, and the whole
EventTrigger fails to produce a ClusterProfile.

The same pattern also affected destinationCluster templating.

HelmChart, KustomizationRef, and DestinationCluster fields are now instantiated individually,
one field at a time, instead of being bundled into a single JSON blob and templated together.
Each field's raw template text goes straight into the template engine, so quoted arguments to
functions like replace are no longer mangled. This also happens to make it cheaper to instantiate
since we don't have to eventually decode a resulting JSON string.

Because each field is now templated independently rathernt, templates that relied on rendering
across multiplefields at once, e.g. defining something in one field and expecting it visible to
another via shared JSON context, no longer work that way, since there was never a supported mechanism
for that and Standalone template expressions within a single field are unaffected and continue to work.
@gianlucam76 gianlucam76 merged commit 9090e37 into projectsveltos:main Jul 7, 2026
7 checks passed
@gianlucam76 gianlucam76 deleted the templating branch July 7, 2026 18:23
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.

1 participant