Skip to content

Commit

Permalink
Bring KVM driver in-tree
Browse files Browse the repository at this point in the history
  • Loading branch information
r2d4 committed Aug 16, 2017
1 parent 86a268b commit 7fcb3c6
Show file tree
Hide file tree
Showing 79 changed files with 17,890 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ LOCALKUBE_LDFLAGS := "$(K8S_VERSION_LDFLAGS) $(MINIKUBE_LDFLAGS) -s -w -extldfla
LOCALKUBEFILES := GOPATH=$(GOPATH) go list -f '{{join .Deps "\n"}}' ./cmd/localkube/ | grep k8s.io | GOPATH=$(GOPATH) xargs go list -f '{{ range $$file := .GoFiles }} {{$$.Dir}}/{{$$file}}{{"\n"}}{{end}}'
MINIKUBEFILES := GOPATH=$(GOPATH) go list -f '{{join .Deps "\n"}}' ./cmd/minikube/ | grep k8s.io | GOPATH=$(GOPATH) xargs go list -f '{{ range $$file := .GoFiles }} {{$$.Dir}}/{{$$file}}{{"\n"}}{{end}}'

KVM_DRIVER_FILES := $(shell go list -f '{{join .Deps "\n"}}' ./cmd/drivers/kvm/ | grep k8s.io | xargs go list -f '{{ range $$file := .GoFiles }} {{$$.Dir}}/{{$$file}}{{"\n"}}{{end}}')

MINIKUBE_ENV_linux := CGO_ENABLED=1 GOARCH=amd64 GOOS=linux
MINIKUBE_ENV_darwin := CGO_ENABLED=1 GOARCH=amd64 GOOS=darwin
MINIKUBE_ENV_windows := CGO_ENABLED=0 GOARCH=amd64 GOOS=windows
Expand Down Expand Up @@ -237,3 +239,16 @@ $(ISO_BUILD_IMAGE): deploy/iso/minikube-iso/Dockerfile
release-iso: minikube_iso checksum
gsutil cp out/minikube.iso gs://$(ISO_BUCKET)/minikube-$(ISO_VERSION).iso
gsutil cp out/minikube.iso.sha256 gs://$(ISO_BUCKET)/minikube-$(ISO_VERSION).iso.sha256

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

.PHONY: kvm-driver
install-kvm-driver: out/docker-machine-driver-kvm
cp out/docker-machine-driver-kvm $(GOBIN)/docker-machine-driver-kvm
26 changes: 26 additions & 0 deletions cmd/drivers/kvm/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Copyright 2016 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 main

import (
"github.com/docker/machine/libmachine/drivers/plugin"
"k8s.io/minikube/pkg/drivers/kvm"
)

func main() {
plugin.RegisterDriver(kvm.NewDriver("", ""))
}
5 changes: 5 additions & 0 deletions hack/jenkins/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@
# Copy only the files we need to this workspace
mkdir -p out/ testdata/
gsutil cp gs://minikube-builds/${MINIKUBE_LOCATION}/minikube-${OS_ARCH} out/
gsutil cp gs://minikube-builds/${MINIKUBE_LOCATION}/docker-machine-driver-* out/
gsutil cp gs://minikube-builds/${MINIKUBE_LOCATION}/e2e-${OS_ARCH} out/
gsutil cp gs://minikube-builds/${MINIKUBE_LOCATION}/testdata/busybox.yaml testdata/
gsutil cp gs://minikube-builds/${MINIKUBE_LOCATION}/testdata/pvc.yaml testdata/
gsutil cp gs://minikube-builds/${MINIKUBE_LOCATION}/testdata/busybox-mount-test.yaml testdata/

# Add the out/ directory to the PATH, for using new drivers.
export PATH=$PATH:"$(pwd)/out/"

# Linux cleanup
virsh -c qemu:///system list --all \
| sed -n '3,$ p' \
Expand Down Expand Up @@ -59,6 +63,7 @@ pgrep xhyve | xargs kill || true
# Set the executable bit on the e2e binary and out binary
chmod +x out/e2e-${OS_ARCH}
chmod +x out/minikube-${OS_ARCH}
chmod +x out/docker-machine-driver-*

MINIKUBE_WANTREPORTERRORPROMPT=False sudo ./out/minikube-${OS_ARCH} delete \
|| MINIKUBE_WANTREPORTERRORPROMPT=False ./out/minikube-${OS_ARCH} delete \
Expand Down
3 changes: 3 additions & 0 deletions hack/jenkins/minikube_cross_build_and_upload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ export GOPATH=~/go
# Build all platforms (Windows, Linux, OSX)
BUILD_IN_DOCKER=y make cross

# Build the KVM driver
make out/docker-machine-driver-kvm

# Build the e2e test target for Darwin and Linux. We don't run tests on Windows yet.
# We build these on Linux, but run the tests on different platforms.
# This makes it easier to provision slaves, since they don't need to have a go toolchain.'
Expand Down
108 changes: 108 additions & 0 deletions pkg/drivers/kvm/domain.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package kvm

import (
"bytes"
"fmt"
"text/template"

libvirt "github.com/libvirt/libvirt-go"
"github.com/pkg/errors"
)

const domainTmpl = `
<domain type='kvm'>
<name>{{.MachineName}}</name>
<memory unit='MB'>{{.Memory}}</memory>
<vcpu>{{.CPU}}</vcpu>
<features>
<acpi/>
<apic/>
<pae/>
</features>
<os>
<type>hvm</type>
<boot dev='cdrom'/>
<boot dev='hd'/>
<bootmenu enable='no'/>
</os>
<devices>
<disk type='file' device='cdrom'>
<source file='{{.ISO}}'/>
<target dev='hdc' bus='ide'/>
<readonly/>
</disk>
<disk type='file' device='disk'>
<driver name='qemu' type='raw' cache='{{.CacheMode}}' io='threads' />
<source file='{{.DiskPath}}'/>
<target dev='hda' bus='ide'/>
</disk>
<interface type='network'>
<source network='default'/>
</interface>
<interface type='network'>
<source network='{{.NetworkName}}'/>
</interface>
<serial type='pty'>
<source path='/dev/pts/2'/>
<target port='0'/>
</serial>
<console type='pty' tty='/dev/pts/2'>
<source path='/dev/pts/2'/>
<target port='0'/>
</console>
</devices>
</domain>
`

func (d *Driver) getDomain() (*libvirt.Domain, *libvirt.Connect, error) {
conn, err := getConnection()
if err != nil {
return nil, nil, errors.Wrap(err, "getting domain")
}

dom, err := conn.LookupDomainByName(d.MachineName)
if err != nil {
return nil, nil, errors.Wrap(err, "looking up domain")
}

return dom, conn, nil
}

func getConnection() (*libvirt.Connect, error) {
conn, err := libvirt.NewConnect(qemusystem)
if err != nil {
return nil, errors.Wrap(err, "Error connecting to libvirt socket")
}

return conn, nil
}

func closeDomain(dom *libvirt.Domain, conn *libvirt.Connect) error {
dom.Free()
if res, _ := conn.Close(); res != 0 {
return fmt.Errorf("Error closing connection CloseConnection() == %d, expected 0", res)
}
return nil
}

func (d *Driver) createDomain() (*libvirt.Domain, error) {
tmpl := template.Must(template.New("domain").Parse(domainTmpl))
var domainXml bytes.Buffer
err := tmpl.Execute(&domainXml, d)
if err != nil {
return nil, errors.Wrap(err, "executing domain xml")
}

conn, err := getConnection()
if err != nil {
return nil, errors.Wrap(err, "Error getting libvirt connection")
}
defer conn.Close()

dom, err := conn.DomainDefineXML(domainXml.String())
if err != nil {
return nil, errors.Wrapf(err, "Error defining domain xml: %s", domainXml.String())
}

return dom, nil
}
Loading

0 comments on commit 7fcb3c6

Please sign in to comment.