Skip to content

Commit

Permalink
Allow upgrade to the same Kubernetes version
Browse files Browse the repository at this point in the history
Signed-off-by: Marko Mudrinić <mudrinic.mare@gmail.com>
  • Loading branch information
xmudrii committed Mar 27, 2019
1 parent 1ff3cdc commit 0873310
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pkg/upgrader/upgrade/preflight_checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -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")
Expand All @@ -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
Expand Down

0 comments on commit 0873310

Please sign in to comment.