From a7d568441cc7bfae28e7635d33f26e2b2ffadf79 Mon Sep 17 00:00:00 2001 From: Matt Rickard Date: Thu, 19 Oct 2017 11:00:56 -0400 Subject: [PATCH 1/4] Remove localkube from bindata This makes the minikube build simpler and the the binary smaller. Localkube will always be remotely fetched and locally cached on the host. --- Makefile | 20 +++++++++---------- .../bootstrapper/localkube/localkube.go | 12 ++++------- test.sh | 2 +- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 3942d31a1c3e..98bf8b6baa2e 100755 --- a/Makefile +++ b/Makefile @@ -32,6 +32,8 @@ ISO_BUCKET ?= minikube/iso GOOS ?= $(shell go env GOOS) GOARCH ?= $(shell go env GOARCH) BUILD_DIR ?= ./out +$(shell mkdir -p $(BUILD_DIR)) + ORG := k8s.io REPOPATH ?= $(ORG)/minikube @@ -53,11 +55,9 @@ LOCALKUBEFILES := GOPATH=$(GOPATH) go list -f '{{join .Deps "\n"}}' ./cmd/local 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}}' HYPERKIT_FILES := GOPATH=$(GOPATH) go list -f '{{join .Deps "\n"}}' k8s.io/minikube/cmd/drivers/hyperkit | 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_TEST_FILES := go list -f '{{ if .TestGoFiles }} {{.ImportPath}} {{end}}' ./... | grep k8s.io | GOPATH=$(GOPATH) 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 +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}}') # extra env vars that need to be set in cross build container MINIKUBE_ENV_darwin_DOCKER := CC=o64-clang CXX=o64-clang++ @@ -70,7 +70,7 @@ KUBE_CROSS_DOCKER_CMD := docker run -w /go/src/$(REPOPATH) --user $(shell id -u) # $(call MINIKUBE_GO_BUILD_CMD, output file, OS) define MINIKUBE_GO_BUILD_CMD - $(MINIKUBE_ENV_$(2)) go build -tags "$(MINIKUBE_BUILD_TAGS)" --installsuffix cgo -ldflags="$(MINIKUBE_LDFLAGS) $(K8S_VERSION_LDFLAGS)" -a -o $(1) k8s.io/minikube/cmd/minikube + GOOS=$(2) go build -tags "$(MINIKUBE_BUILD_TAGS)" --installsuffix cgo -ldflags="$(MINIKUBE_LDFLAGS) $(K8S_VERSION_LDFLAGS)" -a -o $(1) k8s.io/minikube/cmd/minikube endef ifeq ($(BUILD_IN_DOCKER),y) @@ -179,7 +179,7 @@ integration-versioned: out/minikube go test -v -test.timeout=30m $(REPOPATH)/test/integration --tags="$(MINIKUBE_INTEGRATION_BUILD_TAGS) versioned" $(TEST_ARGS) .PHONY: test -test: pkg/minikube/assets/assets.go +test: $(shell $(MINIKUBE_TEST_FILES)) pkg/minikube/assets/assets.go ./test.sh .PHONY: gopath @@ -188,8 +188,8 @@ ifneq ($(GOPATH)/src/$(REPOPATH),$(PWD)) $(warning Warning: Building minikube outside the GOPATH, should be $(GOPATH)/src/$(REPOPATH) but is $(PWD)) endif -pkg/minikube/assets/assets.go: out/localkube $(GOPATH)/bin/go-bindata $(shell find deploy/addons -type f) - $(GOPATH)/bin/go-bindata -nomemcopy -o pkg/minikube/assets/assets.go -pkg assets ./out/localkube deploy/addons/... +pkg/minikube/assets/assets.go: $(GOPATH)/bin/go-bindata $(shell find deploy/addons -type f) + $(GOPATH)/bin/go-bindata -nomemcopy -o pkg/minikube/assets/assets.go -pkg assets deploy/addons/... $(GOPATH)/bin/go-bindata: GOBIN=$(GOPATH)/bin go get github.com/jteeuwen/go-bindata/... @@ -255,9 +255,9 @@ out/minikube-installer.exe: out/minikube-windows-amd64.exe out/docker-machine-driver-hyperkit: $(shell $(HYPERKIT_FILES)) ifeq ($(MINIKUBE_BUILD_IN_DOCKER),y) - $(MINIKUBE_DOCKER_CMD) '$(MINIKUBE_ENV_darwin_DOCKER) $(MINIKUBE_ENV_darwin) go build -o $(BUILD_DIR)/docker-machine-driver-hyperkit k8s.io/minikube/cmd/drivers/hyperkit' + $(MINIKUBE_DOCKER_CMD) '$(MINIKUBE_ENV_darwin_DOCKER) GOOS=darwin CGO_ENABLED=1 go build -o $(BUILD_DIR)/docker-machine-driver-hyperkit k8s.io/minikube/cmd/drivers/hyperkit' else - $(MINIKUBE_ENV_darwin) go build -o $(BUILD_DIR)/docker-machine-driver-hyperkit k8s.io/minikube/cmd/drivers/hyperkit + GOOS=darwin CGO_ENABLED=1 go build -o $(BUILD_DIR)/docker-machine-driver-hyperkit k8s.io/minikube/cmd/drivers/hyperkit endif .PHONY: install-hyperkit-driver diff --git a/pkg/minikube/bootstrapper/localkube/localkube.go b/pkg/minikube/bootstrapper/localkube/localkube.go index 9da544bc2e84..1c4b50005a90 100644 --- a/pkg/minikube/bootstrapper/localkube/localkube.go +++ b/pkg/minikube/bootstrapper/localkube/localkube.go @@ -116,14 +116,10 @@ func (lk *LocalkubeBootstrapper) UpdateCluster(config bootstrapper.KubernetesCon var err error //add url/file/bundled localkube to file list - if localkubeURIWasSpecified(config) && config.KubernetesVersion != constants.DefaultKubernetesVersion { - lCacher := localkubeCacher{config} - localkubeFile, err = lCacher.fetchLocalkubeFromURI() - if err != nil { - return errors.Wrap(err, "Error updating localkube from uri") - } - } else { - localkubeFile = assets.NewBinDataAsset("out/localkube", "/usr/local/bin", "localkube", "0777") + lCacher := localkubeCacher{config} + localkubeFile, err = lCacher.fetchLocalkubeFromURI() + if err != nil { + return errors.Wrap(err, "Error updating localkube from uri") } copyableFiles = append(copyableFiles, localkubeFile) diff --git a/test.sh b/test.sh index 64bb8e55d5c7..924614cb6875 100755 --- a/test.sh +++ b/test.sh @@ -32,7 +32,7 @@ COV_TMP_FILE=coverage_tmp.txt # Run "go test" on packages that have test files. Also create coverage profile echo "Running go tests..." cd ${GOPATH}/src/${REPO_PATH} -rm -f out/$COV_FILE +rm -f out/$COV_FILE || true echo "mode: count" > out/$COV_FILE for pkg in $(go list -f '{{ if .TestGoFiles }} {{.ImportPath}} {{end}}' ./...); do go test -tags "container_image_ostree_stub containers_image_openpgp" -v $pkg -covermode=count -coverprofile=out/$COV_TMP_FILE From 02f0d41c1d7753ed9e35db93f8808c1fa238a5f1 Mon Sep 17 00:00:00 2001 From: Matt Rickard Date: Thu, 19 Oct 2017 16:07:38 -0400 Subject: [PATCH 2/4] Split out hyperkit into CGO needed stub This allows us to use the hyperkit Driver struct in minikube, without needing CGO_ENABLED=1. For the hyperkit driver binary, the CGO_ENABLED=1 function will work. --- pkg/drivers/hyperkit/driver.go | 3 +-- pkg/drivers/hyperkit/vmnet.go | 25 +++++++++++++++++++++++++ pkg/drivers/hyperkit/vmnet_stub.go | 25 +++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 pkg/drivers/hyperkit/vmnet.go create mode 100644 pkg/drivers/hyperkit/vmnet_stub.go diff --git a/pkg/drivers/hyperkit/driver.go b/pkg/drivers/hyperkit/driver.go index 18a003bd249e..750c95177ed9 100644 --- a/pkg/drivers/hyperkit/driver.go +++ b/pkg/drivers/hyperkit/driver.go @@ -32,7 +32,6 @@ import ( hyperkit "github.com/moby/hyperkit/go" "github.com/pborman/uuid" "github.com/pkg/errors" - vmnet "github.com/zchee/go-vmnet" pkgdrivers "k8s.io/minikube/pkg/drivers" commonutil "k8s.io/minikube/pkg/util" ) @@ -159,7 +158,7 @@ func (d *Driver) Start() error { // Set UUID h.UUID = uuid.NewUUID().String() log.Infof("Generated UUID %s", h.UUID) - mac, err := vmnet.GetMACAddressFromUUID(h.UUID) + mac, err := GetMACAddressFromUUID(h.UUID) if err != nil { return err } diff --git a/pkg/drivers/hyperkit/vmnet.go b/pkg/drivers/hyperkit/vmnet.go new file mode 100644 index 000000000000..f100c43c52dd --- /dev/null +++ b/pkg/drivers/hyperkit/vmnet.go @@ -0,0 +1,25 @@ +// +build darwin,cgo + +/* +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 vmnet "github.com/zchee/go-vmnet" + +func GetMACAddressFromUUID(UUID string) (string, error) { + return vmnet.GetMACAddressFromUUID(UUID) +} diff --git a/pkg/drivers/hyperkit/vmnet_stub.go b/pkg/drivers/hyperkit/vmnet_stub.go new file mode 100644 index 000000000000..8602c5b93f96 --- /dev/null +++ b/pkg/drivers/hyperkit/vmnet_stub.go @@ -0,0 +1,25 @@ +// +build darwin,!cgo + +/* +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 "fmt" + +func GetMACAddressFromUUID(UUID string) (string, error) { + return "", fmt.Error("Function not supported on CGO_ENABLED=0 binaries") +} From 7cb4f998866299934aa89822d0be8c17791a264a Mon Sep 17 00:00:00 2001 From: Matt Rickard Date: Thu, 19 Oct 2017 16:08:53 -0400 Subject: [PATCH 3/4] Makefile consolidation --- Makefile | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 98bf8b6baa2e..fdd090da9eea 100755 --- a/Makefile +++ b/Makefile @@ -22,8 +22,8 @@ INSTALL_SIZE ?= $(shell du out/minikube-windows-amd64.exe | cut -f1) BUILDROOT_BRANCH ?= 2017.02 REGISTRY?=gcr.io/k8s-minikube -MINIKUBE_BUILD_IMAGE ?= karalabe/xgo-1.8.3 -LOCALKUBE_BUILD_IMAGE ?= gcr.io/google_containers/kube-cross:v1.8.3-1 +HYPERKIT_BUILD_IMAGE ?= karalabe/xgo-1.8.3 +BUILD_IMAGE ?= gcr.io/google_containers/kube-cross:v1.8.3-1 ISO_BUILD_IMAGE ?= $(REGISTRY)/buildroot-image ISO_VERSION ?= v0.23.5 @@ -59,18 +59,12 @@ MINIKUBE_TEST_FILES := go list -f '{{ if .TestGoFiles }} {{.ImportPath}} {{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}}') -# extra env vars that need to be set in cross build container -MINIKUBE_ENV_darwin_DOCKER := CC=o64-clang CXX=o64-clang++ - MINIKUBE_BUILD_TAGS := container_image_ostree_stub containers_image_openpgp MINIKUBE_INTEGRATION_BUILD_TAGS := integration $(MINIKUBE_BUILD_TAGS) -MINIKUBE_DOCKER_CMD := docker run -e IN_DOCKER=1 --user $(shell id -u):$(shell id -g) --workdir /go/src/$(REPOPATH) --entrypoint /bin/bash -v $(PWD):/go/src/$(REPOPATH) $(MINIKUBE_BUILD_IMAGE) -c -KUBE_CROSS_DOCKER_CMD := docker run -w /go/src/$(REPOPATH) --user $(shell id -u):$(shell id -g) -e IN_DOCKER=1 -v $(shell pwd):/go/src/$(REPOPATH) $(LOCALKUBE_BUILD_IMAGE) - -# $(call MINIKUBE_GO_BUILD_CMD, output file, OS) -define MINIKUBE_GO_BUILD_CMD - GOOS=$(2) go build -tags "$(MINIKUBE_BUILD_TAGS)" --installsuffix cgo -ldflags="$(MINIKUBE_LDFLAGS) $(K8S_VERSION_LDFLAGS)" -a -o $(1) k8s.io/minikube/cmd/minikube +# $(call DOCKER, image, command) +define DOCKER + docker run --rm -e IN_DOCKER=1 --user $(shell id -u):$(shell id -g) -w /go/src/$(REPOPATH) -v $(GOPATH):/go --entrypoint /bin/bash $(1) -c '$(2)' endef ifeq ($(BUILD_IN_DOCKER),y) @@ -99,7 +93,7 @@ out/minikube$(IS_EXE): gopath out/minikube-$(GOOS)-$(GOARCH)$(IS_EXE) out/localkube: $(shell $(LOCALKUBEFILES)) ifeq ($(LOCALKUBE_BUILD_IN_DOCKER),y) - $(KUBE_CROSS_DOCKER_CMD) make $@ + $(call DOCKER,$(BUILD_IMAGE),/usr/bin/make $@) else CGO_ENABLED=1 go build -tags static_build -ldflags=$(LOCALKUBE_LDFLAGS) -o $(BUILD_DIR)/localkube ./cmd/localkube endif @@ -109,9 +103,9 @@ out/minikube-windows-amd64.exe: out/minikube-windows-amd64 out/minikube-%-amd64: pkg/minikube/assets/assets.go $(shell $(MINIKUBEFILES)) ifeq ($(MINIKUBE_BUILD_IN_DOCKER),y) - $(MINIKUBE_DOCKER_CMD) '$(MINIKUBE_ENV_$*_DOCKER) $(call MINIKUBE_GO_BUILD_CMD,$@,$*)' + $(call DOCKER,$(BUILD_IMAGE),GOOS=$* /usr/bin/make $@) else - $(call MINIKUBE_GO_BUILD_CMD,$@,$*) + go build -tags "$(MINIKUBE_BUILD_TAGS)" -ldflags="$(MINIKUBE_LDFLAGS) $(K8S_VERSION_LDFLAGS)" -a -o $@ k8s.io/minikube/cmd/minikube endif .PHONY: e2e-%-amd64 @@ -255,7 +249,7 @@ out/minikube-installer.exe: out/minikube-windows-amd64.exe out/docker-machine-driver-hyperkit: $(shell $(HYPERKIT_FILES)) ifeq ($(MINIKUBE_BUILD_IN_DOCKER),y) - $(MINIKUBE_DOCKER_CMD) '$(MINIKUBE_ENV_darwin_DOCKER) GOOS=darwin CGO_ENABLED=1 go build -o $(BUILD_DIR)/docker-machine-driver-hyperkit k8s.io/minikube/cmd/drivers/hyperkit' + $(call DOCKER,$(HYPERKIT_BUILD_IMAGE),/usr/bin/make $@) else GOOS=darwin CGO_ENABLED=1 go build -o $(BUILD_DIR)/docker-machine-driver-hyperkit k8s.io/minikube/cmd/drivers/hyperkit endif From a19f90fd911de0012f705438c5841ebdb7c84128 Mon Sep 17 00:00:00 2001 From: Matt Rickard Date: Thu, 19 Oct 2017 16:23:36 -0400 Subject: [PATCH 4/4] import erorr --- Makefile | 2 +- pkg/drivers/hyperkit/vmnet_stub.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index fdd090da9eea..d117bfccca02 100755 --- a/Makefile +++ b/Makefile @@ -249,7 +249,7 @@ out/minikube-installer.exe: out/minikube-windows-amd64.exe out/docker-machine-driver-hyperkit: $(shell $(HYPERKIT_FILES)) ifeq ($(MINIKUBE_BUILD_IN_DOCKER),y) - $(call DOCKER,$(HYPERKIT_BUILD_IMAGE),/usr/bin/make $@) + $(call DOCKER,$(HYPERKIT_BUILD_IMAGE),CC=o64-clang CXX=o64-clang++ /usr/bin/make $@) else GOOS=darwin CGO_ENABLED=1 go build -o $(BUILD_DIR)/docker-machine-driver-hyperkit k8s.io/minikube/cmd/drivers/hyperkit endif diff --git a/pkg/drivers/hyperkit/vmnet_stub.go b/pkg/drivers/hyperkit/vmnet_stub.go index 8602c5b93f96..8b4d64bc6e5e 100644 --- a/pkg/drivers/hyperkit/vmnet_stub.go +++ b/pkg/drivers/hyperkit/vmnet_stub.go @@ -18,8 +18,8 @@ limitations under the License. package hyperkit -import "fmt" +import "errors" func GetMACAddressFromUUID(UUID string) (string, error) { - return "", fmt.Error("Function not supported on CGO_ENABLED=0 binaries") + return "", errors.New("Function not supported on CGO_ENABLED=0 binaries") }