Remove logic that limits execution of hooks to only once

Signed-off-by: Anton Bretting <sajfer@gmail.com>
This commit is contained in:
Anton Bretting
2022-09-19 08:55:44 +09:00
committed by Yusuke Kuoka
parent 32477e6cf2
commit c6e8afd3d0
4 changed files with 16 additions and 41 deletions
-6
View File
@@ -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)
+13 -13
View File
@@ -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,
"",