Skip to content

feat: add template args to be used for template and within apply#1833

Open
KATechDev wants to merge 5 commits into
helmfile:mainfrom
KATechDev:feat/add-template-arguments
Open

feat: add template args to be used for template and within apply#1833
KATechDev wants to merge 5 commits into
helmfile:mainfrom
KATechDev:feat/add-template-arguments

Conversation

@KATechDev
Copy link
Copy Markdown

Adding TemplateArgs to allow passing any args to the helm template function.
I use this to pass --dry-run=server for helmfile apply (which is using helm template underneath) . This enables me to use the lookup functionality in my helm charts.

@KATechDev KATechDev force-pushed the feat/add-template-arguments branch 3 times, most recently from f2b21c1 to 2e378f6 Compare December 18, 2024 10:38
@yxxhero yxxhero force-pushed the feat/add-template-arguments branch from 2e378f6 to 0dba2a7 Compare December 18, 2024 13:05
@stale
Copy link
Copy Markdown

stale Bot commented Jan 1, 2025

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale Bot added the wontfix This will not be worked on label Jan 1, 2025
@yxxhero yxxhero removed the wontfix This will not be worked on label Jan 1, 2025
@yxxhero
Copy link
Copy Markdown
Member

yxxhero commented Jan 8, 2025

@KATechDev I will review this at weekend.

@yxxhero
Copy link
Copy Markdown
Member

yxxhero commented Jan 11, 2025

@KATechDev did you test this locally? I don't see any code to use template args.

@yxxhero
Copy link
Copy Markdown
Member

yxxhero commented Jan 11, 2025

@KATechDev BTW. we need some test code to be addde.

@KATechDev
Copy link
Copy Markdown
Author

@KATechDev did you test this locally? I don't see any code to use template args.

Yes I use it via helmfile apply --template-args=--dry-run=server.
In my charts I use something like {{ $existingSecret := (lookup "v1" "Secret" .Release.Namespace "my-secret") }} ...

@yxxhero
Copy link
Copy Markdown
Member

yxxhero commented Jan 15, 2025

@KATechDev ok. got it. pls fix code confilcts.

@Footur
Copy link
Copy Markdown

Footur commented Jan 22, 2025

I've tried this feature, but the flag "--dry-run=server" is not handover to helmfile template.

Example:
helmfile template --template-args '--dry-run=server' -f namespace.yaml

Building dependency release=ns-observability, chart=../helm/namespaces
Templating release=ns-observability, chart=../helm/namespaces
in ./namespace.yaml: command "/usr/local/bin/helm" exited with non-zero status:

PATH:
  /usr/local/bin/helm

ARGS:
  0: helm (4 bytes)
  1: template (8 bytes)
  2: ns-observability (16 bytes)
  3: ../helm/namespaces (18 bytes)
  4: --namespace (11 bytes)
  5: observability (13 bytes)
  6: --values (8 bytes)
  7: /tmp/helmfile2586027982/observability-ns-observability-values-6574bb45c5 (72 bytes)
  8: --values (8 bytes)
  9: /tmp/helmfile142640842/observability-ns-observability-values-5d94988f5b (71 bytes)
  10: --values (8 bytes)
  11: /tmp/helmfile3254496066/observability-ns-observability-values-8666bb65cd (72 bytes)

ERROR:
  exit status 1

EXIT STATUS
  1

STDERR:
  Error: template: namespaces/templates/deny-all.yaml:1:62: executing "namespaces/templates/deny-all.yaml" at <include "namespace.isNcsRegion" .>: error calling include: template: namespaces/templates/_helpers.tpl:5:37: executing "namespace.isNcsRegion" at <first (lookup "v1" "Node" "" "").items>: error calling first: runtime error: invalid memory address or nil pointer dereference
  Use --debug flag to render out invalid YAML

COMBINED OUTPUT:
  Error: template: namespaces/templates/deny-all.yaml:1:62: executing "namespaces/templates/deny-all.yaml" at <include "namespace.isNcsRegion" .>: error calling include: template: namespaces/templates/_helpers.tpl:5:37: executing "namespace.isNcsRegion" at <first (lookup "v1" "Node" "" "").items>: error calling first: runtime error: invalid memory address or nil pointer dereference
  Use --debug flag to render out invalid YAML

@KATechDev
Copy link
Copy Markdown
Author

@Footur I'll try to have a look at it end of next week.

@KATechDev
Copy link
Copy Markdown
Author

@Footur I'll try to have a look at it end of next week.

This bothered me, so I had to check now. I tested template again on my machine and it works as expected.
However I see why this is confusing. helm template is called twice by helmfile. First to generate the expected values and secondly to use these generate values to template the result. As you see in your output the values have already been created and are used in the helm template call. Therefore your output is from the second time helm template gets called. The first time is however the one including the change. You can verify this by calling the helmfile with the --debug option. You'll find the first call: running helm template ... --dry-run=server and the second call exec: helm template ..

@KATechDev KATechDev force-pushed the feat/add-template-arguments branch 2 times, most recently from c1221e4 to c31b686 Compare February 6, 2025 13:34
@KATechDev
Copy link
Copy Markdown
Author

@KATechDev BTW. we need some test code to be addde.

Will be done soon (~2 weeks)

@stale
Copy link
Copy Markdown

stale Bot commented Feb 21, 2025

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale Bot added wontfix This will not be worked on and removed wontfix This will not be worked on labels Feb 21, 2025
@KATechDev KATechDev force-pushed the feat/add-template-arguments branch from a93d135 to cc5b1d5 Compare February 21, 2025 12:54
@KATechDev KATechDev force-pushed the feat/add-template-arguments branch 2 times, most recently from fe77939 to 1ca3527 Compare March 6, 2025 15:23
@KATechDev KATechDev force-pushed the feat/add-template-arguments branch from 1ca3527 to 38157bd Compare March 6, 2025 15:24
@yxxhero yxxhero force-pushed the feat/add-template-arguments branch from 38157bd to 6a4a2a0 Compare March 7, 2025 00:41
@yxxhero
Copy link
Copy Markdown
Member

yxxhero commented Mar 7, 2025

@KATechDev should we update the sync subcommand?

@KATechDev
Copy link
Copy Markdown
Author

@KATechDev should we update the sync subcommand?

Not sure what you mean. Could you please be more specific?

@yxxhero
Copy link
Copy Markdown
Member

yxxhero commented Mar 7, 2025

@KATechDev do same thing in helmfile sync subcommand. because of helmfile apply is equal to helmfile diff && helmfile sync.

@stale
Copy link
Copy Markdown

stale Bot commented Mar 22, 2025

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale Bot added the wontfix This will not be worked on label Mar 22, 2025
@yxxhero yxxhero added in progress and removed wontfix This will not be worked on labels Mar 24, 2025
@tanluongascenda
Copy link
Copy Markdown

hi, thank for your great effort, we're using argocd with helmfile and really need this feature, may I ask any progress on this?

@yxxhero
Copy link
Copy Markdown
Member

yxxhero commented Apr 18, 2025

@KATechDev ping. thanks so much.

@KATechDev
Copy link
Copy Markdown
Author

Hi, I'm currently busy, but in about two weeks I might get a change to get to it.

@khoaanguyenn
Copy link
Copy Markdown

Hi, I'm currently busy, but in about two weeks I might get a change to get to it.

👋 Hi @KATechDev, thanks for spending the effort to work on the feature, we're also using ArgoCD with Helmfile and would like to have such great feature. Might I know if there's any progress on this pull request?

@KATechDev
Copy link
Copy Markdown
Author

Hi there,
adding the same changes for sync isn't the problem, unfortunately I noticed that my code is just executed under specific circumstances. I'll need to analyze this.

@JuryA
Copy link
Copy Markdown

JuryA commented Jul 19, 2025

Is there any progress on this?

Because running helmfile apply … together with helm diff … without implicitly using the --dry-run=server flag is effectively useless and only creates confusion—the user doesn’t realize that this is the root cause.

Frankly, all the security theater around it seems nonsensical, since we ultimately invoke helmfile sync …, which must have cluster access anyway.

Permissions are determined solely by the token in the kubeconfig file; there’s no way to “gain extra” privileges, and in this context that is perfectly fine.

It’s merely a lookup operation, and if someone is concerned about security, the problem lies elsewhere—not with the --dry-run=server flag.

It neither degrades nor improves the outcome, in my opinion, but it does unnecessarily impair the UX.

@KATechDev KATechDev force-pushed the feat/add-template-arguments branch 2 times, most recently from 19ad24e to ed3511b Compare October 1, 2025 07:48
@KATechDev
Copy link
Copy Markdown
Author

KATechDev commented Oct 1, 2025

Hi there,
I'm sorry that I couldn't find time to get into this any sooner.

The current behavior of helmfile is as follow.
Using helmfile apply or helmfile sync, with a "regular" helmfile on a helm-chart with resource that uses the "lookup" function, the lookup works as expected.
However if the helmfile internally uses "chartify", which is triggered for example by forceNamespace or kustomaziation, the lookup doesn't work, as there is no cluster connection for the internal "helm template".

As appy and sync are cluster operations and the use case without "chartify" works without any additional flag, I changed my implementation, that the "dry-run=server" flag for --template-args is set as default. This keeps the behavior consistent between "regular" and "chartify" helmfiles.
However for the helmfile template this mr provides a new flag --template-args where one can set --dry-run=server if desired.

One more thing:
currently when using helmfile apply with a "regular" helmfile on a helm-chart with resource that uses the "lookup" function, the printed diff is not correct. It shows the diff without lookup, but then applies the correct values with lookup. So the result is correct but the printed output is wrong and therefore confusing. This can be changed by enforcing to use the "chartify" if the template args / dry-run=server is set, but this would then be (nearly) always. I was wondering if there are any negative side effects that I'm missing (maybe performance!?). I can add the changes here and to the chartify repo.

Signed-off-by: Kerstin Albers <kerstinzuzej@gmail.com>
Signed-off-by: Kerstin Albers <kerstinzuzej@gmail.com>
Signed-off-by: Kerstin Albers <kerstinzuzej@gmail.com>
…to achieve consistent behavior. For template prodive option --template-args

Signed-off-by: Kerstin Albers <kerstinzuzej@gmail.com>
…o --sry-run=server for sync and apply

Signed-off-by: Kerstin Albers <kerstinzuzej@gmail.com>
@KATechDev KATechDev force-pushed the feat/add-template-arguments branch from b1e6960 to f05d0c7 Compare October 1, 2025 16:34
@KATechDev
Copy link
Copy Markdown
Author

I'm happy to rebase / resolve the conflicts but is there an estimation when there might be a review?

@yxxhero
Copy link
Copy Markdown
Member

yxxhero commented Jan 21, 2026

@KATechDev please rebase / resolve the conflicts

@zhaque44
Copy link
Copy Markdown
Contributor

@KATechDev i can review but the PR needs to be in a state where it can actually be reviewed, please resolve the conflicats and I will take a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants