diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index ac4da6c4ac0f..915933b7ca40 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -76,6 +76,7 @@ const ( enableDefaultCNI = "enable-default-cni" hypervVirtualSwitch = "hyperv-virtual-switch" kvmNetwork = "kvm-network" + kvmQemuURI = "kvm-qemu-uri" keepContext = "keep-context" createMount = "mount" featureGates = "feature-gates" @@ -121,6 +122,7 @@ func init() { startCmd.Flags().String(hostOnlyCIDR, "192.168.99.1/24", "The CIDR to be used for the minikube VM (only supported with Virtualbox driver)") startCmd.Flags().String(hypervVirtualSwitch, "", "The hyperv virtual switch name. Defaults to first found. (only supported with HyperV driver)") startCmd.Flags().String(kvmNetwork, "default", "The KVM network name. (only supported with KVM driver)") + startCmd.Flags().String(kvmQemuURI, "qemu:///system", "The KVM QEMU connection URI. (works only with kvm2 driver on linux)") startCmd.Flags().String(xhyveDiskDriver, "ahci-hd", "The disk driver to use [ahci-hd|virtio-blk] (only supported with xhyve driver)") startCmd.Flags().StringSlice(nfsShare, []string{}, "Local folders to share with Guest via NFS mounts (Only supported on with hyperkit now)") startCmd.Flags().String(nfsSharesRoot, "/nfsshares", "Where to root the NFS Shares (defaults to /nfsshares, only supported with hyperkit now)") @@ -495,7 +497,8 @@ func generateConfig(cmd *cobra.Command, k8sVersion string) (cfg.Config, error) { RegistryMirror: registryMirror, HostOnlyCIDR: viper.GetString(hostOnlyCIDR), HypervVirtualSwitch: viper.GetString(hypervVirtualSwitch), - KvmNetwork: viper.GetString(kvmNetwork), + KVMNetwork: viper.GetString(kvmNetwork), + KVMQemuURI: viper.GetString(kvmQemuURI), Downloader: pkgutil.DefaultDownloader{}, DisableDriverMounts: viper.GetBool(disableDriverMounts), UUID: viper.GetString(uuid), diff --git a/pkg/drivers/kvm/domain.go b/pkg/drivers/kvm/domain.go index 50b354a29be1..88890fa7b5b0 100644 --- a/pkg/drivers/kvm/domain.go +++ b/pkg/drivers/kvm/domain.go @@ -128,7 +128,7 @@ func randomMAC() (net.HardwareAddr, error) { } func (d *Driver) getDomain() (*libvirt.Domain, *libvirt.Connect, error) { - conn, err := getConnection() + conn, err := getConnection(d.ConnectionURI) if err != nil { return nil, nil, errors.Wrap(err, "getting domain") } @@ -141,8 +141,8 @@ func (d *Driver) getDomain() (*libvirt.Domain, *libvirt.Connect, error) { return dom, conn, nil } -func getConnection() (*libvirt.Connect, error) { - conn, err := libvirt.NewConnect(qemusystem) +func getConnection(connectionURI string) (*libvirt.Connect, error) { + conn, err := libvirt.NewConnect(connectionURI) if err != nil { return nil, errors.Wrap(err, connectionErrorText) } @@ -186,7 +186,7 @@ func (d *Driver) createDomain() (*libvirt.Domain, error) { return nil, errors.Wrap(err, "executing domain xml") } - conn, err := getConnection() + conn, err := getConnection(d.ConnectionURI) if err != nil { return nil, errors.Wrap(err, "Error getting libvirt connection") } diff --git a/pkg/drivers/kvm/kvm.go b/pkg/drivers/kvm/kvm.go index 4f2ccd3c2f1c..bc159abe5be3 100644 --- a/pkg/drivers/kvm/kvm.go +++ b/pkg/drivers/kvm/kvm.go @@ -82,6 +82,9 @@ type Driver struct { // XML that needs to be added to passthrough GPU devices. DevicesXML string + + // QEMU Connection URI + ConnectionURI string } const ( @@ -107,12 +110,13 @@ func NewDriver(hostName, storePath string) *Driver { Network: defaultNetworkName, DiskPath: filepath.Join(constants.GetMinipath(), "machines", config.GetMachineName(), fmt.Sprintf("%s.rawdisk", config.GetMachineName())), ISO: filepath.Join(constants.GetMinipath(), "machines", config.GetMachineName(), "boot2docker.iso"), + ConnectionURI: qemusystem, } } // PreCommandCheck checks the connection before issuing a command func (d *Driver) PreCommandCheck() error { - conn, err := getConnection() + conn, err := getConnection(d.ConnectionURI) if err != nil { return errors.Wrap(err, "Error connecting to libvirt socket. Have you added yourself to the libvirtd group?") } @@ -424,7 +428,7 @@ func (d *Driver) Stop() (err error) { // Remove a host func (d *Driver) Remove() error { log.Debug("Removing machine...") - conn, err := getConnection() + conn, err := getConnection(d.ConnectionURI) if err != nil { return errors.Wrap(err, "getting connection") } diff --git a/pkg/drivers/kvm/network.go b/pkg/drivers/kvm/network.go index 8a7e4d98dd97..7a46f0ae14f4 100644 --- a/pkg/drivers/kvm/network.go +++ b/pkg/drivers/kvm/network.go @@ -81,7 +81,7 @@ func setupNetwork(conn *libvirt.Connect, name string) error { // ensureNetwork is called on start of the VM func (d *Driver) ensureNetwork() error { - conn, err := getConnection() + conn, err := getConnection(d.ConnectionURI) if err != nil { return errors.Wrap(err, "getting libvirt connection") } @@ -108,12 +108,11 @@ func (d *Driver) ensureNetwork() error { // createNetwork is called during creation of the VM only (and not on start) func (d *Driver) createNetwork() error { - if d.Network == defaultPrivateNetworkName { return fmt.Errorf("KVM network can't be named %s. This is the name of the private network created by minikube", defaultPrivateNetworkName) } - conn, err := getConnection() + conn, err := getConnection(d.ConnectionURI) if err != nil { return errors.Wrap(err, "getting libvirt connection") } @@ -151,7 +150,7 @@ func (d *Driver) createNetwork() error { } func (d *Driver) deleteNetwork() error { - conn, err := getConnection() + conn, err := getConnection(d.ConnectionURI) if err != nil { return errors.Wrap(err, "getting libvirt connection") } @@ -269,7 +268,7 @@ func (d *Driver) checkDomains(conn *libvirt.Connect) error { } func (d *Driver) lookupIP() (string, error) { - conn, err := getConnection() + conn, err := getConnection(d.ConnectionURI) if err != nil { return "", errors.Wrap(err, "getting connection and domain") } diff --git a/pkg/minikube/config/types.go b/pkg/minikube/config/types.go index 0aa61d402a7a..be83b73bfaa4 100644 --- a/pkg/minikube/config/types.go +++ b/pkg/minikube/config/types.go @@ -45,7 +45,8 @@ type MachineConfig struct { RegistryMirror []string HostOnlyCIDR string // Only used by the virtualbox driver HypervVirtualSwitch string - KvmNetwork string // Only used by the KVM driver + KVMNetwork string // Only used by the KVM driver + KVMQemuURI string // Only used by kvm2 Downloader util.ISODownloader `json:"-"` DockerOpt []string // Each entry is formatted as KEY=VALUE. DisableDriverMounts bool // Only used by virtualbox and xhyve diff --git a/pkg/minikube/drivers/kvm/driver.go b/pkg/minikube/drivers/kvm/driver.go index 989e74276f86..451712b4c7aa 100644 --- a/pkg/minikube/drivers/kvm/driver.go +++ b/pkg/minikube/drivers/kvm/driver.go @@ -64,7 +64,7 @@ func createKVMHost(config cfg.MachineConfig) interface{} { }, Memory: config.Memory, CPU: config.CPUs, - Network: config.KvmNetwork, + Network: config.KVMNetwork, PrivateNetwork: "docker-machines", Boot2DockerURL: config.Downloader.GetISOFileURI(config.MinikubeISO), DiskSize: config.DiskSize, diff --git a/pkg/minikube/drivers/kvm2/driver.go b/pkg/minikube/drivers/kvm2/driver.go index 93395611a868..511f277a86bd 100644 --- a/pkg/minikube/drivers/kvm2/driver.go +++ b/pkg/minikube/drivers/kvm2/driver.go @@ -53,6 +53,7 @@ type kvmDriver struct { DiskPath string GPU bool Hidden bool + ConnectionURI string } func createKVM2Host(config cfg.MachineConfig) interface{} { @@ -64,7 +65,7 @@ func createKVM2Host(config cfg.MachineConfig) interface{} { }, Memory: config.Memory, CPU: config.CPUs, - Network: config.KvmNetwork, + Network: config.KVMNetwork, PrivateNetwork: "minikube-net", Boot2DockerURL: config.Downloader.GetISOFileURI(config.MinikubeISO), DiskSize: config.DiskSize, @@ -72,5 +73,6 @@ func createKVM2Host(config cfg.MachineConfig) interface{} { ISO: filepath.Join(constants.GetMinipath(), "machines", cfg.GetMachineName(), "boot2docker.iso"), GPU: config.GPU, Hidden: config.Hidden, + ConnectionURI: config.KVMQemuURI, } } diff --git a/test/integration/start_stop_delete_test.go b/test/integration/start_stop_delete_test.go index 7a5b9392e3f2..58109193594d 100644 --- a/test/integration/start_stop_delete_test.go +++ b/test/integration/start_stop_delete_test.go @@ -41,6 +41,7 @@ func TestStartStop(t *testing.T) { // default is the network created by libvirt, if we change the name minikube won't boot // because the given network doesn't exist "--kvm-network=default", + "--kvm-qemu-uri=qemu:///system", }}, {"feature_gates_newest_cni", []string{ "--feature-gates",