Closed datlife closed 8 months ago
If I updated the string value of templatePatch
to JSON, it works.
templatePatch: |-
{
{{- if .autoSync }}
"spec": {
"syncPolicy": {{ .syncPolicy | toJson}}
}
{{- end }}
}'
I'd bet quite a bit of money that the problem is indentation. Helm templates make heavy use of an indent
function.
JSON is YAML, so I'd recommend doing this:
templatePatch: |
{{- if .autoSync }}
spec:
syncPolicy: {{ .syncPolicy | toJson }}
{{- end }}
As a matter of fact, I'd recommend always piping variables to toJson
so that things like strings get properly escaped.
Thanks! In the documentation, it said it accepts YAML object as templatePatch so I thought it would be trivial to use YAML object. I'll stick to JSON format for now
YAML is never trivial. 😆 But it was a fair expectation. If you can think of a good docs update that will help others, I'd be happy to review.
Checklist:
argocd version
.Describe the bug Related to https://github.com/argoproj/argo-cd/pull/14893
templatePatch
doesn't reconstruct YAML config properly. Apparently it converts to JSON object first and then converts back to YAML.To Reproduce
I have argocd config YAML files for different environments to allow ApplicationSet generate applications. This is a sample of the config.yaml
Here is my applicationSet definition:
Expected behavior
I expect the
templatePatch
being able to generate nested YAML objects. In the above example, an application manifest should be as the following:However, in reality,
syncPolicy
was ignored and empty. However, if I change thetemplatePatch
to this format, it works:Version