Skip to content

Commit 326113f

Browse files
committed
Fix interactive apply asks in no change situation
This commit moves the pre-apply hooks that are now always run since #522 outside of the check for interactivity or asking for confirmation. It also moves - the early exit condition for the case when there are no releases to Delete or Update - the cleanup of released with no change to before the interactivity check This does subtly change the behaviour of preapply hooks when apply is invoked in interactive mode. The hooks will always be run before confirmation is asked for. In the event there are no releases to delete or update the preapply hooks will still run. Given that each preapply hook command must be idempotent I don't believe this is an issue. Fixes: #679 Signed-off-by: Thomas Arrow <[email protected]>
1 parent c19f220 commit 326113f

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

pkg/app/app.go

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,20 +1418,31 @@ Do you really want to apply?
14181418
// Traverse DAG of all the releases so that we don't suffer from false-positive missing dependencies
14191419
st.Releases = selectedAndNeededReleases
14201420

1421-
if !interactive || interactive && r.askForConfirmation(confMsg) {
1422-
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 {
1423-
for _, r := range subst.Releases {
1424-
release := r
1425-
if _, err := st.TriggerPreapplyEvent(&release, "apply"); err != nil {
1426-
return []error{err}
1427-
}
1421+
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 {
1422+
for _, r := range subst.Releases {
1423+
release := r
1424+
if _, err := st.TriggerPreapplyEvent(&release, "apply"); err != nil {
1425+
return []error{err}
14281426
}
1427+
}
14291428

1430-
return nil
1431-
})); len(preapplyErrors) > 0 {
1432-
return true, false, preapplyErrors
1429+
return nil
1430+
})); len(preapplyErrors) > 0 {
1431+
return true, false, preapplyErrors
1432+
}
1433+
1434+
for id := range releasesWithNoChange {
1435+
r := releasesWithNoChange[id]
1436+
if _, err := st.TriggerCleanupEvent(&r, "apply"); err != nil {
1437+
a.Logger.Warnf("warn: %v\n", err)
14331438
}
1439+
}
1440+
1441+
if releasesToBeDeleted == nil && releasesToBeUpdated == nil {
1442+
return true, false, nil
1443+
}
14341444

1445+
if !interactive || interactive && r.askForConfirmation(confMsg) {
14351446
// We deleted releases by traversing the DAG in reverse order
14361447
if len(releasesToBeDeleted) > 0 {
14371448
_, deletionErrs := withDAG(st, helm, a.Logger, state.PlanOptions{Reverse: true, SelectedReleases: toDelete, SkipNeeds: true}, a.WrapWithoutSelector(func(subst *state.HelmState, helm helmexec.Interface) []error {
@@ -1489,16 +1500,6 @@ Do you really want to apply?
14891500

14901501
affectedReleases.DisplayAffectedReleases(c.Logger())
14911502

1492-
for id := range releasesWithNoChange {
1493-
r := releasesWithNoChange[id]
1494-
if _, err := st.TriggerCleanupEvent(&r, "apply"); err != nil {
1495-
a.Logger.Warnf("warn: %v\n", err)
1496-
}
1497-
}
1498-
if releasesToBeDeleted == nil && releasesToBeUpdated == nil {
1499-
return true, false, nil
1500-
}
1501-
15021503
return true, true, applyErrs
15031504
}
15041505

0 commit comments

Comments
 (0)