Skip to content

Commit

Permalink
# This is a combination of 8 commits.
Browse files Browse the repository at this point in the history
# This is the 1st commit message:

Fix doc comment version.gitCommitID doc


# This is the commit message kubernetes#2:

Add hyperkit doc


# This is the commit message kubernetes#3:

Add commit id to docker-machine-driver-kvm2 version


# This is the commit message kubernetes#4:

removed label selector for registry-proxy daemonset

# This is the commit message kubernetes#5:

Add support to custom qemu uri on kvm2 driver


# This is the commit message kubernetes#6:

Improve hyperkit vm stop


# This is the commit message kubernetes#7:

Make virtualbox DNS settings configurable 


# This is the commit message kubernetes#8:

added integration tests for registry addon
  • Loading branch information
josedonizetti authored and castlemilk committed Jun 29, 2019
1 parent d5ded27 commit ad97983
Show file tree
Hide file tree
Showing 19 changed files with 154 additions and 28 deletions.
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ CMD_SOURCE_DIRS = cmd pkg
SOURCE_DIRS = $(CMD_SOURCE_DIRS) test
SOURCE_PACKAGES = ./cmd/... ./pkg/... ./test/...

# kvm2 ldflags
KVM2_LDFLAGS := -X k8s.io/minikube/pkg/drivers/kvm.version=$(VERSION) -X k8s.io/minikube/pkg/drivers/kvm.gitCommitID=$(COMMIT)

# $(call DOCKER, image, command)
define DOCKER
docker run --rm -e GOCACHE=/app/.cache -e IN_DOCKER=1 --user $(shell id -u):$(shell id -g) -w /app -v $(PWD):/app -v $(GOPATH):/go --entrypoint /bin/bash $(1) -c '$(2)'
Expand Down Expand Up @@ -387,11 +390,11 @@ release-minikube: out/minikube checksum
gsutil cp out/minikube-$(GOOS)-$(GOARCH).sha256 $(MINIKUBE_UPLOAD_LOCATION)/$(MINIKUBE_VERSION)/minikube-$(GOOS)-$(GOARCH).sha256

out/docker-machine-driver-kvm2:
go build \
-installsuffix "static" \
-ldflags "-X k8s.io/minikube/pkg/drivers/kvm.version=$(VERSION)" \
go build \
-installsuffix "static" \
-ldflags="$(KVM2_LDFLAGS)" \
-tags libvirt.1.3.1 \
-o $(BUILD_DIR)/docker-machine-driver-kvm2 \
-o $(BUILD_DIR)/docker-machine-driver-kvm2 \
k8s.io/minikube/cmd/drivers/kvm
chmod +X $@

Expand Down
5 changes: 3 additions & 2 deletions cmd/drivers/kvm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ import (
)

func main() {
if len(os.Args) > 1 && os.Args[1] == "--version" {
fmt.Println(kvm.GetVersion())
if len(os.Args) > 1 && os.Args[1] == "version" {
fmt.Println("version:", kvm.GetVersion())
fmt.Println("commit:", kvm.GetGitCommitID())
return
}

Expand Down
11 changes: 10 additions & 1 deletion cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,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 All @@ -97,6 +98,8 @@ const (
embedCerts = "embed-certs"
noVTXCheck = "no-vtx-check"
downloadOnly = "download-only"
dnsProxy = "dns-proxy"
hostDNSResolver = "host-dns-resolver"
)

var (
Expand All @@ -122,6 +125,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 @@ -156,6 +160,8 @@ func init() {
startCmd.Flags().Bool(gpu, false, "Enable experimental NVIDIA GPU support in minikube (works only with kvm2 driver on Linux)")
startCmd.Flags().Bool(hidden, false, "Hide the hypervisor signature from the guest in minikube (works only with kvm2 driver on Linux)")
startCmd.Flags().Bool(noVTXCheck, false, "Disable checking for the availability of hardware virtualization before the vm is started (virtualbox)")
startCmd.Flags().Bool(dnsProxy, false, "Enable proxy for NAT DNS requests (virtualbox)")
startCmd.Flags().Bool(hostDNSResolver, true, "Enable host resolver for NAT DNS requests (virtualbox)")
if err := viper.BindPFlags(startCmd.Flags()); err != nil {
exit.WithError("unable to bind flags", err)
}
Expand Down Expand Up @@ -520,13 +526,16 @@ 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),
GPU: viper.GetBool(gpu),
Hidden: viper.GetBool(hidden),
NoVTXCheck: viper.GetBool(noVTXCheck),
DNSProxy: viper.GetBool(dnsProxy),
HostDNSResolver: viper.GetBool(hostDNSResolver),
},
KubernetesConfig: cfg.KubernetesConfig{
KubernetesVersion: k8sVersion,
Expand Down
4 changes: 2 additions & 2 deletions deploy/addons/registry/registry-proxy.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
labels:
kubernetes.io/minikube-addons: registry
kubernetes.io/minikube-addons: registry-proxy
addonmanager.kubernetes.io/mode: Reconcile
name: registry-proxy
namespace: kube-system
spec:
template:
metadata:
labels:
kubernetes.io/minikube-addons: registry
kubernetes.io/minikube-addons: registry-proxy
addonmanager.kubernetes.io/mode: Reconcile
spec:
containers:
Expand Down
2 changes: 1 addition & 1 deletion docs/drivers.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ virsh net-start default
Make sure you are running the lastest version of your driver.

```shell
docker-machine-driver-kvm2 --version
docker-machine-driver-kvm2 version
```

## Hyperkit driver
Expand Down
25 changes: 24 additions & 1 deletion pkg/drivers/hyperkit/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const (
"sudo chown root:wheel %s && sudo chmod u+s %s"
)

// Driver is the machine driver for Hyperkit
type Driver struct {
*drivers.BaseDriver
*pkgdrivers.CommonDriver
Expand All @@ -69,6 +70,7 @@ type Driver struct {
VSockPorts []string
}

// NewDriver creates a new driver for a host
func NewDriver(hostName, storePath string) *Driver {
return &Driver{
BaseDriver: &drivers.BaseDriver{
Expand Down Expand Up @@ -98,6 +100,7 @@ func (d *Driver) verifyRootPermissions() error {
return nil
}

// Create a host using the driver's config
func (d *Driver) Create() error {
if err := d.verifyRootPermissions(); err != nil {
return err
Expand Down Expand Up @@ -194,6 +197,7 @@ func (d *Driver) Remove() error {
return nil
}

// Restart a host
func (d *Driver) Restart() error {
return pkgdrivers.Restart(d)
}
Expand Down Expand Up @@ -342,7 +346,26 @@ func (d *Driver) Stop() error {
return err
}
d.cleanupNfsExports()
return d.sendSignal(syscall.SIGTERM)
err := d.sendSignal(syscall.SIGTERM)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("hyperkit sigterm failed"))
}

// wait 5s for graceful shutdown
for i := 0; i < 5; i++ {
log.Debug("waiting for graceful shutdown")
time.Sleep(time.Second * 1)
s, err := d.GetState()
if err != nil {
return errors.Wrap(err, fmt.Sprintf("hyperkit waiting graceful shutdown failed"))
}
if s == state.Stopped {
return nil
}
}

log.Debug("sending sigkill")
return d.Kill()
}

func (d *Driver) extractKernel(isoPath string) error {
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
8 changes: 8 additions & 0 deletions pkg/drivers/kvm/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ package kvm
// version is a private field and should be set when compiling with --ldflags="-X k8s.io/minikube/pkg/drivers/kvm.version=vX.Y.Z"
var version = "v0.0.0-unset"

// gitCommitID is a private field and should be set when compiling with --ldflags="-X k8s.io/minikube/pkg/drivers/kvm.gitCommitID=<commit-id>"
var gitCommitID = ""

// GetVersion returns the current docker-machine-driver-kvm2 version
func GetVersion() string {
return version
}

// GetGitCommitID returns the git commit id from which it is being built
func GetGitCommitID() string {
return gitCommitID
}
5 changes: 4 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 All @@ -55,6 +56,8 @@ type MachineConfig struct {
GPU bool // Only used by kvm2
Hidden bool // Only used by kvm2
NoVTXCheck bool // Only used by virtualbox
DNSProxy bool // Only used by virtualbox
HostDNSResolver bool // Only used by virtualbox
}

// KubernetesConfig contains the parameters used to configure the VM Kubernetes.
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,
}
}
4 changes: 2 additions & 2 deletions pkg/minikube/drivers/virtualbox/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ func createVirtualboxHost(config cfg.MachineConfig) interface{} {
d.NoVTXCheck = config.NoVTXCheck
d.NatNicType = defaultVirtualboxNicType
d.HostOnlyNicType = defaultVirtualboxNicType
d.DNSProxy = false
d.HostDNSResolver = true
d.DNSProxy = config.DNSProxy
d.HostDNSResolver = config.HostDNSResolver

return d
}
2 changes: 1 addition & 1 deletion pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const VersionPrefix = "v"
// version is a private field and should be set when compiling with --ldflags="-X k8s.io/minikube/pkg/version.version=vX.Y.Z"
var version = "v0.0.0-unset"

// version is a private field and should be set when compiling with --ldflags="-X k8s.io/minikube/pkg/version.gitCommitID=<commit-id>"
// gitCommitID is a private field and should be set when compiling with --ldflags="-X k8s.io/minikube/pkg/version.gitCommitID=<commit-id>"
var gitCommitID = ""

// isoVersion is a private field and should be set when compiling with --ldflags="-X k8s.io/minikube/pkg/version.isoVersion=vX.Y.Z"
Expand Down
Loading

0 comments on commit ad97983

Please sign in to comment.