Skip to content

Commit a36fce9

Browse files
tarrowyxxhero
authored andcommitted
Fix interactive apply asks in no change situation
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 <thomas.arrow@wikimedia.de>
1 parent 693637d commit a36fce9

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1483,7 +1483,7 @@ Hooks associated to `presync` events are triggered before each release is synced
14831483
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`.
14841484

14851485
`preapply` hooks are triggered before a release is uninstalled, installed, or upgraded as part of `helmfile apply`.
1486-
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.
1486+
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.
14871487

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

pkg/app/app.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,6 +1637,10 @@ Do you really want to apply?
16371637
// Traverse DAG of all the releases so that we don't suffer from false-positive missing dependencies
16381638
st.Releases = selectedAndNeededReleases
16391639

1640+
if len(releasesToBeUpdated) == 0 && len(releasesToBeDeleted) == 0 {
1641+
return true, false, nil
1642+
}
1643+
16401644
if !interactive || interactive && r.askForConfirmation(confMsg) {
16411645
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 {
16421646
for _, r := range subst.Releases {

0 commit comments

Comments
 (0)