From d6eab468762e4020b49d1852de5b2df53f194eb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Ml=C3=A1dek?= Date: Wed, 28 Apr 2021 22:22:28 +0200 Subject: [PATCH] Add --udpate-dependencies to upgrade command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: David Mládek --- cmd/helm/upgrade.go | 27 +++++++++++++++++++++++++-- pkg/action/upgrade.go | 2 ++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/cmd/helm/upgrade.go b/cmd/helm/upgrade.go index 1952b8421..3bd392d1d 100644 --- a/cmd/helm/upgrade.go +++ b/cmd/helm/upgrade.go @@ -30,6 +30,7 @@ import ( "helm.sh/helm/v3/pkg/chart/loader" "helm.sh/helm/v3/pkg/cli/output" "helm.sh/helm/v3/pkg/cli/values" + "helm.sh/helm/v3/pkg/downloader" "helm.sh/helm/v3/pkg/getter" "helm.sh/helm/v3/pkg/storage/driver" ) @@ -132,7 +133,8 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { return err } - vals, err := valueOpts.MergeValues(getter.All(settings)) + p := getter.All(settings) + vals, err := valueOpts.MergeValues(p) if err != nil { return err } @@ -144,7 +146,27 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { } if req := ch.Metadata.Dependencies; req != nil { if err := action.CheckDependencies(ch, req); err != nil { - return err + if client.DependencyUpdate { + man := &downloader.Manager{ + Out: out, + ChartPath: chartPath, + Keyring: client.ChartPathOptions.Keyring, + SkipUpdate: false, + Getters: p, + RepositoryConfig: settings.RepositoryConfig, + RepositoryCache: settings.RepositoryCache, + Debug: settings.Debug, + } + if err := man.Update(); err != nil { + return err + } + // Reload the chart with the updated Chart.lock file. + if ch, err = loader.Load(chartPath); err != nil { + return errors.Wrap(err, "failed reloading chart after repo update") + } + } else { + return err + } } } @@ -186,6 +208,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { f.BoolVar(&client.CleanupOnFail, "cleanup-on-fail", false, "allow deletion of new resources created in this upgrade when upgrade fails") f.BoolVar(&client.SubNotes, "render-subchart-notes", false, "if set, render subchart notes along with the parent") f.StringVar(&client.Description, "description", "", "add a custom description") + f.BoolVar(&client.DependencyUpdate, "dependency-update", false, "update dependencies if they are missing before installing the chart") addChartPathOptionsFlags(f, &client.ChartPathOptions) addValueOptionsFlags(f, valueOpts) bindOutputFlag(cmd, &outfmt) diff --git a/pkg/action/upgrade.go b/pkg/action/upgrade.go index 3b3dd3f1c..07d9cb40e 100644 --- a/pkg/action/upgrade.go +++ b/pkg/action/upgrade.go @@ -98,6 +98,8 @@ type Upgrade struct { PostRenderer postrender.PostRenderer // DisableOpenAPIValidation controls whether OpenAPI validation is enforced. DisableOpenAPIValidation bool + // Get missing dependencies + DependencyUpdate bool } // NewUpgrade creates a new Upgrade object with the given configuration.