Merge pull request #1984 from r2d4/cleanup-drivers

Clean up unused files, add tar rules
pull/2029/head
Matt Rickard 2017-10-04 10:41:19 -07:00 committed by GitHub
commit e1fd9de778
4 changed files with 11 additions and 185 deletions

View File

@ -213,12 +213,15 @@ out/minikube_$(DEB_VERSION).deb: out/minikube-linux-amd64
rm -rf out/minikube_$(DEB_VERSION)
.SECONDEXPANSION:
TAR_TARGETS_linux := out/minikube-linux-amd64
TAR_TARGETS_linux := out/minikube-linux-amd64 out/docker-machine-driver-kvm2
TAR_TARGETS_darwin := out/minikube-darwin-amd64
TAR_TARGETS_windows := out/minikube-windows-amd64.exe
TAR_TARGETS_ALL := $(shell find deploy/addons -type f)
out/minikube-%-amd64.tar.gz: $$(TAR_TARGETS_$$*) $(TAR_TARGETS_ALL)
tar -cvf $@ $^
.PHONY: cross-tars
cross-tars: out/minikube-windows-amd64.tar.gz out/minikube-linux-amd64.tar.gz out/minikube-darwin-amd64.tar.gz
out/minikube-installer.exe: out/minikube-windows-amd64.exe
rm -rf out/windows_tmp
@ -296,7 +299,7 @@ out/docker-machine-driver-kvm2: $(KVM_DRIVER_FILES)
go build \
-installsuffix "static" \
-ldflags "-X k8s.io/minikube/pkg/drivers/kvm/version.VERSION=$(VERSION)" \
-tags libvirt.1.2.2 \
-tags libvirt.1.3.1 \
-o $(BUILD_DIR)/docker-machine-driver-kvm2 \
k8s.io/minikube/cmd/drivers/kvm
chmod +X $@
@ -304,3 +307,7 @@ out/docker-machine-driver-kvm2: $(KVM_DRIVER_FILES)
.PHONY: install-kvm
install-kvm: out/docker-machine-driver-kvm2
cp out/docker-machine-driver-kvm2 $(GOBIN)/docker-machine-driver-kvm2
.PHONY: release-kvm-driver
release-kvm-driver: install-kvm
gsutil cp $(GOBIN)/docker-machine-driver-kvm2 gs://minikube/drivers/kvm/$(VERSION)/

View File

@ -153,7 +153,7 @@ func (d *Driver) GetIP() (string, error) {
return "", errors.Wrap(err, "machine in unknown state")
}
if s != state.Running {
return "", errors.New("host is not running.")
return "", errors.New("host is not running")
}
ip, err := d.lookupIP()
if err != nil {
@ -168,7 +168,7 @@ func (d *Driver) GetSSHHostname() (string, error) {
}
func (d *Driver) DriverName() string {
return "kvm"
return "kvm2"
}
func (d *Driver) Kill() error {

View File

@ -1,115 +0,0 @@
/*
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 kvm
import (
"archive/tar"
"bytes"
"fmt"
"io"
"io/ioutil"
"math"
"os"
"github.com/docker/machine/libmachine/ssh"
"github.com/pkg/errors"
)
func createRawDiskImage(dest string, size int) error {
f, err := os.OpenFile(dest, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0644)
if err != nil {
if os.IsExist(err) {
return nil
}
return errors.Wrap(err, "opening file for raw disk image")
}
f.Close()
if err := os.Truncate(dest, int64(float64(size)*math.Pow10(6))); err != nil {
return errors.Wrap(err, "writing sparse file")
}
return nil
}
func (d *Driver) buildDiskImage() error {
diskPath := d.ResolveStorePath(fmt.Sprintf("%s.img", d.MachineName))
if err := createRawDiskImage(diskPath, d.DiskSize); err != nil {
return errors.Wrap(err, "creating raw disk image")
}
tarBuf, err := d.generateCertBundle()
if err != nil {
return errors.Wrap(err, "generating cert bundle")
}
f, err := os.OpenFile(d.DiskPath, os.O_WRONLY, 0644)
if err != nil {
return errors.Wrap(err, "opening raw disk image to write cert bundle")
}
defer f.Close()
f.Seek(0, io.SeekStart)
_, err = f.Write(tarBuf.Bytes())
if err != nil {
return errors.Wrap(err, "wrting cert bundle to disk image")
}
return nil
}
func (d *Driver) generateCertBundle() (*bytes.Buffer, error) {
magicString := "boot2docker, please format-me"
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return nil, errors.Wrap(err, "generating ssh key")
}
buf := new(bytes.Buffer)
tw := tar.NewWriter(buf)
file := &tar.Header{Name: magicString, Size: int64(len(magicString))}
if err := tw.WriteHeader(file); err != nil {
return nil, errors.Wrap(err, "writing magic string header to tar")
}
if _, err := tw.Write([]byte(magicString)); err != nil {
return nil, errors.Wrap(err, "writing magic string to tar")
}
// .ssh/key.pub => authorized_keys
file = &tar.Header{Name: ".ssh", Typeflag: tar.TypeDir, Mode: 0700}
if err := tw.WriteHeader(file); err != nil {
return nil, errors.Wrap(err, "writing .ssh header to tar")
}
pubKey, err := ioutil.ReadFile(d.publicSSHKeyPath())
if err != nil {
return nil, errors.Wrap(err, "reading ssh pub key for tar")
}
file = &tar.Header{Name: ".ssh/authorized_keys", Size: int64(len(pubKey)), Mode: 0644}
if err := tw.WriteHeader(file); err != nil {
return nil, errors.Wrap(err, "writing header for authorized_keys to tar")
}
if _, err := tw.Write([]byte(pubKey)); err != nil {
return nil, errors.Wrap(err, "writing pub key to tar")
}
if err := tw.Close(); err != nil {
return nil, errors.Wrap(err, "closing tar writer")
}
return buf, nil
}
func (d *Driver) publicSSHKeyPath() string {
return d.GetSSHKeyPath() + ".pub"
}

View File

@ -1,66 +0,0 @@
/*
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 hyperkit
import (
"io"
"io/ioutil"
"os"
"path/filepath"
"syscall"
"github.com/cloudflare/cfssl/log"
"github.com/docker/machine/libmachine/mcnutils"
"github.com/pkg/errors"
)
func createDiskImage(sshKeyPath, diskPath string, diskSizeMb int) error {
tarBuf, err := mcnutils.MakeDiskImage(sshKeyPath)
if err != nil {
return err
}
file, err := os.OpenFile(diskPath, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0644)
if err != nil {
return err
}
defer file.Close()
file.Seek(0, io.SeekStart)
if _, err := file.Write(tarBuf.Bytes()); err != nil {
return err
}
file.Close()
if err := os.Truncate(diskPath, int64(diskSizeMb*1000000)); err != nil {
return errors.Wrap(err, "creating disk")
}
return nil
}
func fixPermissions(path string) error {
os.Chown(path, syscall.Getuid(), syscall.Getegid())
files, _ := ioutil.ReadDir(path)
for _, f := range files {
fp := filepath.Join(path, f.Name())
log.Debugf(fp)
if err := os.Chown(fp, syscall.Getuid(), syscall.Getegid()); err != nil {
return err
}
}
return nil
}