fixup! Fix preapply hook behavior

Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com>
This commit is contained in:
Yusuke Kuoka 2022-10-10 12:46:17 +00:00 committed by yxxhero
parent c2ea0f0355
commit 111a248523
21 changed files with 137 additions and 8 deletions

View File

@ -960,13 +960,17 @@ func withDAG(templated *state.HelmState, helm helmexec.Interface, logger *zap.Su
return false, []error{err}
}
return withBatches(templated, batches, helm, logger, converge)
return withBatches(opts.Purpose, templated, batches, helm, logger, converge)
}
func withBatches(templated *state.HelmState, batches [][]state.Release, helm helmexec.Interface, logger *zap.SugaredLogger, converge func(*state.HelmState, helmexec.Interface) (bool, []error)) (bool, []error) {
func withBatches(purpose string, templated *state.HelmState, batches [][]state.Release, helm helmexec.Interface, logger *zap.SugaredLogger, converge func(*state.HelmState, helmexec.Interface) (bool, []error)) (bool, []error) {
numBatches := len(batches)
logger.Debugf("processing %d groups of releases in this order:\n%s", numBatches, printBatches(batches))
if purpose == "" {
purpose = "processing"
}
logger.Debugf("%s %d groups of releases in this order:\n%s", purpose, numBatches, printBatches(batches))
any := false
@ -983,7 +987,7 @@ func withBatches(templated *state.HelmState, batches [][]state.Release, helm hel
releaseIds = append(releaseIds, state.ReleaseToID(&release))
}
logger.Debugf("processing releases in group %d/%d: %s", i+1, numBatches, strings.Join(releaseIds, ", "))
logger.Debugf("%s releases in group %d/%d: %s", purpose, i+1, numBatches, strings.Join(releaseIds, ", "))
batchSt := *templated
batchSt.Releases = targets
@ -1360,7 +1364,7 @@ Do you really want to apply?
st.Releases = selectedAndNeededReleases
if !interactive || interactive && r.askForConfirmation(confMsg) {
if _, preapplyErrors := withDAG(st, helm, a.Logger, state.PlanOptions{Reverse: true, SelectedReleases: toDelete, SkipNeeds: true}, a.WrapWithoutSelector(func(subst *state.HelmState, helm helmexec.Interface) []error {
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 {
release := r
if _, err := st.TriggerPreapplyEvent(&release, "apply"); err != nil {

View File

@ -38,6 +38,13 @@ Affected releases are:
bar (stable/mychart2) DELETED
foo (stable/mychart1) UPDATED
invoking preapply hooks for 2 groups of releases in this order:
GROUP RELEASES
1 default//bar
2 default//foo
invoking preapply hooks for releases in group 1/2: default//bar
invoking preapply hooks for releases in group 2/2: default//foo
processing 1 groups of releases in this order:
GROUP RELEASES
1 default//bar

View File

@ -38,6 +38,13 @@ Affected releases are:
bar (stable/mychart2) DELETED
foo (stable/mychart1) UPDATED
invoking preapply hooks for 2 groups of releases in this order:
GROUP RELEASES
1 default//foo
2 default//bar
invoking preapply hooks for releases in group 1/2: default//foo
invoking preapply hooks for releases in group 2/2: default//bar
processing 1 groups of releases in this order:
GROUP RELEASES
1 default//bar

View File

@ -40,6 +40,13 @@ Affected releases are:
bar (stable/mychart2) DELETED
foo (stable/mychart1) DELETED
invoking preapply hooks for 2 groups of releases in this order:
GROUP RELEASES
1 default//bar
2 default//foo
invoking preapply hooks for releases in group 1/2: default//bar
invoking preapply hooks for releases in group 2/2: default//foo
processing 2 groups of releases in this order:
GROUP RELEASES
1 default//bar

View File

@ -40,6 +40,13 @@ Affected releases are:
bar (stable/mychart2) DELETED
foo (stable/mychart1) DELETED
invoking preapply hooks for 2 groups of releases in this order:
GROUP RELEASES
1 default//foo
2 default//bar
invoking preapply hooks for releases in group 1/2: default//foo
invoking preapply hooks for releases in group 2/2: default//bar
processing 2 groups of releases in this order:
GROUP RELEASES
1 default//foo

View File

@ -38,6 +38,13 @@ Affected releases are:
bar (stable/mychart2) UPDATED
foo (stable/mychart1) DELETED
invoking preapply hooks for 2 groups of releases in this order:
GROUP RELEASES
1 default//bar
2 default//foo
invoking preapply hooks for releases in group 1/2: default//bar
invoking preapply hooks for releases in group 2/2: default//foo
processing 1 groups of releases in this order:
GROUP RELEASES
1 default//foo

View File

@ -38,6 +38,13 @@ Affected releases are:
bar (stable/mychart2) UPDATED
foo (stable/mychart1) DELETED
invoking preapply hooks for 2 groups of releases in this order:
GROUP RELEASES
1 default//foo
2 default//bar
invoking preapply hooks for releases in group 1/2: default//foo
invoking preapply hooks for releases in group 2/2: default//bar
processing 1 groups of releases in this order:
GROUP RELEASES
1 default//foo

View File

@ -44,6 +44,13 @@ Affected releases are:
bar (stable/mychart2) UPDATED
foo (stable/mychart1) UPDATED
invoking preapply hooks for 2 groups of releases in this order:
GROUP RELEASES
1 default/tns1/foo
2 default/tns2/bar
invoking preapply hooks for releases in group 1/2: default/tns1/foo
invoking preapply hooks for releases in group 2/2: default/tns2/bar
processing 2 groups of releases in this order:
GROUP RELEASES
1 default/tns2/bar

View File

@ -41,6 +41,13 @@ Affected releases are:
baz (stable/mychart3) UPDATED
foo (stable/mychart1) UPDATED
invoking preapply hooks for 2 groups of releases in this order:
GROUP RELEASES
1 default//foo
2 default//baz, default//bar
invoking preapply hooks for releases in group 1/2: default//foo
invoking preapply hooks for releases in group 2/2: default//baz, default//bar
processing 2 groups of releases in this order:
GROUP RELEASES
1 default//baz, default//bar

View File

@ -135,6 +135,19 @@ Affected releases are:
logging (charts/fluent-bit) UPDATED
servicemesh (charts/istio) UPDATED
invoking preapply hooks for 5 groups of releases in this order:
GROUP RELEASES
1 default//frontend-v1, default//frontend-v2, default//frontend-v3
2 default//backend-v1, default//backend-v2
3 default//anotherbackend
4 default//database, default//servicemesh
5 default//logging, default//front-proxy
invoking preapply hooks for releases in group 1/5: default//frontend-v1, default//frontend-v2, default//frontend-v3
invoking preapply hooks for releases in group 2/5: default//backend-v1, default//backend-v2
invoking preapply hooks for releases in group 3/5: default//anotherbackend
invoking preapply hooks for releases in group 4/5: default//database, default//servicemesh
invoking preapply hooks for releases in group 5/5: default//logging, default//front-proxy
processing 2 groups of releases in this order:
GROUP RELEASES
1 default//frontend-v1

View File

@ -36,6 +36,13 @@ Affected releases are:
bar (stable/mychart2) UPDATED
foo (stable/mychart1) UPDATED
invoking preapply hooks for 2 groups of releases in this order:
GROUP RELEASES
1 default/testNamespace/bar
2 default/testNamespace/foo
invoking preapply hooks for releases in group 1/2: default/testNamespace/bar
invoking preapply hooks for releases in group 2/2: default/testNamespace/foo
processing 2 groups of releases in this order:
GROUP RELEASES
1 default/testNamespace/foo

View File

@ -36,6 +36,13 @@ Affected releases are:
bar (stable/mychart2) UPDATED
foo (stable/mychart1) UPDATED
invoking preapply hooks for 2 groups of releases in this order:
GROUP RELEASES
1 default//bar
2 default//foo
invoking preapply hooks for releases in group 1/2: default//bar
invoking preapply hooks for releases in group 2/2: default//foo
processing 2 groups of releases in this order:
GROUP RELEASES
1 default//foo

View File

@ -36,6 +36,13 @@ Affected releases are:
bar (stable/mychart2) UPDATED
foo (stable/mychart1) UPDATED
invoking preapply hooks for 2 groups of releases in this order:
GROUP RELEASES
1 default/testNamespace/foo
2 default/testNamespace/bar
invoking preapply hooks for releases in group 1/2: default/testNamespace/foo
invoking preapply hooks for releases in group 2/2: default/testNamespace/bar
processing 2 groups of releases in this order:
GROUP RELEASES
1 default/testNamespace/bar

View File

@ -36,6 +36,13 @@ Affected releases are:
bar (stable/mychart2) UPDATED
foo (stable/mychart1) UPDATED
invoking preapply hooks for 2 groups of releases in this order:
GROUP RELEASES
1 default//foo
2 default//bar
invoking preapply hooks for releases in group 1/2: default//foo
invoking preapply hooks for releases in group 2/2: default//bar
processing 2 groups of releases in this order:
GROUP RELEASES
1 default//bar

View File

@ -40,6 +40,13 @@ Affected releases are:
bar (stable/mychart2) UPDATED
foo (stable/mychart1) UPDATED
invoking preapply hooks for 2 groups of releases in this order:
GROUP RELEASES
1 default/ns1/foo
2 default/ns2/bar
invoking preapply hooks for releases in group 1/2: default/ns1/foo
invoking preapply hooks for releases in group 2/2: default/ns2/bar
processing 2 groups of releases in this order:
GROUP RELEASES
1 default/ns2/bar

View File

@ -40,6 +40,13 @@ Affected releases are:
bar (stable/mychart2) UPDATED
foo (stable/mychart1) UPDATED
invoking preapply hooks for 2 groups of releases in this order:
GROUP RELEASES
1 default/ns2/bar
2 default/ns1/foo
invoking preapply hooks for releases in group 1/2: default/ns2/bar
invoking preapply hooks for releases in group 2/2: default/ns1/foo
processing 2 groups of releases in this order:
GROUP RELEASES
1 default/ns1/foo

View File

@ -53,6 +53,11 @@ merged environment: &{default map[] map[]}
Affected releases are:
foo (incubator/raw) UPDATED
invoking preapply hooks for 1 groups of releases in this order:
GROUP RELEASES
1 default/default/foo
invoking preapply hooks for releases in group 1/1: default/default/foo
processing 1 groups of releases in this order:
GROUP RELEASES
1 default/default/foo

View File

@ -57,6 +57,11 @@ merged environment: &{default map[] map[]}
Affected releases are:
foo (incubator/raw) UPDATED
invoking preapply hooks for 1 groups of releases in this order:
GROUP RELEASES
1 default/default/foo
invoking preapply hooks for releases in group 1/1: default/default/foo
processing 1 groups of releases in this order:
GROUP RELEASES
1 default/default/foo

View File

@ -5,6 +5,9 @@ hook[prepare] logs |
hook[preapply] logs | foo
hook[preapply] logs |
hook[preapply] logs | bar
hook[preapply] logs |
hook[presync] logs | foo
hook[presync] logs |

View File

@ -2,15 +2,15 @@
hook[prepare] logs | foo
hook[prepare] logs |
hook[preapply] logs | foo
hook[preapply] logs |
hook[preapply] logs | bar
hook[preapply] logs |
hook[presync] logs | bar
hook[presync] logs |
hook[preapply] logs | foo
hook[preapply] logs |
hook[presync] logs | foo
hook[presync] logs |

View File

@ -100,6 +100,7 @@ func (st *HelmState) iterateOnReleases(helm helmexec.Interface, concurrency int,
}
type PlanOptions struct {
Purpose string
Reverse bool
IncludeNeeds bool
IncludeTransitiveNeeds bool