allow dependency versions to be overwritten on package update

Signed-off-by: Gregory Hill <greg.hill@monax.io>
pull/7312/head
Gregory Hill 6 years ago
parent 1ff8272748
commit 43ad5e9e9e
No known key found for this signature in database
GPG Key ID: 54841B20DB63C22B

@ -83,13 +83,14 @@ func newPackageCmd(out io.Writer) *cobra.Command {
if client.DependencyUpdate { if client.DependencyUpdate {
downloadManager := &downloader.Manager{ downloadManager := &downloader.Manager{
Out: ioutil.Discard, Out: ioutil.Discard,
ChartPath: path, ChartPath: path,
Keyring: client.Keyring, Keyring: client.Keyring,
Getters: p, Getters: p,
Debug: settings.Debug, Debug: settings.Debug,
RepositoryConfig: settings.RepositoryConfig, DependencyVersions: client.DependencyVersions,
RepositoryCache: settings.RepositoryCache, RepositoryConfig: settings.RepositoryConfig,
RepositoryCache: settings.RepositoryCache,
} }
if err := downloadManager.Update(); err != nil { 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.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.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.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) addValueOptionsFlags(f, valueOpts)
return cmd return cmd

@ -36,13 +36,14 @@ import (
// //
// It provides the implementation of 'helm package'. // It provides the implementation of 'helm package'.
type Package struct { type Package struct {
Sign bool Sign bool
Key string Key string
Keyring string Keyring string
Version string Version string
AppVersion string AppVersion string
Destination string Destination string
DependencyUpdate bool DependencyUpdate bool
DependencyVersions map[string]string
RepositoryConfig string RepositoryConfig string
RepositoryCache string RepositoryCache string
@ -77,6 +78,15 @@ func (p *Package) Run(path string, vals map[string]interface{}) (string, error)
ch.Metadata.AppVersion = p.AppVersion 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 reqs := ch.Metadata.Dependencies; reqs != nil {
if err := CheckDependencies(ch, reqs); err != nil { if err := CheckDependencies(ch, reqs); err != nil {
return "", err return "", err

@ -56,9 +56,11 @@ type Manager struct {
// SkipUpdate indicates that the repository should not be updated first. // SkipUpdate indicates that the repository should not be updated first.
SkipUpdate bool SkipUpdate bool
// Getter collection for the operation // Getter collection for the operation
Getters []getter.Provider Getters []getter.Provider
RepositoryConfig string // DependencyVersions allows us to explicitly set versions
RepositoryCache string DependencyVersions map[string]string
RepositoryConfig string
RepositoryCache string
} }
// Build rebuilds a local charts directory from a lockfile. // Build rebuilds a local charts directory from a lockfile.
@ -123,6 +125,13 @@ func (m *Manager) Update() error {
return nil 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 // Check that all of the repos we're dependent on actually exist and
// the repo index names. // the repo index names.
repoNames, err := m.resolveRepoNames(req) repoNames, err := m.resolveRepoNames(req)

Loading…
Cancel
Save