Fixes for updates from rebase

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 fcdd852153
commit f0b76e9e26
6 changed files with 37 additions and 17 deletions
+31 -1
View File
@@ -15,6 +15,7 @@ import (
"github.com/variantdev/vals"
"go.uber.org/zap"
"golang.org/x/exp/slices"
"github.com/helmfile/helmfile/pkg/argparser"
"github.com/helmfile/helmfile/pkg/filesystem"
@@ -1359,7 +1360,7 @@ Do you really want to apply?
for _, release := range releasesWithPreApply {
a.Logger.Infof("\nRunning preapply hook for %s:", release.Name)
if _, err := st.TriggerPreapplyEvent(&release, "apply"); err != nil {
syncErrs = append(syncErrs, err)
applyErrs = append(applyErrs, err)
continue
}
}
@@ -1420,6 +1421,35 @@ Do you really want to apply?
return true, true, applyErrs
}
func getReleasesWithPreApply(releases []state.ReleaseSpec) []state.ReleaseSpec {
var releasesWithPreApply []state.ReleaseSpec
for _, r := range releases {
release := r
for _, hook := range release.Hooks {
if slices.Contains(hook.Events, "preapply") {
releasesWithPreApply = append(releasesWithPreApply, release)
break
}
}
}
return releasesWithPreApply
}
func preApplyInfoMsg(releasesWithPreApply []state.ReleaseSpec, infoMsg *string) *string {
if len(releasesWithPreApply) > 0 {
msg := "Releases with preapply hooks: \n"
if infoMsg != nil {
msg = fmt.Sprintf("%s\n%s", *infoMsg, msg)
}
infoMsg = &msg
}
for _, release := range releasesWithPreApply {
tmp := fmt.Sprintf("%s %s (%s)\n", *infoMsg, release.Name, release.Chart)
infoMsg = &tmp
}
return infoMsg
}
func (a *App) delete(r *Run, purge bool, c DestroyConfigProvider) (bool, []error) {
st := r.state
helm := r.helm
-3
View File
@@ -4,7 +4,6 @@ import (
"bufio"
"bytes"
"io"
"path/filepath"
"sync"
"testing"
@@ -94,8 +93,6 @@ func TestApply_hooks(t *testing.T) {
app := appWithFs(&App{
OverrideHelmBinary: DefaultHelmBinary,
glob: filepath.Glob,
abs: filepath.Abs,
OverrideKubeContext: "default",
Env: "default",
Logger: logger,
+1 -2
View File
@@ -10,7 +10,6 @@ import (
"github.com/helmfile/helmfile/pkg/filesystem"
"github.com/helmfile/helmfile/pkg/helmexec"
"github.com/helmfile/helmfile/pkg/tmpl"
"go.uber.org/zap"
)
type Hook struct {
@@ -89,7 +88,7 @@ func (bus *Bus) Trigger(evt string, evtErr error, context map[string]interface{}
}
}
bus.Logger.Debugf("hook[%s]: stateFilePath=%s, basePath=%s", name, bus.StateFilePath, bus.BasePath)
bus.Logger.Debugf("hook[%s]: stateFilePath=%s, basePath=%s\n", name, bus.StateFilePath, bus.BasePath)
data := map[string]interface{}{
"Environment": bus.Env,
+1 -8
View File
@@ -18,10 +18,10 @@ import (
"text/template"
"github.com/imdario/mergo"
"github.com/variantdev/chartify"
"github.com/helmfile/helmfile/pkg/environment"
"github.com/helmfile/helmfile/pkg/event"
"github.com/helmfile/helmfile/pkg/filesystem"
"github.com/helmfile/helmfile/pkg/helmexec"
"github.com/helmfile/helmfile/pkg/remote"
"github.com/helmfile/helmfile/pkg/tmpl"
@@ -31,13 +31,6 @@ import (
"github.com/variantdev/vals"
"go.uber.org/zap"
"gopkg.in/yaml.v2"
"github.com/helmfile/helmfile/pkg/environment"
"github.com/helmfile/helmfile/pkg/event"
"github.com/helmfile/helmfile/pkg/filesystem"
"github.com/helmfile/helmfile/pkg/helmexec"
"github.com/helmfile/helmfile/pkg/remote"
"github.com/helmfile/helmfile/pkg/tmpl"
)
const (