From 087331069c2f0619b104d6a5d1b19c8479822bc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mudrini=C4=87?= Date: Wed, 27 Mar 2019 14:42:47 +0100 Subject: [PATCH] Allow upgrade to the same Kubernetes version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marko Mudrinić --- pkg/upgrader/upgrade/preflight_checks.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/upgrader/upgrade/preflight_checks.go b/pkg/upgrader/upgrade/preflight_checks.go index 193adb25e..0729f1db4 100644 --- a/pkg/upgrader/upgrade/preflight_checks.go +++ b/pkg/upgrader/upgrade/preflight_checks.go @@ -83,7 +83,7 @@ func runPreflightChecks(ctx *util.Context) error { } ctx.Logger.Infoln("Verifying is it possible to upgrade to the desired version…") - if err := verifyVersion(ctx.Cluster.Versions.Kubernetes, &nodes, ctx.Verbose); err != nil { + if err := verifyVersion(ctx.Cluster.Versions.Kubernetes, &nodes, ctx.Verbose, ctx.ForceUpgrade); err != nil { return errors.Wrap(err, "unable to verify components version") } @@ -195,7 +195,7 @@ func verifyEndpoints(nodes *corev1.NodeList, hosts []*config.HostConfig, verbose } // verifyVersion verifies is it possible to upgrade to the requested version -func verifyVersion(version string, nodes *corev1.NodeList, verbose bool) error { +func verifyVersion(version string, nodes *corev1.NodeList, verbose, force bool) error { reqVer, err := semver.NewVersion(version) if err != nil { return errors.Wrap(err, "provided version is invalid") @@ -211,8 +211,11 @@ func verifyVersion(version string, nodes *corev1.NodeList, verbose bool) error { fmt.Printf("Requested version: %s", reqVer.String()) } - if reqVer.Compare(kubelet) <= 0 { - return errors.New("unable to upgrade to same or lower version") + if reqVer.Compare(kubelet) < 0 { + return errors.New("unable to upgrade to lower version") + } + if !force && reqVer.Compare(kubelet) == 0 { + return errors.New("unable to upgrade to the same version") } return nil