diff --git a/pkg/app/testdata/testapply_hooks/apply_release_with_preapply_hook#01/log b/pkg/app/testdata/testapply_hooks/apply_release_with_preapply_hook#01/log index cbffb336..bcc2fb64 100644 --- a/pkg/app/testdata/testapply_hooks/apply_release_with_preapply_hook#01/log +++ b/pkg/app/testdata/testapply_hooks/apply_release_with_preapply_hook#01/log @@ -6,8 +6,9 @@ Running preapply hook for foo: hook[preapply] logs | foo hook[preapply] logs | -hook[echo]: already executed by "preapply", skipping "presync" +hook[presync] logs | foo +hook[presync] logs | UPDATED RELEASES: NAME CHART VERSION diff --git a/pkg/event/bus.go b/pkg/event/bus.go index cd0c273a..fcf18a2b 100644 --- a/pkg/event/bus.go +++ b/pkg/event/bus.go @@ -11,7 +11,6 @@ import ( "github.com/helmfile/helmfile/pkg/helmexec" "github.com/helmfile/helmfile/pkg/tmpl" "go.uber.org/zap" - "golang.org/x/exp/slices" ) type Hook struct { @@ -21,7 +20,6 @@ type Hook struct { Kubectl map[string]string `yaml:"kubectlApply,omitempty"` Args []string `yaml:"args"` ShowLogs bool `yaml:"showlogs"` - Executed bool `yaml:"-"` } type event struct { @@ -74,10 +72,6 @@ func (bus *Bus) Trigger(evt string, evtErr error, context map[string]interface{} } } - if slices.Contains(hook.Events, "preapply") && evt == "presync" && hook.Executed { - bus.Logger.Infof("hook[%s]: already executed by \"preapply\", skipping \"%s\"\n", name, evt) - continue - } if hook.Kubectl != nil { if hook.Command != "" { bus.Logger.Warnf("warn: ignoring command '%s' given within a kubectlApply hook", hook.Command) diff --git a/pkg/event/bus_test.go b/pkg/event/bus_test.go index 2352fad1..f2cc2d89 100644 --- a/pkg/event/bus_test.go +++ b/pkg/event/bus_test.go @@ -41,21 +41,21 @@ func TestTrigger(t *testing.T) { }{ { "okhook1", - &Hook{"okhook1", []string{"foo"}, "ok", nil, []string{}, true, false}, + &Hook{"okhook1", []string{"foo"}, "ok", nil, []string{}, true}, "foo", true, "", }, { "okhooké", - &Hook{"okhook2", []string{"foo"}, "ok", nil, []string{}, false, false}, + &Hook{"okhook2", []string{"foo"}, "ok", nil, []string{}, false}, "foo", true, "", }, { "missinghook1", - &Hook{"okhook1", []string{"foo"}, "ok", nil, []string{}, false, false}, + &Hook{"okhook1", []string{"foo"}, "ok", nil, []string{}, false}, "bar", false, "", @@ -69,70 +69,70 @@ func TestTrigger(t *testing.T) { }, { "nghook1", - &Hook{"nghook1", []string{"foo"}, "ng", nil, []string{}, false, false}, + &Hook{"nghook1", []string{"foo"}, "ng", nil, []string{}, false}, "foo", false, "hook[nghook1]: command `ng` failed: cmd failed due to invalid cmd: ng", }, { "nghook2", - &Hook{"nghook2", []string{"foo"}, "ok", nil, []string{"ng"}, false, false}, + &Hook{"nghook2", []string{"foo"}, "ok", nil, []string{"ng"}, false}, "foo", false, "hook[nghook2]: command `ok` failed: cmd failed due to invalid arg: ng", }, { "okkubeapply1", - &Hook{"okkubeapply1", []string{"foo"}, "", map[string]string{"kustomize": "kustodir"}, []string{}, false, false}, + &Hook{"okkubeapply1", []string{"foo"}, "", map[string]string{"kustomize": "kustodir"}, []string{}, false}, "foo", true, "", }, { "okkubeapply2", - &Hook{"okkubeapply2", []string{"foo"}, "", map[string]string{"filename": "resource.yaml"}, []string{}, false, false}, + &Hook{"okkubeapply2", []string{"foo"}, "", map[string]string{"filename": "resource.yaml"}, []string{}, false}, "foo", true, "", }, { "kokubeapply", - &Hook{"kokubeapply", []string{"foo"}, "", map[string]string{"kustomize": "kustodir", "filename": "resource.yaml"}, []string{}, true, false}, + &Hook{"kokubeapply", []string{"foo"}, "", map[string]string{"kustomize": "kustodir", "filename": "resource.yaml"}, []string{}, true}, "foo", false, "hook[kokubeapply]: kustomize & filename cannot be used together", }, { "kokubeapply2", - &Hook{"kokubeapply2", []string{"foo"}, "", map[string]string{}, []string{}, true, false}, + &Hook{"kokubeapply2", []string{"foo"}, "", map[string]string{}, []string{}, true}, "foo", false, "hook[kokubeapply2]: either kustomize or filename must be given", }, { "kokubeapply3", - &Hook{"", []string{"foo"}, "", map[string]string{}, []string{}, true, false}, + &Hook{"", []string{"foo"}, "", map[string]string{}, []string{}, true}, "foo", false, "hook[kubectlApply]: either kustomize or filename must be given", }, { "warnkubeapply1", - &Hook{"warnkubeapply1", []string{"foo"}, "ok", map[string]string{"filename": "resource.yaml"}, []string{}, true, false}, + &Hook{"warnkubeapply1", []string{"foo"}, "ok", map[string]string{"filename": "resource.yaml"}, []string{}, true}, "foo", true, "", }, { "warnkubeapply2", - &Hook{"warnkubeapply2", []string{"foo"}, "", map[string]string{"filename": "resource.yaml"}, []string{"ng"}, true, false}, + &Hook{"warnkubeapply2", []string{"foo"}, "", map[string]string{"filename": "resource.yaml"}, []string{"ng"}, true}, "foo", true, "", }, { "warnkubeapply3", - &Hook{"warnkubeapply3", []string{"foo"}, "ok", map[string]string{"filename": "resource.yaml"}, []string{"ng"}, true, false}, + &Hook{"warnkubeapply3", []string{"foo"}, "ok", map[string]string{"filename": "resource.yaml"}, []string{"ng"}, true}, "foo", true, "", diff --git a/pkg/state/state.go b/pkg/state/state.go index 48815202..e880bee9 100644 --- a/pkg/state/state.go +++ b/pkg/state/state.go @@ -19,7 +19,6 @@ import ( "github.com/imdario/mergo" "github.com/variantdev/chartify" - "golang.org/x/exp/slices" "github.com/helmfile/helmfile/pkg/environment" "github.com/helmfile/helmfile/pkg/event" @@ -2266,15 +2265,6 @@ func (st *HelmState) TriggerPreapplyEvent(r *ReleaseSpec, helmfileCommand string func (st *HelmState) triggerReleaseEvent(evt string, evtErr error, r *ReleaseSpec, helmfileCmd string) (bool, error) { - var stateRelease ReleaseSpec - - for id, release := range st.Releases { - if release.Name == r.Name { - stateRelease = st.Releases[id] - break - } - } - bus := &event.Bus{ Hooks: r.Hooks, StateFilePath: st.FilePath, @@ -2292,17 +2282,7 @@ func (st *HelmState) triggerReleaseEvent(evt string, evtErr error, r *ReleaseSpe "HelmfileCommand": helmfileCmd, } - executed, err := bus.Trigger(evt, evtErr, data) - - if executed { - for id, hook := range stateRelease.Hooks { - if slices.Contains(hook.Events, evt) { - stateRelease.Hooks[id].Executed = true - } - } - } - - return executed, err + return bus.Trigger(evt, evtErr, data) } // ResolveDeps returns a copy of this helmfile state with the concrete chart version numbers filled in for remote chart dependencies