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,