fix: HelmChart/KustomizationRef template values containing quoted string function arguments#501
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.