From 43ad5e9e9e7d51bfcf37b5359eb7ceeb13e1e66c Mon Sep 17 00:00:00 2001 From: Gregory Hill Date: Mon, 30 Dec 2019 17:37:32 +0000 Subject: [PATCH] allow dependency versions to be overwritten on package update Signed-off-by: Gregory Hill --- cmd/helm/package.go | 16 +++++++++------- pkg/action/package.go | 24 +++++++++++++++++------- pkg/downloader/manager.go | 15 ++++++++++++--- 3 files changed, 38 insertions(+), 17 deletions(-) diff --git a/cmd/helm/package.go b/cmd/helm/package.go index 9f7961f95..270ada335 100644 --- a/cmd/helm/package.go +++ b/cmd/helm/package.go @@ -83,13 +83,14 @@ func newPackageCmd(out io.Writer) *cobra.Command { if client.DependencyUpdate { downloadManager := &downloader.Manager{ - Out: ioutil.Discard, - ChartPath: path, - Keyring: client.Keyring, - Getters: p, - Debug: settings.Debug, - RepositoryConfig: settings.RepositoryConfig, - RepositoryCache: settings.RepositoryCache, + Out: ioutil.Discard, + ChartPath: path, + Keyring: client.Keyring, + Getters: p, + Debug: settings.Debug, + DependencyVersions: client.DependencyVersions, + RepositoryConfig: settings.RepositoryConfig, + RepositoryCache: settings.RepositoryCache, } if err := downloadManager.Update(); err != nil { @@ -114,6 +115,7 @@ func newPackageCmd(out io.Writer) *cobra.Command { f.StringVar(&client.AppVersion, "app-version", "", "set the appVersion on the chart to this version") f.StringVarP(&client.Destination, "destination", "d", ".", "location to write the chart.") f.BoolVarP(&client.DependencyUpdate, "dependency-update", "u", false, `update dependencies from "Chart.yaml" to dir "charts/" before packaging`) + f.StringToStringVar(&client.DependencyVersions, "set-dependency-version", make(map[string]string), "set dependency versions. Used if --dependency-update is true") addValueOptionsFlags(f, valueOpts) return cmd diff --git a/pkg/action/package.go b/pkg/action/package.go index 5c85ebe0d..5ad06da45 100644 --- a/pkg/action/package.go +++ b/pkg/action/package.go @@ -36,13 +36,14 @@ import ( // // It provides the implementation of 'helm package'. type Package struct { - Sign bool - Key string - Keyring string - Version string - AppVersion string - Destination string - DependencyUpdate bool + Sign bool + Key string + Keyring string + Version string + AppVersion string + Destination string + DependencyUpdate bool + DependencyVersions map[string]string RepositoryConfig string RepositoryCache string @@ -77,6 +78,15 @@ func (p *Package) Run(path string, vals map[string]interface{}) (string, error) ch.Metadata.AppVersion = p.AppVersion } + if p.DependencyUpdate { + // only alter these upon successful update + for _, d := range ch.Metadata.Dependencies { + if v, ok := p.DependencyVersions[d.Name]; ok { + d.Version = v + } + } + } + if reqs := ch.Metadata.Dependencies; reqs != nil { if err := CheckDependencies(ch, reqs); err != nil { return "", err diff --git a/pkg/downloader/manager.go b/pkg/downloader/manager.go index e46af6944..4321ec446 100644 --- a/pkg/downloader/manager.go +++ b/pkg/downloader/manager.go @@ -56,9 +56,11 @@ type Manager struct { // SkipUpdate indicates that the repository should not be updated first. SkipUpdate bool // Getter collection for the operation - Getters []getter.Provider - RepositoryConfig string - RepositoryCache string + Getters []getter.Provider + // DependencyVersions allows us to explicitly set versions + DependencyVersions map[string]string + RepositoryConfig string + RepositoryCache string } // Build rebuilds a local charts directory from a lockfile. @@ -123,6 +125,13 @@ func (m *Manager) Update() error { return nil } + // Allow dependency versions to be overwritten. + for _, d := range c.Metadata.Dependencies { + if v, ok := m.DependencyVersions[d.Name]; ok { + d.Version = v + } + } + // Check that all of the repos we're dependent on actually exist and // the repo index names. repoNames, err := m.resolveRepoNames(req)