Skip to content

Commit c342ed4

Browse files
author
Priya Wadhwa
committed
Added storage prov deps to Makefile and rewrote main file
1 parent 7098431 commit c342ed4

File tree

5 files changed

+42
-52
lines changed

5 files changed

+42
-52
lines changed

Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ LOCALKUBE_LDFLAGS := "$(K8S_VERSION_LDFLAGS) $(MINIKUBE_LDFLAGS) -s -w -extldfla
5454
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}}'
5555
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}}'
5656
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}}'
57-
57+
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}}'
5858
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}}'
5959

6060
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
300300
@echo ""
301301
@echo "$(@) successfully built"
302302

303-
storage-provisioner-main: cmd/storage-provisioner/main.go
304-
go build cmd/storage-provisioner/main.go
303+
out/storage-provisioner: $(shell $(STORAGE_PROVISIONER_FILES))
304+
go build -o $(BUILD_DIR)/storage-provisioner cmd/storage-provisioner/main.go
305305

306306
.PHONY: storage-provisioner-image
307-
storage-provisioner-image: storage-provisioner-main
307+
storage-provisioner-image: out/storage-provisioner
308308
docker build -t $(REGISTRY)/storage-provisioner:$(TAG) -f deploy/storage-provisioner/Dockerfile .
309309
gcloud docker -- push $(REGISTRY)/storage-provisioner:$(TAG)
310310

cmd/storage-provisioner/main.go

+9-12
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,16 @@ limitations under the License.
1717
package main
1818

1919
import (
20-
"k8s.io/minikube/cmd/localkube/cmd"
21-
"sync"
20+
"flag"
21+
"github.com/golang/glog"
22+
"k8s.io/minikube/pkg/localkube"
2223
)
2324

2425
func main() {
25-
localkubeServer := cmd.NewLocalkubeServer()
26-
storageProvisionerServer := localkubeServer.NewStorageProvisionerServer()
27-
28-
var wg sync.WaitGroup
29-
wg.Add(2)
30-
go func() {
31-
defer wg.Done()
32-
storageProvisionerServer.Start()
33-
}()
34-
wg.Wait()
26+
flag.Parse()
27+
28+
if err := localkube.StartStorageProvisioner(); err != nil {
29+
glog.Exit(err)
30+
}
31+
3532
}

deploy/addons/storage-provisioner/storage-provisioner.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ metadata:
2020
labels:
2121
integration-test: storage-provisioner
2222
addonmanager.kubernetes.io/mode: EnsureExists
23-
kubernetes.io/minikube-addons: storage-provisioner
2423
spec:
2524
hostNetwork: true
2625
containers:

deploy/storage-provisioner/Dockerfile

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,5 @@
1313
# limitations under the License.
1414

1515
FROM scratch
16-
COPY main main
17-
CMD ["/main"]
18-
16+
COPY out/storage-provisioner storage-provisioner
17+
CMD ["/storage-provisioner"]

pkg/localkube/storage_provisioner.go

+27-32
Original file line numberDiff line numberDiff line change
@@ -109,38 +109,33 @@ func (p *hostPathProvisioner) Delete(volume *v1.PersistentVolume) error {
109109
return nil
110110
}
111111

112-
func (lk LocalkubeServer) NewStorageProvisionerServer() Server {
113-
return NewSimpleServer("storage-provisioner", serverInterval, StartStorageProvisioner(lk), noop)
114-
}
112+
// Start storage provisioner server
113+
func StartStorageProvisioner() error {
114+
config, err := restclient.InClusterConfig()
115+
if err != nil {
116+
return err
117+
}
118+
clientset, err := kubernetes.NewForConfig(config)
119+
if err != nil {
120+
glog.Fatalf("Failed to create client: %v", err)
121+
}
115122

116-
func StartStorageProvisioner(lk LocalkubeServer) func() error {
117-
return func() error {
118-
config, err := restclient.InClusterConfig()
119-
if err != nil {
120-
return err
121-
}
122-
clientset, err := kubernetes.NewForConfig(config)
123-
if err != nil {
124-
glog.Fatalf("Failed to create client: %v", err)
125-
}
126-
127-
// The controller needs to know what the server version is because out-of-tree
128-
// provisioners aren't officially supported until 1.5
129-
serverVersion, err := clientset.Discovery().ServerVersion()
130-
if err != nil {
131-
return fmt.Errorf("Error getting server version: %v", err)
132-
}
133-
134-
// Create the provisioner: it implements the Provisioner interface expected by
135-
// the controller
136-
hostPathProvisioner := NewHostPathProvisioner()
137-
138-
// Start the provision controller which will dynamically provision hostPath
139-
// PVs
140-
pc := controller.NewProvisionController(clientset, provisionerName, hostPathProvisioner, serverVersion.GitVersion)
141-
142-
fmt.Println("wait never stop")
143-
pc.Run(wait.NeverStop)
144-
return nil
123+
// The controller needs to know what the server version is because out-of-tree
124+
// provisioners aren't officially supported until 1.5
125+
serverVersion, err := clientset.Discovery().ServerVersion()
126+
if err != nil {
127+
return fmt.Errorf("Error getting server version: %v", err)
145128
}
129+
130+
// Create the provisioner: it implements the Provisioner interface expected by
131+
// the controller
132+
hostPathProvisioner := NewHostPathProvisioner()
133+
134+
// Start the provision controller which will dynamically provision hostPath
135+
// PVs
136+
pc := controller.NewProvisionController(clientset, provisionerName, hostPathProvisioner, serverVersion.GitVersion)
137+
138+
glog.Info("Starting storage provisioner server")
139+
pc.Run(wait.NeverStop)
140+
return nil
146141
}

0 commit comments

Comments
 (0)