Skip to content

presync hook not running with apply #1940

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

Open
Sajfer opened this issue Aug 11, 2021 · 11 comments
Open

presync hook not running with apply #1940

Sajfer opened this issue Aug 11, 2021 · 11 comments

Comments

@Sajfer
Copy link
Contributor

Sajfer commented Aug 11, 2021

Hi.
I am trying to use the presync hook, but it does not seem to run when using helmfile apply, and only with helmfile sync.

In the documentation it seems like it should run on both apply and sync.
"Hooks associated to presync events are triggered before each release is applied to the remote cluster. This is the ideal event to execute any commands that may mutate the cluster state as it will not be run for read-only operations like lint, diff or template."

Is this the expected behavior?

@Sajfer
Copy link
Contributor Author

Sajfer commented Apr 19, 2022

@mumoshu is this a bug or the expected behaviour?

@mumoshu
Copy link
Collaborator

mumoshu commented Apr 19, 2022

@Sajfer It should work for apply as well. We do call presync hooks from within the apply code path which invokes the some logic that backs helmfile sync

return subst.SyncReleases(&affectedReleases, helm, c.Values(), c.Concurrency(), &syncOpts)
which explicitly calls presync hooks
if _, err := st.triggerPresyncEvent(release, "sync"); err != nil {

@gakesson
Copy link

gakesson commented Apr 20, 2022

@mumoshu I'm not sure @Sajfer has the same issue as I'm facing but I'm currently not able to use apply (even though I really would like to!) as the recommended operation because in case there is no diff to the release then the hook will not execute. I.e. any potential behavior changes induced by the hook may go missing during an upgrade.
So maybe what I'm after is a pre/post apply hook which will execute irrespective of sync being triggered on the release

@mumoshu
Copy link
Collaborator

mumoshu commented Apr 21, 2022

@gakesson In terms of Helmfile, sync means it runs helm upgrade --install on the release. That said, the presync hook not being run on releases with no changes seems a correct behavior. If you need something that works for every release regardless of it has any changes or not, how about prepare?

@gakesson
Copy link

@mumoshu I don't object to the current behavior of presync hook only running when sync is in fact triggered on the release. It seems like a well-defined behavior, but it also means hooks become somewhat non-deterministic when using apply because the hook is entirely dependent on diffs in the release.
prepare could work but then we would need to have every hook script ignore further executions for non-mutating events/operations (repo, list, template etc.). In an ideal world I would like to have a preapply / postapply events so that specifying e.g. ["presync", "preapply"] would unconditionally run the hook once for the release before it being applied on the cluster.

@mumoshu
Copy link
Collaborator

mumoshu commented Apr 21, 2022

@gakesson Thanks for the feedback. preapply that runs unconditionally sounds legit!

@mumoshu
Copy link
Collaborator

mumoshu commented Apr 21, 2022

@Sajfer @gakesson Should we reuse this issue as a feature request for preapply?
Also, any of you willing to contribute a pull request to add that? Thanks!

@Sajfer
Copy link
Contributor Author

Sajfer commented Apr 21, 2022

That is fine for me.
I can see if I can figure out how to add that.

@Sajfer
Copy link
Contributor Author

Sajfer commented Apr 30, 2022

Just to clarify, what we want is a preapply command that runs everytime we apply, not just when there is changes?

@mumoshu
Copy link
Collaborator

mumoshu commented Apr 30, 2022

@Sajfer Exactly!

@Sajfer
Copy link
Contributor Author

Sajfer commented Apr 30, 2022

I created a pullrequest against helmfile/helmfile, helmfile/helmfile#79

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

No branches or pull requests

3 participants