From 419771c8defbabfb151209bc8f9712aa366977ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20B=C3=A4hler?= Date: Thu, 25 Feb 2021 14:39:02 +0100 Subject: [PATCH] Implement UpdateDependencies function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Oliver Bähler --- cmd/helm/install.go | 17 +---------- .../chart-with-subchart-notes/Chart.lock | 6 ++++ cmd/helm/upgrade.go | 22 ++------------ pkg/action/dependency.go | 29 +++++++++++++++++++ 4 files changed, 38 insertions(+), 36 deletions(-) create mode 100644 cmd/helm/testdata/testcharts/chart-with-subchart-notes/Chart.lock diff --git a/cmd/helm/install.go b/cmd/helm/install.go index fac2131c1..998022a0c 100644 --- a/cmd/helm/install.go +++ b/cmd/helm/install.go @@ -31,7 +31,6 @@ 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/release" ) @@ -215,23 +214,9 @@ func runInstall(args []string, client *action.Install, valueOpts *values.Options // https://github.com/helm/helm/issues/2209 if err := action.CheckDependencies(chartRequested, req); err != nil { if client.DependencyUpdate { - man := &downloader.Manager{ - Out: out, - ChartPath: cp, - Keyring: client.ChartPathOptions.Keyring, - SkipUpdate: false, - Getters: p, - RepositoryConfig: settings.RepositoryConfig, - RepositoryCache: settings.RepositoryCache, - Debug: settings.Debug, - } - if err := man.Update(); err != nil { + if chartRequested, err = action.UpdateDependencies(cp, client.ChartPathOptions.Keyring, settings, out, p); err != nil { return nil, err } - // Reload the chart with the updated Chart.lock file. - if chartRequested, err = loader.Load(cp); err != nil { - return nil, errors.Wrap(err, "failed reloading chart after repo update") - } } else { return nil, err } diff --git a/cmd/helm/testdata/testcharts/chart-with-subchart-notes/Chart.lock b/cmd/helm/testdata/testcharts/chart-with-subchart-notes/Chart.lock new file mode 100644 index 000000000..a3e80d6e5 --- /dev/null +++ b/cmd/helm/testdata/testcharts/chart-with-subchart-notes/Chart.lock @@ -0,0 +1,6 @@ +dependencies: +- name: subchart-with-notes + repository: "" + version: 0.0.1 +digest: sha256:eb038c91a8a689391fdbedd7a1016b2512bc3daee2a11afb7f359ba1341f03c6 +generated: "2021-02-25T14:22:08.359847407+01:00" diff --git a/cmd/helm/upgrade.go b/cmd/helm/upgrade.go index 9e9504b8f..62c079f4a 100644 --- a/cmd/helm/upgrade.go +++ b/cmd/helm/upgrade.go @@ -30,7 +30,6 @@ 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" ) @@ -148,28 +147,11 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { // Only check dependencies if there are any if req := ch.Metadata.Dependencies; req != nil { - // Update all dependencies if DependencyUpdate is true 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, - } - - // reload chart dependencies - if err := man.Update(); err != nil { + // Update all dependencies if DependencyUpdate is true + if ch, err = action.UpdateDependencies(chartPath, client.ChartPathOptions.Keyring, settings, out, p); 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") - } } // If CheckDependencies returns an error, we have unfulfilled dependencies. diff --git a/pkg/action/dependency.go b/pkg/action/dependency.go index 4c80d0159..236223740 100644 --- a/pkg/action/dependency.go +++ b/pkg/action/dependency.go @@ -25,9 +25,13 @@ import ( "github.com/Masterminds/semver/v3" "github.com/gosuri/uitable" + "github.com/pkg/errors" "helm.sh/helm/v3/pkg/chart" "helm.sh/helm/v3/pkg/chart/loader" + "helm.sh/helm/v3/pkg/cli" + "helm.sh/helm/v3/pkg/downloader" + "helm.sh/helm/v3/pkg/getter" ) // Dependency is the action for building a given chart's dependency tree. @@ -225,3 +229,28 @@ func (d *Dependency) printMissing(chartpath string, out io.Writer, reqs []*chart } } } + +// UpdateDependencies update dependency charts. +func UpdateDependencies(chartPath string, keyRing string, settings *cli.EnvSettings, out io.Writer, p getter.Providers) (*chart.Chart, error) { + // Update all dependencies if DependencyUpdate is true + man := &downloader.Manager{ + Out: out, + ChartPath: chartPath, + Keyring: keyRing, + SkipUpdate: false, + Getters: p, + RepositoryConfig: settings.RepositoryConfig, + RepositoryCache: settings.RepositoryCache, + Debug: settings.Debug, + } + // Reload chart dependencies + if err := man.Update(); err != nil { + return nil, err + } + // Reload the chart with the updated Chart.lock file. + ch, err := loader.Load(chartPath) + if err != nil { + return nil, errors.Wrap(err, "failed reloading chart after repo update") + } + return ch, nil +}