Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

a flag to disable downgrade to a minor version #77

Open
github-actions bot opened this issue Jun 16, 2022 · 3 comments
Open

a flag to disable downgrade to a minor version #77

github-actions bot opened this issue Jun 16, 2022 · 3 comments
Labels
bug Something isn't working priority/backlog todo
Milestone

Comments

@github-actions
Copy link

downgrade to a minor version

this is just for test purpose, need to define if it should be supported in the future

// TODO downgrade to a minor version

Copyright 2022 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package operations

import (
	"fmt"

	"k8s.io/apimachinery/pkg/util/version"
)

func upgradeCheck(current, target string) (isSupported, isCrossVersion, canSkip bool) {
	currentVer, err := version.ParseSemantic(current)
	if err != nil {
		return false, false, false
	}
	targetVer, err := version.ParseSemantic(target)
	if err != nil {
		return false, false, false
	}
	return upgradeCheckVersion(currentVer, targetVer)
}

func upgradeCheckVersion(current, target *version.Version) (isSupported, isCrossVersion, canSkip bool) {
	// no need to check major as only major 1 is supported
	// if current.Major() != target.Major() {
	// 	return false
	// }
	if current.Minor() == target.Minor() {
		if current.Patch() == target.Patch() {
			// just skip as the version is the same
			return true, false, true
		}
		// upgrade to a patched version
		return true, false, false
	} else if current.Minor() < target.Minor() {
		if current.Minor()+1 == target.Minor() {
			// upgrade to a minor version
			return true, false, false
		}
		// upgrade multi-minor version, need to split into multiple upgrade tasks
		return true, true, false
	}
	// downgrade is not supported
	if current.Minor()-1 == target.Minor() {
		// TODO downgrade to a minor version
		// this is just for test purpose, need to define if it should be supported in the future
		return true, false, false
	}
	return false, false, false

}

func isSupported(ver string) bool {
	v, err := version.ParseSemantic(ver)
	if err != nil {
		return false
	}
	return isSupportedVersion(v)
}

func isSupportedVersion(ver *version.Version) bool {
	// TODO a table of supported versions needs to be created in the docs
	if ver.Major() != 1 && ver.Minor() < 17 {
		return false
	}
	return true
}

// before this, we should make sure the version is supported
func getCrossVersions(current, target string) []string {
	versions := []string{}
	cur, err := version.ParseSemantic(current)
	if err != nil {
		return versions
	}
	tar, err := version.ParseSemantic(target)
	if err != nil {
		return versions
	}
	_, isCross, _ := upgradeCheckVersion(cur, tar)
	if !isCross {
		return versions
	}
	tarMinor := tar.Minor()
	for i := cur.Minor() + 1; i < tarMinor; i++ {
		versions = append(versions, fmt.Sprintf("v1.%d.0", i))
	}
	return versions
}
ew file mode 100644
ndex 0000000..3d11a78
++ b/operations/version_test.go

f8d06843b70231dc6828b4811100dc36025cff71

@github-actions github-actions bot added the todo label Jun 16, 2022
@pacoxu
Copy link
Owner

pacoxu commented Jun 16, 2022

There may be some unsupported scenarios.

  • for instance, in v1.23 we use the NodeSwap true to use swap. If we downgrade to v1.22, we have to manually disable the swap on servers.

@pacoxu pacoxu added priority/backlog bug Something isn't working labels Jun 16, 2022
@pacoxu
Copy link
Owner

pacoxu commented Jun 16, 2022

The downgrade support is added for testing.

@pacoxu pacoxu added this to the v0.2 milestone Jun 16, 2022
@pacoxu pacoxu changed the title downgrade to a minor version a flag to disable downgrade to a minor version Jun 24, 2022
@pacoxu
Copy link
Owner

pacoxu commented Jun 24, 2022

By default, we should not support it. But it is very useful when upgrade fails and user want to restore to the older version.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working priority/backlog todo
Projects
None yet
Development

No branches or pull requests

1 participant