Skip to content

Commit

Permalink
Added storage prov deps to Makefile and rewrote main file
Browse files Browse the repository at this point in the history
  • Loading branch information
Priya Wadhwa committed Nov 1, 2017
1 parent 7098431 commit c342ed4
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 52 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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}}')
Expand Down Expand Up @@ -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)

Expand Down
21 changes: 9 additions & 12 deletions cmd/storage-provisioner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}
1 change: 0 additions & 1 deletion deploy/addons/storage-provisioner/storage-provisioner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions deploy/storage-provisioner/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@
# limitations under the License.

FROM scratch
COPY main main
CMD ["/main"]

COPY out/storage-provisioner storage-provisioner
CMD ["/storage-provisioner"]
59 changes: 27 additions & 32 deletions pkg/localkube/storage_provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit c342ed4

Please sign in to comment.