Skip to content

Commit

Permalink
Allow upgrade to the same Kubernetes version (#315)
Browse files Browse the repository at this point in the history
Signed-off-by: Marko Mudrinić <mudrinic.mare@gmail.com>
  • Loading branch information
xmudrii authored and kubermatic-bot committed Mar 29, 2019
1 parent 5206a8c commit 78ea337
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions pkg/upgrader/upgrade/preflight_checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/Masterminds/semver"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"

"github.com/kubermatic/kubeone/pkg/config"
"github.com/kubermatic/kubeone/pkg/ssh"
Expand Down Expand Up @@ -83,7 +84,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.Logger, ctx.Cluster.Versions.Kubernetes, &nodes, ctx.Verbose, ctx.ForceUpgrade); err != nil {
return errors.Wrap(err, "unable to verify components version")
}

Expand Down Expand Up @@ -195,7 +196,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(logger logrus.FieldLogger, 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")
Expand All @@ -211,8 +212,15 @@ 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 reqVer.Compare(kubelet) == 0 {
if force {
logger.Warningf("upgrading to the same kubernetes version")
return nil
}
return errors.New("unable to upgrade to the same version")
}

return nil
Expand Down

0 comments on commit 78ea337

Please sign in to comment.