diff --git a/Makefile b/Makefile index c68d9f0a33b5..655dc39b9411 100755 --- a/Makefile +++ b/Makefile @@ -54,7 +54,7 @@ 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}}' 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}}' - +STORAGE_PROVISIONER_FILES := GOPATH=$(GOPATH) go list -f '{{join .Deps "\n"}}' k8s.io/minikube/cmd/storage-provisioner | grep k8s.io | GOPATH=$(GOPATH) 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}}' 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}}') @@ -300,11 +300,11 @@ $(ISO_BUILD_IMAGE): deploy/iso/minikube-iso/Dockerfile @echo "" @echo "$(@) successfully built" -storage-provisioner-main: cmd/storage-provisioner/main.go - go build cmd/storage-provisioner/main.go +out/storage-provisioner: $(shell $(STORAGE_PROVISIONER_FILES)) + go build -o $(BUILD_DIR)/storage-provisioner cmd/storage-provisioner/main.go .PHONY: storage-provisioner-image -storage-provisioner-image: storage-provisioner-main +storage-provisioner-image: out/storage-provisioner docker build -t $(REGISTRY)/storage-provisioner:$(TAG) -f deploy/storage-provisioner/Dockerfile . gcloud docker -- push $(REGISTRY)/storage-provisioner:$(TAG) diff --git a/cmd/storage-provisioner/main.go b/cmd/storage-provisioner/main.go index 335999319ed8..ac08d4ae73d0 100644 --- a/cmd/storage-provisioner/main.go +++ b/cmd/storage-provisioner/main.go @@ -17,19 +17,16 @@ limitations under the License. package main import ( - "k8s.io/minikube/cmd/localkube/cmd" - "sync" + "flag" + "github.com/golang/glog" + "k8s.io/minikube/pkg/localkube" ) func main() { - localkubeServer := cmd.NewLocalkubeServer() - storageProvisionerServer := localkubeServer.NewStorageProvisionerServer() - - var wg sync.WaitGroup - wg.Add(2) - go func() { - defer wg.Done() - storageProvisionerServer.Start() - }() - wg.Wait() + flag.Parse() + + if err := localkube.StartStorageProvisioner(); err != nil { + glog.Exit(err) + } + } diff --git a/deploy/addons/storage-provisioner/storage-provisioner.yaml b/deploy/addons/storage-provisioner/storage-provisioner.yaml index 1bef2d8eb6d9..2abdae67aea0 100644 --- a/deploy/addons/storage-provisioner/storage-provisioner.yaml +++ b/deploy/addons/storage-provisioner/storage-provisioner.yaml @@ -20,7 +20,6 @@ metadata: labels: integration-test: storage-provisioner addonmanager.kubernetes.io/mode: EnsureExists - kubernetes.io/minikube-addons: storage-provisioner spec: hostNetwork: true containers: diff --git a/deploy/storage-provisioner/Dockerfile b/deploy/storage-provisioner/Dockerfile index dc0decc3bd4c..bef335d5142c 100644 --- a/deploy/storage-provisioner/Dockerfile +++ b/deploy/storage-provisioner/Dockerfile @@ -13,6 +13,5 @@ # limitations under the License. FROM scratch -COPY main main -CMD ["/main"] - +COPY out/storage-provisioner storage-provisioner +CMD ["/storage-provisioner"] diff --git a/pkg/localkube/storage_provisioner.go b/pkg/localkube/storage_provisioner.go index 5d22f81845fd..a2baba170b74 100644 --- a/pkg/localkube/storage_provisioner.go +++ b/pkg/localkube/storage_provisioner.go @@ -109,38 +109,33 @@ func (p *hostPathProvisioner) Delete(volume *v1.PersistentVolume) error { return nil } -func (lk LocalkubeServer) NewStorageProvisionerServer() Server { - return NewSimpleServer("storage-provisioner", serverInterval, StartStorageProvisioner(lk), noop) -} +// Start storage provisioner server +func StartStorageProvisioner() error { + config, err := restclient.InClusterConfig() + if err != nil { + return err + } + clientset, err := kubernetes.NewForConfig(config) + if err != nil { + glog.Fatalf("Failed to create client: %v", err) + } -func StartStorageProvisioner(lk LocalkubeServer) func() error { - return func() error { - config, err := restclient.InClusterConfig() - if err != nil { - return err - } - clientset, err := kubernetes.NewForConfig(config) - if err != nil { - glog.Fatalf("Failed to create client: %v", err) - } - - // The controller needs to know what the server version is because out-of-tree - // provisioners aren't officially supported until 1.5 - serverVersion, err := clientset.Discovery().ServerVersion() - if err != nil { - return fmt.Errorf("Error getting server version: %v", err) - } - - // Create the provisioner: it implements the Provisioner interface expected by - // the controller - hostPathProvisioner := NewHostPathProvisioner() - - // Start the provision controller which will dynamically provision hostPath - // PVs - pc := controller.NewProvisionController(clientset, provisionerName, hostPathProvisioner, serverVersion.GitVersion) - - fmt.Println("wait never stop") - pc.Run(wait.NeverStop) - return nil + // The controller needs to know what the server version is because out-of-tree + // provisioners aren't officially supported until 1.5 + serverVersion, err := clientset.Discovery().ServerVersion() + if err != nil { + return fmt.Errorf("Error getting server version: %v", err) } + + // Create the provisioner: it implements the Provisioner interface expected by + // the controller + hostPathProvisioner := NewHostPathProvisioner() + + // Start the provision controller which will dynamically provision hostPath + // PVs + pc := controller.NewProvisionController(clientset, provisionerName, hostPathProvisioner, serverVersion.GitVersion) + + glog.Info("Starting storage provisioner server") + pc.Run(wait.NeverStop) + return nil }