From 22b7562c62c2fc0cc89f568755f0c2e09106c0ab Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Thu, 12 Mar 2020 12:16:21 -0400 Subject: [PATCH] fix(cli): Make upgrade check if cluster reachable 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 --- cmd/helm/upgrade.go | 5 +++-- pkg/action/upgrade.go | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/helm/upgrade.go b/cmd/helm/upgrade.go index 53aef7af7..af8ff68e3 100644 --- a/cmd/helm/upgrade.go +++ b/cmd/helm/upgrade.go @@ -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 { @@ -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 } } diff --git a/pkg/action/upgrade.go b/pkg/action/upgrade.go index 62e26adb4..fabba9af4 100644 --- a/pkg/action/upgrade.go +++ b/pkg/action/upgrade.go @@ -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