-
Notifications
You must be signed in to change notification settings - Fork 5k
hyperkit driver should be happy with current minimum verison #9365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
2423f81
d124f29
8ba7478
334779c
11b8534
c82e327
6ca9402
2641e3d
7322fdd
08da827
9b70ec8
786037e
1381394
0a9cbbb
bfca3a6
489b59b
eef3fd8
4eb6f9a
3941018
2b32f6f
63ca225
4c5ac5a
a072e89
8db8f55
57a0e40
5fc73c7
6c65c5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
Copyright 2020 The Kubernetes Authors All rights reserved. | ||
|
||
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 driver | ||
|
||
import ( | ||
"github.com/blang/semver" | ||
"github.com/golang/glog" | ||
) | ||
|
||
// minHyperkitVersion is the minimum version of the minikube hyperkit driver compatible with the current minikube code | ||
var minHyperkitVersion *semver.Version | ||
|
||
const minHyperkitVersionStr = "1.11.0" | ||
|
||
func init() { | ||
v, err := semver.New(minHyperkitVersionStr) | ||
if err != nil { | ||
glog.Errorf("Failed to parse the hyperkit driver version: %v", err) | ||
} else { | ||
minHyperkitVersion = v | ||
} | ||
} | ||
|
||
// minAcceptableDriverVersion is the minimum version of driver supported by current version of minikube | ||
func minAcceptableDriverVersion(driver string, mkVer semver.Version) semver.Version { | ||
switch driver { | ||
case HyperKit: | ||
if minHyperkitVersion != nil { | ||
return *minHyperkitVersion | ||
} | ||
return mkVer | ||
case KVM2: | ||
return mkVer | ||
default: | ||
glog.Warningf("Unexpected driver: %v", driver) | ||
return mkVer | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
Copyright 2020 The Kubernetes Authors All rights reserved. | ||
|
||
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 driver | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/blang/semver" | ||
) | ||
|
||
func Test_minDriverVersion(t *testing.T) { | ||
|
||
tests := []struct { | ||
desc string | ||
driver string | ||
mkV string | ||
want semver.Version | ||
}{ | ||
{"Hyperkit", HyperKit, "1.1.1", *minHyperkitVersion}, | ||
{"Invalid", "_invalid_", "1.1.1", v("1.1.1")}, | ||
{"KVM2", KVM2, "1.1.1", v("1.1.1")}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.desc, func(t *testing.T) { | ||
if got := minAcceptableDriverVersion(tt.driver, v(tt.mkV)); !got.EQ(tt.want) { | ||
t.Errorf("Invalid min supported version, got: %v, want: %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func v(s string) semver.Version { | ||
r, err := semver.New(s) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return *r | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ import ( | |
"github.com/blang/semver" | ||
|
||
"k8s.io/minikube/pkg/minikube/driver" | ||
"k8s.io/minikube/pkg/version" | ||
) | ||
|
||
func TestKVMDriverInstallOrUpdate(t *testing.T) { | ||
|
@@ -173,3 +174,85 @@ func TestHyperKitDriverInstallOrUpdate(t *testing.T) { | |
} | ||
} | ||
} | ||
|
||
func TestHyperKitDriverSkipUpgrade(t *testing.T) { | ||
if runtime.GOOS != "darwin" { | ||
t.Skip("Skip if not darwin.") | ||
} | ||
MaybeParallel(t) | ||
tests := []struct { | ||
name string | ||
path string | ||
downloadExpected bool | ||
}{ | ||
{ | ||
name: "upgrade-v1.11.0-to-current", | ||
path: filepath.Join(*testdataDir, "hyperkit-driver-version-1.11.0"), | ||
downloadExpected: false, | ||
}, | ||
{ | ||
name: "upgrade-v1.2.0-to-current", | ||
path: filepath.Join(*testdataDir, "hyperkit-driver-older-version"), | ||
downloadExpected: true, | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
originalPath := os.Getenv("PATH") | ||
defer func() { | ||
if err := os.Setenv("PATH", originalPath); err != nil { | ||
t.Errorf("failed to restore PATH: %v", err) | ||
} | ||
}() | ||
|
||
dir, err := ioutil.TempDir("", tc.name) | ||
if err != nil { | ||
t.Fatalf("Expected to create tempdir. test: %s, got: %v", tc.name, err) | ||
} | ||
defer func() { | ||
if err := os.RemoveAll(dir); err != nil { | ||
t.Errorf("Failed to remove dir %q: %v", dir, err) | ||
} | ||
}() | ||
|
||
pwd, err := os.Getwd() | ||
if err != nil { | ||
t.Fatalf("Error not expected when getting working directory. test: %s, got: %v", tc.name, err) | ||
} | ||
|
||
driverPath := filepath.Join(pwd, tc.path, "docker-machine-driver-hyperkit") | ||
if _, err = os.Stat(driverPath); err != nil { | ||
t.Fatalf("Expected driver to exist. test: %s, got: %v", tc.name, err) | ||
} | ||
|
||
// change permission to allow driver to be executable | ||
if err = os.Chmod(driverPath, 0700); err != nil { | ||
t.Fatalf("Expected not expected when changing driver permission. test: %s, got: %v", tc.name, err) | ||
} | ||
|
||
if err = os.Setenv("PATH", filepath.Dir(driverPath)); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of setting Env variable for the whole test (that could conflict the other parallel tests)
here is an example here https://github.com/medyagh/minikube/blob/32922f4184c31fb405fb8dab7a1d7a8ef120b47a/test/integration/aaa_download_only_test.go#L170 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
t.Fatalf("Unexpected error on SetEn, got: %v", err) | ||
} | ||
curVersion, err := version.GetSemverVersion() | ||
if err != nil { | ||
t.Fatalf("Expected new semver. test: %v, got: %v", tc.name, err) | ||
} | ||
|
||
if _, err = driver.AssureDriverBinary("hyperkit", dir, curVersion, true); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about instead of using "driver.AssureDriverBinary" use
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really like the idea of running minikube binary instead of just calling internal functions in integration tests. When Another issue is that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have at least one integration test that runs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like my issue is specific to the external drivers only. I tried to forcibly use hyperkit in
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not super familiar with this part of the code, but do you know if we try to set the permissions before asking for root access? My guess is that we don't need a password to set the permissions in our testing environment. If it doesn't already work like this, we could try to set the driver permissions first and then ask for root access if that fails. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, I checked CI scripts, looks like out test environment just allows sudo without a password. Updated the test to skip if sudo needs a password. |
||
t.Fatalf("Failed to update driver to %v. test: %s, got: %v", curVersion, tc.name, err) | ||
} | ||
|
||
_, err = os.Stat(filepath.Join(dir, "docker-machine-driver-hyperkit")) | ||
if tc.downloadExpected { | ||
if err != nil { | ||
t.Fatalf("driver downlad expected. test: %s, got: %v", tc.name, err) | ||
} | ||
} else { | ||
if err == nil { | ||
t.Fatalf("driver downlad NOT expected. test: %s", tc.name) | ||
} | ||
} | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Starting minikube version 1.13.1 we do not update the installed hyperkit driver if its version is 1.11.0 or higher. | ||
Have the hyperkit driver v1.11.0 here to test this behaviour. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that we allow version mismatches, could you please add a log sttatement declaring what driver version we are using? This will help for future debugging;
klog.Infof("%s version is %s", path, driverVersion)
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Done.