-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new functions to the template engine #11974
Comments
To note, join already exists: http://masterminds.github.io/sprig/string_slice.html |
Thank you for your response. I saw that but its usage is not clean yet. I have a Kafka cluster and I wanna set its bootstrap-servers. here is my code:
What is your idea about adding a new function named With append function it will be:
|
Add toSeconds function to convert duration to seconds Add toMilliSeconds function to convert duration to milliseconds It's related to: helm#11974
Add toSeconds function to convert duration to seconds Add toMilliSeconds function to convert duration to milliseconds It's related to: helm#11974 Signed-off-by: Ehsan Karimi <karimiehsan901@gmail.com>
You mean like http://masterminds.github.io/sprig/lists.html#append-mustappend ? Familiarize yourself with the sprig functions. There's a lot you can do with them. |
@joejulian No I don't mean it. |
Add toSeconds function to convert duration to seconds Add toMilliSeconds function to convert duration to milliseconds It's related to: helm#11974 Signed-off-by: Ehsan Karimi <karimiehsan901@gmail.com>
Ah, in the go template language, you'll have to write a loop for that:
|
Each of these can be solved using named templates and that's probably the best way to handle this. Sprig is maintained, but is very resistant to adding new functions. Here's an example of SI-to-bytes |
@joejulian I know it is possible now. But this loop will be duplicated for all of the developers and it's a code smell. This is my solution for the current helm:
And it will be after adding the mapAppend function:
Do you see the difference? The second one is much more readable than the first one. |
Sure. The new function does make it simpler and more readable, but the chance that a new function is being added to helm is very slim. The maintainers have been very clear in the past that if it can be done with the existing tools, then no new functions will be added.
|
Got me wondering what I did, but our structure's different from that: redpanda-data/helm-charts/main/charts/redpanda/templates/configmap.yaml
|
@joejulian I disagree with this paradigm. In my opinion the template engine must be as simple as possible. After 3 years writing Ansible Roles and Helm Charts, I feel I am tied in the Go template engine. In Jinja we have all these functions and Ansible is extensible (Thanks for the python interpreter). But in Helm, this simple common problem must be solved with a loop (and in some cases a condition). |
Well feel free to open a PR. I'm just sharing what I know from past conversations with the maintainers. |
@joejulian |
This issue has been marked as stale because it has been open for 90 days with no activity. This thread will be automatically closed in 30 days if no further activity occurs. |
I wanna add some functions to the template engine and I want ask your feedback first:
I wanna add the below functions:
{{ ['a', 'b', 'c'] | join ',' }}
toa,b,c
.{{ '1h' | toSeconds }}
to3600
{{ '1 KB' | toBytes }}
to1024
First I wanted to add them into the sprig library, but unfortunately it seems not to be maintained anymore: Masterminds/sprig#365
The text was updated successfully, but these errors were encountered: