Fix regression in helmfile deps (#1431)

Fixes #1421
This commit is contained in:
Yusuke Kuoka 2020-08-27 09:22:02 +09:00 committed by GitHub
parent 90a41222e6
commit 14e2b9ed93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 24 deletions

View File

@ -103,7 +103,10 @@ func Init(app *App) *App {
func (a *App) Deps(c DepsConfigProvider) error { func (a *App) Deps(c DepsConfigProvider) error {
return a.ForEachState(func(run *Run) (_ bool, errs []error) { return a.ForEachState(func(run *Run) (_ bool, errs []error) {
prepErr := run.withPreparedCharts(false, c.SkipRepos(), "deps", func() { prepErr := run.withPreparedCharts("deps", state.ChartPrepareOptions{
SkipRepos: c.SkipRepos(),
SkipResolve: true,
}, func() {
errs = run.Deps(c) errs = run.Deps(c)
}) })
@ -119,7 +122,7 @@ func (a *App) Repos(c ReposConfigProvider) error {
return a.ForEachState(func(run *Run) (_ bool, errs []error) { return a.ForEachState(func(run *Run) (_ bool, errs []error) {
var reposErr error var reposErr error
err := run.withPreparedCharts(false, true, "repos", func() { err := run.withPreparedCharts("repos", state.ChartPrepareOptions{SkipRepos: true}, func() {
reposErr = run.Repos(c) reposErr = run.Repos(c)
}) })
@ -137,7 +140,7 @@ func (a *App) Repos(c ReposConfigProvider) error {
func (a *App) DeprecatedSyncCharts(c DeprecatedChartsConfigProvider) error { func (a *App) DeprecatedSyncCharts(c DeprecatedChartsConfigProvider) error {
return a.ForEachState(func(run *Run) (_ bool, errs []error) { return a.ForEachState(func(run *Run) (_ bool, errs []error) {
err := run.withPreparedCharts(false, true, "charts", func() { err := run.withPreparedCharts("charts", state.ChartPrepareOptions{SkipRepos: true}, func() {
errs = run.DeprecatedSyncCharts(c) errs = run.DeprecatedSyncCharts(c)
}) })
@ -163,7 +166,7 @@ func (a *App) Diff(c DiffConfigProvider) error {
var errs []error var errs []error
prepErr := run.withPreparedCharts(false, c.SkipDeps(), "diff", func() { prepErr := run.withPreparedCharts("diff", state.ChartPrepareOptions{SkipRepos: c.SkipDeps()}, func() {
msg, matched, affected, errs = a.diff(run, c) msg, matched, affected, errs = a.diff(run, c)
}) })
@ -218,7 +221,10 @@ func (a *App) Template(c TemplateConfigProvider) error {
return a.ForEachState(func(run *Run) (ok bool, errs []error) { return a.ForEachState(func(run *Run) (ok bool, errs []error) {
// `helm template` in helm v2 does not support local chart. // `helm template` in helm v2 does not support local chart.
// So, we set forceDownload=true for helm v2 only // So, we set forceDownload=true for helm v2 only
prepErr := run.withPreparedCharts(!run.helm.IsHelm3(), c.SkipDeps(), "template", func() { prepErr := run.withPreparedCharts("template", state.ChartPrepareOptions{
ForceDownload: !run.helm.IsHelm3(),
SkipRepos: c.SkipDeps(),
}, func() {
ok, errs = a.template(run, c) ok, errs = a.template(run, c)
}) })
@ -233,7 +239,10 @@ func (a *App) Template(c TemplateConfigProvider) error {
func (a *App) Lint(c LintConfigProvider) error { func (a *App) Lint(c LintConfigProvider) error {
return a.ForEachState(func(run *Run) (_ bool, errs []error) { return a.ForEachState(func(run *Run) (_ bool, errs []error) {
// `helm lint` on helm v2 and v3 does not support remote charts, that we need to set `forceDownload=true` here // `helm lint` on helm v2 and v3 does not support remote charts, that we need to set `forceDownload=true` here
prepErr := run.withPreparedCharts(true, c.SkipDeps(), "lint", func() { prepErr := run.withPreparedCharts("lint", state.ChartPrepareOptions{
ForceDownload: true,
SkipRepos: c.SkipDeps(),
}, func() {
errs = run.Lint(c) errs = run.Lint(c)
}) })
@ -247,7 +256,9 @@ func (a *App) Lint(c LintConfigProvider) error {
func (a *App) Sync(c SyncConfigProvider) error { func (a *App) Sync(c SyncConfigProvider) error {
return a.ForEachState(func(run *Run) (ok bool, errs []error) { return a.ForEachState(func(run *Run) (ok bool, errs []error) {
prepErr := run.withPreparedCharts(false, c.SkipDeps(), "sync", func() { prepErr := run.withPreparedCharts("sync", state.ChartPrepareOptions{
SkipRepos: c.SkipDeps(),
}, func() {
ok, errs = a.sync(run, c) ok, errs = a.sync(run, c)
}) })
@ -269,7 +280,9 @@ func (a *App) Apply(c ApplyConfigProvider) error {
opts = append(opts, SetRetainValuesFiles(c.RetainValuesFiles())) opts = append(opts, SetRetainValuesFiles(c.RetainValuesFiles()))
err := a.ForEachState(func(run *Run) (ok bool, errs []error) { err := a.ForEachState(func(run *Run) (ok bool, errs []error) {
prepErr := run.withPreparedCharts(false, c.SkipDeps(), "apply", func() { prepErr := run.withPreparedCharts("apply", state.ChartPrepareOptions{
SkipRepos: c.SkipDeps(),
}, func() {
matched, updated, es := a.apply(run, c) matched, updated, es := a.apply(run, c)
mut.Lock() mut.Lock()
@ -301,7 +314,9 @@ func (a *App) Apply(c ApplyConfigProvider) error {
func (a *App) Status(c StatusesConfigProvider) error { func (a *App) Status(c StatusesConfigProvider) error {
return a.ForEachState(func(run *Run) (_ bool, errs []error) { return a.ForEachState(func(run *Run) (_ bool, errs []error) {
err := run.withPreparedCharts(false, true, "status", func() { err := run.withPreparedCharts("status", state.ChartPrepareOptions{
SkipRepos: true,
}, func() {
errs = run.Status(c) errs = run.Status(c)
}) })
@ -315,7 +330,9 @@ func (a *App) Status(c StatusesConfigProvider) error {
func (a *App) Delete(c DeleteConfigProvider) error { func (a *App) Delete(c DeleteConfigProvider) error {
return a.ForEachState(func(run *Run) (ok bool, errs []error) { return a.ForEachState(func(run *Run) (ok bool, errs []error) {
err := run.withPreparedCharts(false, true, "delete", func() { err := run.withPreparedCharts("delete", state.ChartPrepareOptions{
SkipRepos: true,
}, func() {
ok, errs = a.delete(run, c.Purge(), c) ok, errs = a.delete(run, c.Purge(), c)
}) })
@ -329,7 +346,9 @@ func (a *App) Delete(c DeleteConfigProvider) error {
func (a *App) Destroy(c DestroyConfigProvider) error { func (a *App) Destroy(c DestroyConfigProvider) error {
return a.ForEachState(func(run *Run) (ok bool, errs []error) { return a.ForEachState(func(run *Run) (ok bool, errs []error) {
err := run.withPreparedCharts(false, true, "destroy", func() { err := run.withPreparedCharts("destroy", state.ChartPrepareOptions{
SkipRepos: true,
}, func() {
ok, errs = a.delete(run, true, c) ok, errs = a.delete(run, true, c)
}) })
@ -349,7 +368,9 @@ func (a *App) Test(c TestConfigProvider) error {
"or set helm.sh/hook-delete-policy\n") "or set helm.sh/hook-delete-policy\n")
} }
err := run.withPreparedCharts(false, true, "test", func() { err := run.withPreparedCharts("test", state.ChartPrepareOptions{
SkipRepos: true,
}, func() {
errs = run.Test(c) errs = run.Test(c)
}) })
@ -363,7 +384,9 @@ func (a *App) Test(c TestConfigProvider) error {
func (a *App) PrintState(c StateConfigProvider) error { func (a *App) PrintState(c StateConfigProvider) error {
return a.ForEachState(func(run *Run) (_ bool, errs []error) { return a.ForEachState(func(run *Run) (_ bool, errs []error) {
err := run.withPreparedCharts(false, true, "build", func() { err := run.withPreparedCharts("build", state.ChartPrepareOptions{
SkipRepos: true,
}, func() {
state, err := run.state.ToYaml() state, err := run.state.ToYaml()
if err != nil { if err != nil {
errs = []error{err} errs = []error{err}
@ -386,7 +409,9 @@ func (a *App) ListReleases(c ListConfigProvider) error {
var releases []*HelmRelease var releases []*HelmRelease
err := a.ForEachState(func(run *Run) (_ bool, errs []error) { err := a.ForEachState(func(run *Run) (_ bool, errs []error) {
err := run.withPreparedCharts(false, true, "list", func() { err := run.withPreparedCharts("list", state.ChartPrepareOptions{
SkipRepos: true,
}, func() {
//var releases m //var releases m
for _, r := range run.state.Releases { for _, r := range run.state.Releases {

View File

@ -36,12 +36,12 @@ func (r *Run) askForConfirmation(msg string) bool {
return AskForConfirmation(msg) return AskForConfirmation(msg)
} }
func (r *Run) withPreparedCharts(forceDownload, skipRepos bool, helmfileCommand string, f func()) error { func (r *Run) withPreparedCharts(helmfileCommand string, opts state.ChartPrepareOptions, f func()) error {
if r.ReleaseToChart != nil { if r.ReleaseToChart != nil {
panic("Run.PrepareCharts can be called only once") panic("Run.PrepareCharts can be called only once")
} }
if !skipRepos { if !opts.SkipRepos {
ctx := r.ctx ctx := r.ctx
if err := ctx.SyncReposOnce(r.state, r.helm); err != nil { if err := ctx.SyncReposOnce(r.state, r.helm); err != nil {
return err return err
@ -59,7 +59,7 @@ func (r *Run) withPreparedCharts(forceDownload, skipRepos bool, helmfileCommand
return err return err
} }
releaseToChart, errs := r.state.PrepareCharts(r.helm, dir, 2, helmfileCommand, forceDownload, skipRepos) releaseToChart, errs := r.state.PrepareCharts(r.helm, dir, 2, helmfileCommand, opts)
if len(errs) > 0 { if len(errs) > 0 {
return fmt.Errorf("%v", errs) return fmt.Errorf("%v", errs)

View File

@ -792,6 +792,12 @@ func releasesNeedCharts(releases []ReleaseSpec) []ReleaseSpec {
return result return result
} }
type ChartPrepareOptions struct {
ForceDownload bool
SkipRepos bool
SkipResolve bool
}
// PrepareCharts creates temporary directories of charts. // PrepareCharts creates temporary directories of charts.
// //
// Each resulting "chart" can be one of the followings: // Each resulting "chart" can be one of the followings:
@ -806,7 +812,7 @@ func releasesNeedCharts(releases []ReleaseSpec) []ReleaseSpec {
// Otheriwse, if a chart is not a helm chart, it will call "chartify" to turn it into a chart. // Otheriwse, if a chart is not a helm chart, it will call "chartify" to turn it into a chart.
// //
// If exists, it will also patch resources by json patches, strategic-merge patches, and injectors. // If exists, it will also patch resources by json patches, strategic-merge patches, and injectors.
func (st *HelmState) PrepareCharts(helm helmexec.Interface, dir string, concurrency int, helmfileCommand string, forceDownload, skipDeps bool) (map[string]string, []error) { func (st *HelmState) PrepareCharts(helm helmexec.Interface, dir string, concurrency int, helmfileCommand string, opts ChartPrepareOptions) (map[string]string, []error) {
releases := releasesNeedCharts(st.Releases) releases := releasesNeedCharts(st.Releases)
temp := make(map[string]string, len(releases)) temp := make(map[string]string, len(releases))
@ -828,11 +834,13 @@ func (st *HelmState) PrepareCharts(helm helmexec.Interface, dir string, concurre
helm3 = helm.IsHelm3() helm3 = helm.IsHelm3()
} }
updated, err := st.ResolveDeps() if !opts.SkipResolve {
if err != nil { updated, err := st.ResolveDeps()
return nil, []error{err} if err != nil {
return nil, []error{err}
}
*st = *updated
} }
*st = *updated
var diagnostics []string var diagnostics []string
@ -916,7 +924,7 @@ func (st *HelmState) PrepareCharts(helm helmexec.Interface, dir string, concurre
// a broken remote chart won't completely block their job. // a broken remote chart won't completely block their job.
chartPath = normalizeChart(st.basePath, chartPath) chartPath = normalizeChart(st.basePath, chartPath)
if !skipDeps { if !opts.SkipRepos {
if err := helm.BuildDeps(release.Name, chartPath); err != nil { if err := helm.BuildDeps(release.Name, chartPath); err != nil {
if chartFetchedByGoGetter { if chartFetchedByGoGetter {
diagnostic = fmt.Sprintf( diagnostic = fmt.Sprintf(
@ -934,7 +942,7 @@ func (st *HelmState) PrepareCharts(helm helmexec.Interface, dir string, concurre
} }
} }
} }
} else if !forceDownload { } else if !opts.ForceDownload {
// At this point, we are sure that either: // At this point, we are sure that either:
// 1. It is a local chart and we can use it in later process (helm upgrade/template/lint/etc) // 1. It is a local chart and we can use it in later process (helm upgrade/template/lint/etc)
// without any modification, or // without any modification, or