-
Notifications
You must be signed in to change notification settings - Fork 278
feat: Go template with sprig for application template render (#303) #513
base: master
Are you sure you want to change the base?
feat: Go template with sprig for application template render (#303) #513
Conversation
96a7fcc
to
f38bbfd
Compare
Just a couple notes while you continue to work on this:
|
6bf032d
to
757ac79
Compare
Another random thought: is it okay to run the template tool across the whole template, or should we recurse through the template and apply templates on a field-by-field basis? The downsides are speed and complexity. The upside is we avoid letting params break out of their field. People setting params like |
Hello @crenshaw-dev, They behave nearly identical, with a tiny difference. With Gotemplate, to begin with, the application structure change is not possible with the current implementation. Here is some demonstration: The input to GoTemplate renderer is a yaml marshaled The only difference I have found is that with fasttemplate based rendering one can pass in the identation special characters such as Anyway, I think we should probably focus on the option I decided to drop initially. What if we allow
boolean values: integers: and control the whole optional object creation, such as: Could be very usefull for example to control
WDYT about this approach? |
b7e9f46
to
fcdd2ea
Compare
@vavdoshka thanks for the detailed writeup! I'm still not sure where to go with the flexibility/predictability tradeoff. I'm going to spend some time reading the duplicate issues (#518, #447, #351, #303) to see what makes the most sense for their use cases. I'm also going to look at the use cases for non-string fields (#424, #385, #287) to see if they justify full-text templating. Finally, I need to look at @jgwest's proposal for an arbitrary-JSON version of tl;dr - this PR is looking awesome, but I gotta do some reading/thinking before responding to your design questions. :-) |
Oh! For an out-of-bounds field edit test, try this:
Given a substitution at the right place, that could change the chart field value. |
found also similar need here #168 @crenshaw-dev with tast input the actual value I recieve now is so tabulation and line ending are lost during unmarshaling, I've spotted that issue already and not yet exactly sure how to fix this, I will be happy to dig in if needed once we would settle on the overall design. |
With the above test, I can actually force
(From the debugger) In one proposed fix for a similar bug in Argo Workflows, Alex simply traversed through the templated object and only performed templating at the individual-string level. I thought it was a pretty elegant solution, but it was dropped in favor of a less intrusive option at the time. https://github.com/argoproj/argo-workflows/pull/6442/files#diff-f052cf13b02f8aaed79df3589c9f5d0124dc630043901ef3a2c89cc3d829dd90R17 |
Okay, I did my reading. :-) Use casesUse cases which only require string templating:
Use cases which require non-string primitive templating:
Use cases which require non-primitive templating:
Proposals
RecommendationsIf it were me writing the code, I'd go with proposal 1. It solves a few use cases with relatively little trouble. But if you're feeling really excited about implementing 2 or 3, I think it would be important to coordinate with @jgwest to make sure that whatever gets written solves the use cases described in his proposal. I know he's been especially busy lately, so that collaboration might be difficult. Hopefully he can chime in here? |
In the back of my mind, I have this idea of duplicating the Application structure, replacing certain non-string fields with |
Thanks @crenshaw-dev for these inputs I believe it is worth to spend a bit more time to think of how that new templating feature would satisfy all of these usecases. And I do agree that it can cover #362 need as well. I will dig in this weekend to experiment and hopefully find a better solution. |
Sounds good! My main concern about #362 is that, if the template is YAML-formatted, my template must also be valid JSON. For example, I couldn't do this: spec:
source:
helm:
parameters:
{{ range .Values.parameters }}
- name: {{.Name}}
value: {{.Value}}
{{ end }} The output is valid YAML, but the template itself is not valid YAML, so I don't think it would be supported by #362. |
Re: #362, @crenshaw-dev, your lists of pros and cons for each approach looks accurate, great analysis! For 362, it should support non-string types: eg a generator should be able to return a json object as a generator parameter, and it should be serialized into the appropriate field of the template, as a full object (rather than just as a string). Personally I don't have any insight into which of the use cases we should focus on, like you I can see the pros and cons of each. My motivation for #362 is it seems like a bunch of folks are using Helm, and wanting to insert helm params (JSON objects) into the Application helm field (the Helm example I posted on the issue) from Git generator. |
@vavdoshka with Jonathan's comments in mind, I'd recommend going ahead with full text-field templating. At some point I'd like to explore per-field templating for users who need more control over their Application resources. But I think full text-field templating would cover all the use cases. |
@crenshaw-dev sorry I did not communicate back, I've made some progress - I just need to have a bit more time, I'm sure I will be able to wrap it up by the end of this week. |
@vavdoshka that's fantastic! My only suggestion would be that we use something besides |
Hello, any update concerning this PR ? I need to pass a bool value for syncOptions, but can't right now |
@vavdoshka if you want to just push what you have, I can try to get it across the finish line! |
3d587d0
to
a080c73
Compare
Signed-off-by: Vlad <[email protected]>
Signed-off-by: Vlad <[email protected]>
Signed-off-by: Vlad <[email protected]>
Signed-off-by: Vlad <[email protected]>
Signed-off-by: Vlad <[email protected]>
Signed-off-by: Vlad <[email protected]>
Signed-off-by: Vlad <[email protected]>
a080c73
to
ff41793
Compare
@crenshaw-dev
A consequence of having two different template inputs is that none of them is mandatory now, and I'm not sure if my proposal to handle this is correct, but it works. I tried to go with Happy to finalize this in short time :) |
@vavdoshka : Can u please move this PR into argocd as applicationset is moved. If u find it laborious, i can do it on your behalf with your consent |
Sure, I agree, please move
Пн, 4 апр. 2022 г. в 07:25, rishabh625 ***@***.***>:
@vavdoshka <https://github.com/vavdoshka> : Can u please move this PR
into argocd as applicationset is moved
<argoproj/argo-cd#8864>. If u find it laborious,
i can do it on your behalf with your consent
—
Reply to this email directly, view it on GitHub
<#513 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACZERGCHXCUSB3RTFD6IBGDVDJ4OHANCNFSM5O47ZCQQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
--
Cordialement,
Vladimir Avdoshka
|
I'm going to take a swing a coming up with some docs for this per: https://cloud-native.slack.com/archives/C01U45M2SVB/p1650554181079489?thread_ts=1650552801.132729&cid=C01U45M2SVB if that'd be helpful. |
Any progress/updates on this PR? Or on where it's been moved within the argo-cd project? I am looking to use a Git File Generator to define a
This would allow me to setup the ApplicationSet to have a templated helm section like:
As of right now, we are forced to use |
@rishabh625 is this on your TODO list? No worries if not, you've got plenty on your plate. Just want to give @zbialik a status update. :-) |
I'll do it @crenshaw-dev I forgot about it, since was looking at argo-cd issues only, we should have migrated issues too.. |
There might be many interesting use-cases where this feature will come in handy. Just a couple that was in demand for me so far:
{{default "default-name-for-namespace" .namespace}}
(Sprig Default Fucntions) while can customize the namespace name if present in the file data. To keep the Git File data DRY, users can also apply this pattern for many other parameters.{{trunc 63 (printf "%s-%s" (now | date "2006-01-02") .cluster)}}
in order to generate unique namespace name for ephemerial application and make sure it will not run over the limit of 63 characters.Some ideas over the design for this need:
{{ namespace }}
will try to call a functionnamespace
, which is different from existing behavior. Aligning the behavior of both seems like a non-trivial and risky venture.RawTemplate string `json:"rawTemplate,omitempty"`
inApplicationSetSpec
would give full freedom in inserting whatever users wants as Application template. I know at least one use-case where it could be useful described here (controllingsyncPolicy
section creation). But I believe this option is too complex and might lead to some bad DX, so I refused to POC it.So I end up integrating Go template / Sprig as seamlessly as possible and letting users decide whether they want to use it or not.
With this POC Pull Request, I want to validate the design/implementation with the maintainers.
If the design is verified, and required changes are done, I want to add some more tests to have some executable spec and add the documentation section about this functionality.
Also, it would be great to get some guidance on how to test the performance of this solution adequately, maybe compare it with the primary templating implementation so that it is also documented and users can make better decisions.