提交 f9d47627 编写于 作者: K Kenta Iso

Improve hyperkit specific version check

上级 fcbf4d1b
......@@ -24,8 +24,6 @@ ISO_VERSION ?= v$(VERSION_MAJOR).$(VERSION_MINOR).0
# Dashes are valid in semver, but not Linux packaging. Use ~ to delimit alpha/beta
DEB_VERSION ?= $(subst -,~,$(RAW_VERSION))
RPM_VERSION ?= $(DEB_VERSION)
# used by hyperkit versionCheck(whether user's hyperkit is older than this)
HYPERKIT_VERSION ?= 0.20190201
# used by hack/jenkins/release_build_and_upload.sh and KVM_BUILD_IMAGE, see also BUILD_IMAGE below
GO_VERSION ?= 1.13.4
......@@ -84,7 +82,7 @@ SHA512SUM=$(shell command -v sha512sum || echo "shasum -a 512")
STORAGE_PROVISIONER_TAG := v1.8.1
# Set the version information for the Kubernetes servers
MINIKUBE_LDFLAGS := -X k8s.io/minikube/pkg/version.version=$(VERSION) -X k8s.io/minikube/pkg/version.isoVersion=$(ISO_VERSION) -X k8s.io/minikube/pkg/version.isoPath=$(ISO_BUCKET) -X k8s.io/minikube/pkg/version.gitCommitID=$(COMMIT) -X k8s.io/minikube/pkg/version.hyperKitVersion=$(HYPERKIT_VERSION)
MINIKUBE_LDFLAGS := -X k8s.io/minikube/pkg/version.version=$(VERSION) -X k8s.io/minikube/pkg/version.isoVersion=$(ISO_VERSION) -X k8s.io/minikube/pkg/version.isoPath=$(ISO_BUCKET) -X k8s.io/minikube/pkg/version.gitCommitID=$(COMMIT)
PROVISIONER_LDFLAGS := "$(MINIKUBE_LDFLAGS) -s -w"
MINIKUBEFILES := ./cmd/minikube/
......
......@@ -33,13 +33,17 @@ import (
"k8s.io/minikube/pkg/minikube/driver"
"k8s.io/minikube/pkg/minikube/localpath"
"k8s.io/minikube/pkg/minikube/registry"
"k8s.io/minikube/pkg/version"
)
const (
docURL = "https://minikube.sigs.k8s.io/docs/reference/drivers/hyperkit/"
)
var (
// hyperkitSpecificVersion is used by hyperkit versionCheck(whether user's hyperkit is older than this)
hyperkitSpecificVersion = "0.20190201"
)
func init() {
if err := registry.Register(registry.DriverDef{
Name: driver.HyperKit,
......@@ -89,34 +93,40 @@ func status() registry.State {
}
// Split version from v0.YYYYMMDD-HH-xxxxxxx or 0.YYYYMMDD to YYYYMMDD
specificVersion := splitHyperKitVersion(version.GetHyperKitVersion())
currentVersion := convertVersionToDate(string(out))
specificVersion := splitHyperKitVersion(GetHyperKitVersion())
// If hyperkit is not newer than specificVersion, suggest upgrade information
isNew := isNewerVersion(convertVersionToDate(string(out)), specificVersion)
isNew, err := isNewerVersion(currentVersion, specificVersion)
if err != nil {
return registry.State{Installed: true, Error: fmt.Errorf("hyperkit version check failed:\n%s", err), Doc: docURL}
}
if !isNew {
return registry.State{Installed: true, Error: fmt.Errorf("%s is too old. the higher than %s is needed", "hyperkit version", version.GetHyperKitVersion()), Fix: "Run 'brew upgrade hyperkit' or Upgrade Docker for Desktop version", Doc: docURL}
return registry.State{Installed: true, Error: fmt.Errorf("the mininum recommended hyperkit version is %s. your hyperkit version is 0.%s. please consider upgrading your hyperkit", GetHyperKitVersion(), currentVersion), Fix: "Run 'brew upgrade hyperkit'", Doc: docURL}
}
return registry.State{Installed: true, Healthy: true}
}
// isNewerVersion checks whether current hyperkit is newer than specific version
func isNewerVersion(currentVersion string, specificVersion string) bool {
func isNewerVersion(currentVersion string, specificVersion string) (bool, error) {
// Convert hyperkit version to time.Date to compare whether hyperkit version is not old.
layout := "20060102"
currentVersionDate, err := time.Parse(layout, currentVersion)
if err != nil {
glog.Warningf("Unable to parse to time.Date: %v", err)
return false, err
}
specificVersionDate, err := time.Parse(layout, specificVersion)
if err != nil {
glog.Warningf("Unable to parse to time.Date: %v", err)
return false, err
}
// If currentVersionDate is equal to specificVersionDate, no need to upgrade hyperkit
if currentVersionDate.Equal(specificVersionDate) {
return true
return true, nil
}
// If currentVersionDate is after specificVersionDate, return true
return currentVersionDate.After(specificVersionDate)
return currentVersionDate.After(specificVersionDate), nil
}
// convertVersionToDate returns current hyperkit version
......@@ -134,11 +144,18 @@ func convertVersionToDate(hyperKitVersionOutput string) string {
// splitHyperKitVersion splits version from v0.YYYYMMDD-HH-xxxxxxx or 0.YYYYMMDD to YYYYMMDD
func splitHyperKitVersion(version string) string {
// Cut off like "20190201-11-gc0dd46" or "20190201"
version = strings.Split(version, ".")[1]
if strings.Contains(version, ".") {
// Cut off like "20190201-11-gc0dd46" or "20190201"
version = strings.Split(version, ".")[1]
}
if len(version) >= 8 {
// Format to "20190201"
version = version[:8]
}
return version
}
// GetHyperKitVersion returns the specific hyperKit version
func GetHyperKitVersion() string {
return hyperkitSpecificVersion
}
......@@ -39,6 +39,11 @@ func TestSplitHyperKitVersion(t *testing.T) {
version: "0.20190201",
expect: "20190201",
},
{
desc: "non split YYYYMMDD output to YYYYMMDD format",
version: "20190201",
expect: "20190201",
},
{
desc: "split semver output to YYYYMMDD format",
version: "v1.0.0",
......@@ -111,7 +116,10 @@ func TestIsNewerVersion(t *testing.T) {
}
for _, test := range tc {
t.Run(test.desc, func(t *testing.T) {
isNew := isNewerVersion(test.currentVersion, test.specificVersion)
isNew, err := isNewerVersion(test.currentVersion, test.specificVersion)
if err != nil {
t.Fatalf("Got unexpected error %v", err)
}
if isNew != test.isNew {
t.Fatalf("Error %v expected but result %v", test.isNew, isNew)
}
......
......@@ -38,9 +38,6 @@ var isoVersion = "v0.0.0-unset"
var isoPath = "minikube/iso"
// hyperKitVersion is a private field and should be set when compiling with --ldflags="-X k8s.io/minikube/pkg/version.hyperKitVersion=v0.YYYYMMDD"
var hyperKitVersion = "v0.20000101-unset"
// GetVersion returns the current minikube version
func GetVersion() string {
return version
......@@ -61,11 +58,6 @@ func GetISOPath() string {
return isoPath
}
// GetHyperKitVersion returns the specific hyperKit version
func GetHyperKitVersion() string {
return hyperKitVersion
}
// GetSemverVersion returns the current minikube semantic version (semver)
func GetSemverVersion() (semver.Version, error) {
return semver.Make(strings.TrimPrefix(GetVersion(), VersionPrefix))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册