Skip to content

Commit

Permalink
fix(cli): Make upgrade check if cluster reachable
Browse files Browse the repository at this point in the history
The 'helm upgrade' command was not checking if the cluster was reachable.
Also, 'helm upgrade --install' first checks if the release exists
already.  If that check fails there is no point in continuing the
upgrade.  This optimization avoids a second timeout of 30 seconds when
trying to do the upgrade.

Signed-off-by: Marc Khouzam <[email protected]>
  • Loading branch information
marckhouzam authored and wawa0210 committed Mar 14, 2020
1 parent f5b7efb commit b9005ea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cmd/helm/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
}

if client.Install {
// If a release does not exist, install it. If another error occurs during
// the check, ignore the error and continue with the upgrade.
// If a release does not exist, install it.
histClient := action.NewHistory(cfg)
histClient.Max = 1
if _, err := histClient.Run(args[0]); err == driver.ErrReleaseNotFound {
Expand All @@ -119,6 +118,8 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
return err
}
return outfmt.Write(out, &statusPrinter{rel, settings.Debug})
} else if err != nil {
return err
}
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/action/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ func NewUpgrade(cfg *Configuration) *Upgrade {

// Run executes the upgrade on the given release.
func (u *Upgrade) Run(name string, chart *chart.Chart, vals map[string]interface{}) (*release.Release, error) {
if err := u.cfg.KubeClient.IsReachable(); err != nil {
return nil, err
}

// Make sure if Atomic is set, that wait is set as well. This makes it so
// the user doesn't have to specify both
u.Wait = u.Wait || u.Atomic
Expand Down

0 comments on commit b9005ea

Please sign in to comment.