Skip to content

Commit

Permalink
Fix interactive apply asks in no change situation
Browse files Browse the repository at this point in the history
This commit makes the apply logic exit early in the event there are no
changes to releases. I believe this effectively reverts #522.

Fixes: #679
Signed-off-by: Thomas Arrow <[email protected]>
  • Loading branch information
tarrow committed Mar 11, 2024
1 parent 5991077 commit ed9f73a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,7 @@ Hooks associated to `presync` events are triggered before each release is synced
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`.

`preapply` hooks are triggered before a release is uninstalled, installed, or upgraded as part of `helmfile apply`.
This is the ideal event to hook into when you are going to use `helmfile apply` for every kind of change and you want the hook to be triggered regardless of whether the releases have changed or not. Be sure to make each `preapply` hook command idempotent. Otherwise, rerunning helmfile-apply on a transient failure may end up either breaking your cluster, or the hook that runs for the second time will never succeed.
This is the ideal event to hook into when you are going to use `helmfile apply` for every kind of change and it is acceptable for the hook to be triggered regardless of whether the releases have changed or not (n.b. if there are no changes for any releases then this will not run). Be sure to make each `preapply` hook command idempotent. Otherwise, rerunning helmfile-apply on a transient failure may end up either breaking your cluster, or the hook that runs for the second time will never succeed.

`preuninstall` hooks are triggered immediately before a release is uninstalled as part of `helmfile apply`, `helmfile sync`, `helmfile delete`, and `helmfile destroy`.

Expand Down
4 changes: 4 additions & 0 deletions pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,10 @@ Do you really want to apply?
// Traverse DAG of all the releases so that we don't suffer from false-positive missing dependencies
st.Releases = selectedAndNeededReleases

if len(releasesToBeUpdated) == 0 && len(releasesToBeDeleted) == 0 {
return true, false, nil
}

if !interactive || interactive && r.askForConfirmation(confMsg) {
if _, preapplyErrors := withDAG(st, helm, a.Logger, state.PlanOptions{Purpose: "invoking preapply hooks for", Reverse: true, SelectedReleases: toApplyWithNeeds, SkipNeeds: true}, a.WrapWithoutSelector(func(subst *state.HelmState, helm helmexec.Interface) []error {
for _, r := range subst.Releases {
Expand Down

0 comments on commit ed9f73a

Please sign in to comment.