feat(config): enable pipe operations on source function output#6790
feat(config): enable pipe operations on source function output#6790VaismanLior wants to merge 1 commit intoupdatecli:mainfrom
Conversation
|
|
||
| tmpl, err := template.New("cfg").Funcs(updatecliRuntimeFuncMap(data)).Parse(string(content)) | ||
| tmpl, err := template.New("cfg"). | ||
| Funcs(sprig.FuncMap()). |
There was a problem hiding this comment.
While we are here, I am wondering if you shouldn't also add the custom Helm function
updatecli/pkg/core/config/template.go
Line 49 in 7e7aaa2
| Funcs(sprig.FuncMap()). | |
| Funcs(sprig.FuncMap()). | |
| Funcs(helmFuncMap()). // add helm funcMap |
|
Thank you for the PR, it looks great especially with the tests. I just have a minor feedback to only this templating with the one happening at the beginning |
|
I don't know what happening but I just gave it a test using |
|
I just took another look and unfortunately I am not even sure it's technically possible to achieve what you need. Updatecli has two kind of templating, one at start time and a second one after each resource execution to leverage dynamic information like source result. Because the templating engine doesn't know when a resource is executed, we are using this trick If a source hasn't been executed yet, then the template returns '{{ source "sourceID"}}', so in the current implementation it would drop any additional filters like |
|
Worth mentioning your tests are passing because it's executed at start time but with source result which never happen in reality |
|
Thanks for the quick review and for looking into this! |
Fix #6789
Enable pipe operations on
{{ source }}function output to allow transformation of source values at runtime using sprig template functions.Changes
pkg/core/config/main.goExample
Test
To test this pull request, you can run the following commands:
Additional Information
Checklist
Tradeoff
No breaking changes. All existing
{{ source }}usage continues to work. Adding sprig functions to runtime templates provides flexibility with minimal performance impact.Potential improvement