Skip to content
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

WIP: Add minikube support for the "generic" VM driver #6873

Closed
wants to merge 8 commits into from
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func deleteProfile(profile *config.Profile) error {
return DeletionError{Err: delErr, Errtype: MissingProfile}
}

if err == nil && driver.BareMetal(cc.Driver) {
if err == nil && (driver.BareMetal(cc.Driver) || cc.Driver == driver.Generic) {
if err := uninstallKubernetes(api, *cc, cc.Nodes[0], viper.GetString(cmdcfg.Bootstrapper)); err != nil {
deletionError, ok := err.(DeletionError)
if ok {
Expand Down
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func provisionWithDriver(cmd *cobra.Command, ds registry.DriverState, existing *
os.Exit(0)
}

if driver.IsVM(driverName) {
if driver.IsVM(driverName) && driverName != driver.Generic {
url, err := download.ISO(viper.GetStringSlice(isoURL), cmd.Flags().Changed(isoURL))
if err != nil {
return node.Starter{}, errors.Wrap(err, "Failed to cache ISO")
Expand Down
6 changes: 6 additions & 0 deletions pkg/minikube/cluster/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ func HostIP(host *host.Host) (net.IP, error) {
return oci.RoutableHostIPFromInside(oci.Docker, host.Name)
case driver.Podman:
return oci.RoutableHostIPFromInside(oci.Podman, host.Name)
case driver.Generic:
ip, err := host.Driver.GetIP()
if err != nil {
return []byte{}, errors.Wrap(err, "Error getting VM/Host IP address")
}
return net.ParseIP(ip), nil
case driver.KVM2:
return net.ParseIP("192.168.39.1"), nil
case driver.HyperV:
Expand Down
4 changes: 4 additions & 0 deletions pkg/minikube/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ type ClusterConfig struct {
HostDNSResolver bool // Only used by virtualbox
HostOnlyNicType string // Only used by virtualbox
NatNicType string // Only used by virtualbox
GenericIPAddress string // Only used by generic
GenericSSHUser string // Only used by generic
GenericSSHKey string // Only used by generic
GenericSSHPort int // Only used by generic
KubernetesConfig KubernetesConfig
Nodes []Node
Addons map[string]bool
Expand Down
2 changes: 2 additions & 0 deletions pkg/minikube/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const (
Mock = "mock"
// None driver
None = "none"
// Generic driver
Generic = "generic"
// KVM2 driver
KVM2 = "kvm2"
// VirtualBox driver
Expand Down
47 changes: 31 additions & 16 deletions pkg/minikube/machine/fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/driver"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/out"
)

Expand Down Expand Up @@ -93,6 +94,12 @@ func fixHost(api libmachine.API, cc *config.ClusterConfig, n *config.Node) (*hos
return h, nil
}

if h.Driver.DriverName() == driver.Generic {
if _, err := h.RunSSHCommand(fmt.Sprintf("sudo usermod -aG docker %s", h.Driver.GetSSHUsername())); err != nil {
return h, errors.Wrap(err, "usermod")
}
}

return h, ensureSyncedGuestClock(h, driverName)
}

Expand Down Expand Up @@ -127,25 +134,33 @@ func recreateIfNeeded(api libmachine.API, cc *config.ClusterConfig, n *config.No
}
}

if serr != constants.ErrMachineMissing {
glog.Warningf("unexpected machine state, will restart: %v", serr)
}
if h.Driver.DriverName() != driver.Generic {
if serr != constants.ErrMachineMissing {
glog.Warningf("unexpected machine state, will restart: %v", serr)
}

if s == state.Running {
if !recreated {
out.T(out.Running, `Updating the running {{.driver_name}} "{{.cluster}}" {{.machine_type}} ...`, out.V{"driver_name": cc.Driver, "cluster": cc.Name, "machine_type": machineType})
if s == state.Running {
if !recreated {
out.T(out.Running, `Updating the running {{.driver_name}} "{{.cluster}}" {{.machine_type}} ...`, out.V{"driver_name": cc.Driver, "cluster": cc.Name, "machine_type": machineType})
}
return h, nil
}
return h, nil
}

if !recreated {
out.T(out.Restarting, `Restarting existing {{.driver_name}} {{.machine_type}} for "{{.cluster}}" ...`, out.V{"driver_name": cc.Driver, "cluster": cc.Name, "machine_type": machineType})
}
if err := h.Driver.Start(); err != nil {
return h, errors.Wrap(err, "driver start")
}
if err := saveHost(api, h, cc, n); err != nil {
return h, err
if !recreated {
out.T(out.Restarting, `Restarting existing {{.driver_name}} {{.machine_type}} for "{{.cluster}}" ...`, out.V{"driver_name": cc.Driver, "cluster": cc.Name, "machine_type": machineType})
}
if err := h.Driver.Start(); err != nil {
return h, errors.Wrap(err, "driver start")
}
if err := saveHost(api, h, cc, n); err != nil {
return h, err
}
} else {
if s == state.Running {
out.T(out.Running, `Using the {{.driver_name}} "{{.cluster}}" {{.machine_type}} ...`, out.V{"driver_name": cc.Driver, "cluster": cc.Name, "machine_type": machineType})
} else {
exit.WithCodeT(exit.Unavailable, `Unable to reach {{.driver_name}} {{.machine_type}} for "{{.cluster}}"`, out.V{"driver_name": cc.Driver, "cluster": cc.Name, "machine_type": machineType})
}
}
return h, nil
}
Expand Down
16 changes: 9 additions & 7 deletions pkg/minikube/machine/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ func stop(h *host.Host) error {
}
}

if err := h.Stop(); err != nil {
glog.Infof("stop err: %v", err)
st, ok := err.(mcnerror.ErrHostAlreadyInState)
if ok && st.State == state.Stopped {
glog.Infof("host is already stopped")
return nil
if h.DriverName != driver.Generic {
if err := h.Stop(); err != nil {
glog.Infof("stop err: %v", err)
st, ok := err.(mcnerror.ErrHostAlreadyInState)
if ok && st.State == state.Stopped {
glog.Infof("host is already stopped")
return nil
}
return &retry.RetriableError{Err: errors.Wrap(err, "stop")}
}
return &retry.RetriableError{Err: errors.Wrap(err, "stop")}
}
glog.Infof("duration metric: stop complete within %s", time.Since(start))
return nil
Expand Down
63 changes: 63 additions & 0 deletions pkg/minikube/registry/drvs/generic/generic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
Copyright 2019 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 generic

import (
"fmt"

"github.com/docker/machine/drivers/generic"
"github.com/docker/machine/libmachine/drivers"

"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/driver"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/localpath"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/minikube/registry"
)

func init() {
err := registry.Register(registry.DriverDef{
Name: driver.Generic,
Config: configure,
Status: status,
Priority: registry.Fallback,
Init: func() drivers.Driver { return generic.NewDriver("", "") },
})
if err != nil {
panic(fmt.Sprintf("unable to register: %v", err))
}
}

func configure(cc config.ClusterConfig, n config.Node) (interface{}, error) {
d := generic.NewDriver(driver.MachineName(cc, n), localpath.MiniPath())

if cc.GenericIPAddress == "" {
exit.UsageT("Please provide an IP address. the vm-driver {{.name}} requires it.", out.V{"name": driver.Generic})
}

d.(*generic.Driver).IPAddress = cc.GenericIPAddress
d.(*generic.Driver).SSHUser = cc.GenericSSHUser
d.(*generic.Driver).SSHKey = cc.GenericSSHKey
d.(*generic.Driver).SSHPort = cc.GenericSSHPort

return d, nil
}

func status() registry.State {
return registry.State{Installed: true, Healthy: true}
}
1 change: 1 addition & 0 deletions pkg/minikube/registry/drvs/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package drvs
import (
// Register all of the drvs we know of
_ "k8s.io/minikube/pkg/minikube/registry/drvs/docker"
_ "k8s.io/minikube/pkg/minikube/registry/drvs/generic"
_ "k8s.io/minikube/pkg/minikube/registry/drvs/hyperkit"
_ "k8s.io/minikube/pkg/minikube/registry/drvs/hyperv"
_ "k8s.io/minikube/pkg/minikube/registry/drvs/kvm2"
Expand Down