Skip to content

Commit

Permalink
feat(helm): add --app-version flag to 'helm install/upgrade'
Browse files Browse the repository at this point in the history
When 'helm install/upgrade --app-version 1.0.0' is run, this will
override the chart app version

Closes helm#3555

Signed-off-by: Kevin Labesse <kevin@labesse.me>

docs(helm): add --app-version flags for 'helm install/upgrade'

Signed-off-by: Kevin Labesse <kevin@labesse.me>
  • Loading branch information
eraac committed Nov 28, 2018
1 parent d3357fa commit 8ddaa4e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
6 changes: 6 additions & 0 deletions cmd/helm/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ type installCmd struct {
fileValues []string
nameTemplate string
version string
appVersion string
timeout int64
wait bool
repoURL string
Expand Down Expand Up @@ -209,6 +210,7 @@ func newInstallCmd(c helm.Interface, out io.Writer) *cobra.Command {
f.BoolVar(&inst.verify, "verify", false, "verify the package before installing it")
f.StringVar(&inst.keyring, "keyring", defaultKeyring(), "location of public keys used for verification")
f.StringVar(&inst.version, "version", "", "specify the exact chart version to install. If this is not specified, the latest version is installed")
f.StringVar(&inst.appVersion, "app-version", "", "specify an app version for the release")
f.Int64Var(&inst.timeout, "timeout", 300, "time in seconds to wait for any individual Kubernetes operation (like Jobs for hooks)")
f.BoolVar(&inst.wait, "wait", false, "if set, will wait until all Pods, PVCs, Services, and minimum number of Pods of a Deployment are in a ready state before marking the release as successful. It will wait for as long as --timeout")
f.StringVar(&inst.repoURL, "repo", "", "chart repository url where to locate the requested chart")
Expand Down Expand Up @@ -291,6 +293,10 @@ func (i *installCmd) run() error {
return fmt.Errorf("cannot load requirements: %v", err)
}

if i.appVersion != "" {
chartRequested.Metadata.AppVersion = i.appVersion
}

res, err := i.client.InstallReleaseFromChart(
chartRequested,
i.namespace,
Expand Down
31 changes: 20 additions & 11 deletions cmd/helm/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ type upgradeCmd struct {
install bool
namespace string
version string
appVersion string
timeout int64
resetValues bool
reuseValues bool
Expand Down Expand Up @@ -162,6 +163,7 @@ func newUpgradeCmd(client helm.Interface, out io.Writer) *cobra.Command {
f.BoolVarP(&upgrade.install, "install", "i", false, "if a release by this name doesn't already exist, run an install")
f.StringVar(&upgrade.namespace, "namespace", "", "namespace to install the release into (only used if --install is set). Defaults to the current kube config namespace")
f.StringVar(&upgrade.version, "version", "", "specify the exact chart version to use. If this is not specified, the latest version is used")
f.StringVar(&upgrade.appVersion, "app-version", "", "specify the app version to use for the upgrade")
f.Int64Var(&upgrade.timeout, "timeout", 300, "time in seconds to wait for any individual Kubernetes operation (like Jobs for hooks)")
f.BoolVar(&upgrade.resetValues, "reset-values", false, "when upgrading, reset the values to the ones built into the chart")
f.BoolVar(&upgrade.reuseValues, "reuse-values", false, "when upgrading, reuse the last release's values and merge in any overrides from the command line via --set and -f. If '--reset-values' is specified, this is ignored.")
Expand Down Expand Up @@ -227,6 +229,7 @@ func (u *upgradeCmd) run() error {
stringValues: u.stringValues,
fileValues: u.fileValues,
namespace: u.namespace,
appVersion: u.appVersion,
timeout: u.timeout,
wait: u.wait,
description: u.description,
Expand All @@ -240,22 +243,28 @@ func (u *upgradeCmd) run() error {
return err
}

// load the chart to update
chart, err := chartutil.Load(chartPath)
if err != nil {
return prettyError(err)
}

// Check chart requirements to make sure all dependencies are present in /charts
if ch, err := chartutil.Load(chartPath); err == nil {
if req, err := chartutil.LoadRequirements(ch); err == nil {
if err := renderutil.CheckDependencies(ch, req); err != nil {
return err
}
} else if err != chartutil.ErrRequirementsNotFound {
return fmt.Errorf("cannot load requirements: %v", err)
if req, err := chartutil.LoadRequirements(chart); err == nil {
if err := renderutil.CheckDependencies(chart, req); err != nil {
return err
}
} else {
return prettyError(err)
} else if err != chartutil.ErrRequirementsNotFound {
return fmt.Errorf("cannot load requirements: %v", err)
}

if u.appVersion != "" {
chart.Metadata.AppVersion = u.appVersion
}

resp, err := u.client.UpdateRelease(
resp, err := u.client.UpdateReleaseFromChart(
u.release,
chartPath,
chart,
helm.UpdateValueOverrides(rawVals),
helm.UpgradeDryRun(u.dryRun),
helm.UpgradeRecreate(u.recreate),
Expand Down
3 changes: 2 additions & 1 deletion docs/helm/helm_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ helm install [CHART] [flags]
### Options

```
--app-version string specify an app version for the release
--ca-file string verify certificates of HTTPS-enabled servers using this CA bundle
--cert-file string identify HTTPS client using this SSL certificate file
--dep-up run helm dependency update before installing the chart
Expand Down Expand Up @@ -128,4 +129,4 @@ helm install [CHART] [flags]

* [helm](helm.md) - The Helm package manager for Kubernetes.

###### Auto generated by spf13/cobra on 10-Aug-2018
###### Auto generated by spf13/cobra on 22-Nov-2018
3 changes: 2 additions & 1 deletion docs/helm/helm_upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ helm upgrade [RELEASE] [CHART] [flags]
### Options

```
--app-version string specify the app version to use for the upgrade
--ca-file string verify certificates of HTTPS-enabled servers using this CA bundle
--cert-file string identify HTTPS client using this SSL certificate file
--description string specify the description to use for the upgrade, rather than the default
Expand Down Expand Up @@ -115,4 +116,4 @@ helm upgrade [RELEASE] [CHART] [flags]

* [helm](helm.md) - The Helm package manager for Kubernetes.

###### Auto generated by spf13/cobra on 24-Aug-2018
###### Auto generated by spf13/cobra on 22-Nov-2018

0 comments on commit 8ddaa4e

Please sign in to comment.