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

Add support to custom qemu uri on kvm2 driver #4401

Merged
merged 2 commits into from
Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)")
Expand Down Expand Up @@ -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),
Expand Down
8 changes: 4 additions & 4 deletions pkg/drivers/kvm/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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")
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/drivers/kvm/kvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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?")
}
Expand Down Expand Up @@ -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")
}
Expand Down
9 changes: 4 additions & 5 deletions pkg/drivers/kvm/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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")
}
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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")
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/minikube/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/drivers/kvm/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion pkg/minikube/drivers/kvm2/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type kvmDriver struct {
DiskPath string
GPU bool
Hidden bool
ConnectionURI string
}

func createKVM2Host(config cfg.MachineConfig) interface{} {
Expand All @@ -64,13 +65,14 @@ 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,
DiskPath: filepath.Join(constants.GetMinipath(), "machines", cfg.GetMachineName(), fmt.Sprintf("%s.rawdisk", cfg.GetMachineName())),
ISO: filepath.Join(constants.GetMinipath(), "machines", cfg.GetMachineName(), "boot2docker.iso"),
GPU: config.GPU,
Hidden: config.Hidden,
ConnectionURI: config.KVMQemuURI,
}
}
1 change: 1 addition & 0 deletions test/integration/start_stop_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down