Skip to content

Commit 28a1472

Browse files
authored
Merge pull request #5354 from josedonizetti/install-or-update-hyperkit
Automatically install docker-machine-driver-hyperkit if missing or incompatible
2 parents 1d12a36 + 6da3f24 commit 28a1472

File tree

4 files changed

+48
-55
lines changed

4 files changed

+48
-55
lines changed

Diff for: cmd/minikube/cmd/root.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func Execute() {
109109
flag.Usage = translate.T(flag.Usage)
110110
})
111111

112-
if runtime.GOOS == "linux" {
112+
if runtime.GOOS != "windows" {
113113
// add minikube binaries to the path
114114
targetDir := constants.MakeMiniPath("bin")
115115
addToPath(targetDir)

Diff for: cmd/minikube/cmd/start.go

+8-44
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ func runStart(cmd *cobra.Command, args []string) {
289289

290290
validateConfig()
291291
validateUser()
292-
validateDriverVersion(driver)
292+
installOrUpdateDriver(driver)
293293

294294
k8sVersion, isUpgrade := getKubernetesVersion()
295295
config, err := generateCfgFromFlags(cmd, k8sVersion)
@@ -1028,62 +1028,26 @@ func saveConfig(clusterCfg *cfg.Config) error {
10281028
return cfg.CreateProfile(viper.GetString(cfg.MachineProfile), clusterCfg)
10291029
}
10301030

1031-
func validateDriverVersion(vmDriver string) {
1031+
func installOrUpdateDriver(vmDriver string) {
10321032
var driverExecutable string
1033-
driverDocumentation := fmt.Sprintf("%s%s#driver-installation", constants.DriverDocumentation, vmDriver)
1034-
1035-
minikubeVersion, err := version.GetSemverVersion()
1036-
if err != nil {
1037-
out.WarningT("Error parsing minukube version: {{.error}}", out.V{"error": err})
1038-
return
1039-
}
1040-
10411033
switch vmDriver {
10421034
case constants.DriverKvm2:
10431035
driverExecutable = fmt.Sprintf("docker-machine-driver-%s", constants.DriverKvm2)
1044-
targetDir := constants.MakeMiniPath("bin")
1045-
err := drivers.InstallOrUpdate(driverExecutable, targetDir, minikubeVersion)
1046-
if err != nil {
1047-
out.WarningT("Error downloading driver: {{.error}}", out.V{"error": err})
1048-
}
1049-
return
10501036
case constants.DriverHyperkit:
10511037
driverExecutable = fmt.Sprintf("docker-machine-driver-%s", constants.DriverHyperkit)
1052-
default: // driver doesn't support version
1038+
default: // driver doesn't install or update
10531039
return
10541040
}
10551041

1056-
cmd := exec.Command(driverExecutable, "version")
1057-
output, err := cmd.Output()
1058-
1059-
// we don't want to fail if an error was returned,
1060-
// libmachine has a nice message for the user if the driver isn't present
1042+
minikubeVersion, err := version.GetSemverVersion()
10611043
if err != nil {
1062-
out.WarningT("Error checking driver version: {{.error}}", out.V{"error": err})
1044+
out.WarningT("Error parsing minikube version: {{.error}}", out.V{"error": err})
10631045
return
10641046
}
10651047

1066-
v := drivers.ExtractVMDriverVersion(string(output))
1067-
1068-
// if the driver doesn't have return any version, it is really old, we force a upgrade.
1069-
if len(v) == 0 && !viper.GetBool(force) {
1070-
exit.WithCodeT(
1071-
exit.Failure,
1072-
"The installed version of '{{.driver_executable}}' is obsolete. Upgrade: {{.documentation_url}}",
1073-
out.V{"driver_executable": driverExecutable, "documentation_url": driverDocumentation},
1074-
)
1075-
}
1076-
1077-
vmDriverVersion, err := semver.Make(v)
1048+
targetDir := constants.MakeMiniPath("bin")
1049+
err = drivers.InstallOrUpdate(driverExecutable, targetDir, minikubeVersion)
10781050
if err != nil {
1079-
out.WarningT("Error parsing vmDriver version: {{.error}}", out.V{"error": err})
1080-
return
1081-
}
1082-
1083-
if vmDriverVersion.LT(minikubeVersion) {
1084-
out.WarningT(
1085-
"The installed version of '{{.driver_executable}}' ({{.driver_version}}) is no longer current. Upgrade: {{.documentation_url}}",
1086-
out.V{"driver_executable": driverExecutable, "driver_version": vmDriverVersion, "documentation_url": driverDocumentation},
1087-
)
1051+
out.WarningT("Error downloading driver: {{.error}}", out.V{"error": err})
10881052
}
10891053
}

Diff for: pkg/drivers/drivers.go

+39-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package drivers
1818

1919
import (
20+
"fmt"
2021
"io"
2122
"io/ioutil"
2223
"os"
@@ -42,7 +43,8 @@ import (
4243
)
4344

4445
const (
45-
driverKVMDownloadURL = "https://storage.googleapis.com/minikube/releases/latest/docker-machine-driver-kvm2"
46+
driverKVMDownloadURL = "https://storage.googleapis.com/minikube/releases/latest/docker-machine-driver-kvm2"
47+
driverHyperKitDownloadURL = "https://storage.googleapis.com/minikube/releases/latest/docker-machine-driver-hyperkit"
4648
)
4749

4850
// GetDiskPath returns the path of the machine disk image
@@ -187,17 +189,23 @@ func InstallOrUpdate(driver, destination string, minikubeVersion semver.Version)
187189
}
188190

189191
func download(driver, destination string) error {
190-
// only support kvm2 for now
191-
if driver != "docker-machine-driver-kvm2" {
192+
// supports kvm2 and hyperkit
193+
if driver != "docker-machine-driver-kvm2" && driver != "docker-machine-driver-hyperkit" {
192194
return nil
193195
}
194196

195197
out.T(out.Happy, "Downloading driver {{.driver}}:", out.V{"driver": driver})
196198

197-
targetFilepath := path.Join(destination, "docker-machine-driver-kvm2")
199+
targetFilepath := path.Join(destination, driver)
198200
os.Remove(targetFilepath)
199201

200-
url := driverKVMDownloadURL
202+
var url string
203+
switch driver {
204+
case "docker-machine-driver-kvm2":
205+
url = driverKVMDownloadURL
206+
case "docker-machine-driver-hyperkit":
207+
url = driverHyperKitDownloadURL
208+
}
201209

202210
opts := []getter.ClientOption{getter.WithProgress(util.DefaultProgressBar)}
203211
client := &getter.Client{
@@ -216,6 +224,13 @@ func download(driver, destination string) error {
216224
return errors.Wrap(err, "chmod error")
217225
}
218226

227+
if driver == "docker-machine-driver-hyperkit" {
228+
err := setHyperKitPermissions(targetFilepath)
229+
if err != nil {
230+
return errors.Wrap(err, "setting hyperkit permission")
231+
}
232+
}
233+
219234
return nil
220235
}
221236

@@ -235,3 +250,22 @@ func ExtractVMDriverVersion(s string) string {
235250
v := strings.TrimSpace(matches[1])
236251
return strings.TrimPrefix(v, version.VersionPrefix)
237252
}
253+
254+
func setHyperKitPermissions(driverPath string) error {
255+
msg := fmt.Sprintf("A new hyperkit driver was installed. It needs elevated permissions to run. The following commands will be executed\nsudo chown root:wheel %s\nsudo chmod u+s %s", driverPath, driverPath)
256+
out.T(out.Happy, msg, out.V{})
257+
258+
cmd := exec.Command("sudo", "chown", "root:wheel", driverPath)
259+
err := cmd.Run()
260+
if err != nil {
261+
return errors.Wrap(err, "chown root:wheel")
262+
}
263+
264+
cmd = exec.Command("sudo", "chmod", "u+s", driverPath)
265+
err = cmd.Run()
266+
if err != nil {
267+
return errors.Wrap(err, "chmod u+s")
268+
}
269+
270+
return nil
271+
}

Diff for: pkg/minikube/constants/constants.go

-5
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,3 @@ const (
374374
// GvisorURL is the url to download gvisor
375375
GvisorURL = "https://storage.googleapis.com/gvisor/releases/nightly/2019-01-14/runsc"
376376
)
377-
378-
const (
379-
// DriverDocumentation the documentation of the KVM driver
380-
DriverDocumentation = "https://minikube.sigs.k8s.io/docs/reference/drivers/"
381-
)

0 commit comments

Comments
 (0)