Skip to content

Commit f368ac4

Browse files
authored
Merge pull request #2137 from priyawadhwa/storage-provisioner-as-pod
Run storage provisioner as pod
2 parents 38e719a + c342ed4 commit f368ac4

File tree

10 files changed

+150
-42
lines changed

10 files changed

+150
-42
lines changed

Makefile

+9-1
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,6 +300,14 @@ $(ISO_BUILD_IMAGE): deploy/iso/minikube-iso/Dockerfile
300300
@echo ""
301301
@echo "$(@) successfully built"
302302

303+
out/storage-provisioner: $(shell $(STORAGE_PROVISIONER_FILES))
304+
go build -o $(BUILD_DIR)/storage-provisioner cmd/storage-provisioner/main.go
305+
306+
.PHONY: storage-provisioner-image
307+
storage-provisioner-image: out/storage-provisioner
308+
docker build -t $(REGISTRY)/storage-provisioner:$(TAG) -f deploy/storage-provisioner/Dockerfile .
309+
gcloud docker -- push $(REGISTRY)/storage-provisioner:$(TAG)
310+
303311
.PHONY: release-iso
304312
release-iso: minikube_iso checksum
305313
gsutil cp out/minikube.iso gs://$(ISO_BUCKET)/minikube-$(ISO_VERSION).iso

cmd/localkube/cmd/start.go

-2
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,4 @@ func SetupServer(s *localkube.LocalkubeServer) {
139139
proxy := s.NewProxyServer()
140140
s.AddServer(proxy)
141141

142-
storageProvisioner := s.NewStorageProvisionerServer()
143-
s.AddServer(storageProvisioner)
144142
}

cmd/storage-provisioner/main.go

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Copyright 2016 The Kubernetes Authors All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package main
18+
19+
import (
20+
"flag"
21+
"github.com/golang/glog"
22+
"k8s.io/minikube/pkg/localkube"
23+
)
24+
25+
func main() {
26+
flag.Parse()
27+
28+
if err := localkube.StartStorageProvisioner(); err != nil {
29+
glog.Exit(err)
30+
}
31+
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright 2016 The Kubernetes Authors All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
apiVersion: v1
16+
kind: Pod
17+
metadata:
18+
name: storage-provisioner
19+
namespace: kube-system
20+
labels:
21+
integration-test: storage-provisioner
22+
addonmanager.kubernetes.io/mode: EnsureExists
23+
spec:
24+
hostNetwork: true
25+
containers:
26+
- name: storage-provisioner
27+
image: gcr.io/k8s-minikube/storage-provisioner:v1.8.0
28+
imagePullPolicy: IfNotPresent

deploy/storage-provisioner/Dockerfile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2016 The Kubernetes Authors All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
FROM scratch
16+
COPY out/storage-provisioner storage-provisioner
17+
CMD ["/storage-provisioner"]

pkg/localkube/storage_provisioner.go

+28-34
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ import (
3030
"k8s.io/apimachinery/pkg/util/uuid"
3131
"k8s.io/apimachinery/pkg/util/wait"
3232
"k8s.io/client-go/kubernetes"
33-
"k8s.io/client-go/tools/clientcmd"
34-
"k8s.io/minikube/pkg/util"
33+
restclient "k8s.io/client-go/rest"
3534
)
3635

3736
const provisionerName = "k8s.io/minikube-hostpath"
@@ -110,38 +109,33 @@ func (p *hostPathProvisioner) Delete(volume *v1.PersistentVolume) error {
110109
return nil
111110
}
112111

113-
func (lk LocalkubeServer) NewStorageProvisionerServer() Server {
114-
return NewSimpleServer("storage-provisioner", serverInterval, StartStorageProvisioner(lk), noop)
115-
}
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+
}
116122

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

pkg/minikube/assets/addons.go

+7
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ var Addons = map[string]*Addon{
8282
"storageclass.yaml",
8383
"0640"),
8484
}, true, "default-storageclass"),
85+
"storage-provisioner": NewAddon([]*BinDataAsset{
86+
NewBinDataAsset(
87+
"deploy/addons/storage-provisioner/storage-provisioner.yaml",
88+
constants.AddonsPath,
89+
"storage-provisioner.yaml",
90+
"0640"),
91+
}, true, "storage-provisioner"),
8592
"coredns": NewAddon([]*BinDataAsset{
8693
NewBinDataAsset(
8794
"deploy/addons/coredns/coreDNS-controller.yaml",

pkg/minikube/constants/constants.go

+6
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ var LocalkubeCachedImages = []string{
176176

177177
// Pause
178178
"gcr.io/google_containers/pause-amd64:3.0",
179+
180+
//Storage Provisioner
181+
"gcr.io/k8s-minikube/storage-provisioner:v1.8.0",
179182
}
180183

181184
func GetKubeadmCachedImages(version string) []string {
@@ -201,6 +204,9 @@ func GetKubeadmCachedImages(version string) []string {
201204
"gcr.io/google_containers/kube-scheduler-amd64:" + version,
202205
"gcr.io/google_containers/kube-controller-manager-amd64:" + version,
203206
"gcr.io/google_containers/kube-apiserver-amd64:" + version,
207+
208+
//Storage Provisioner
209+
"gcr.io/k8s-minikube/storage-provisioner:v1.8.0",
204210
}
205211
}
206212

test/integration/functional_test.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ func TestFunctional(t *testing.T) {
3535
t.Run("Addons", testAddons)
3636
t.Run("Dashboard", testDashboard)
3737
t.Run("ServicesList", testServicesList)
38-
39-
// Don't run this test on kubeadm bootstrapper for now.
40-
if !strings.Contains(*args, "--bootstrapper=kubeadm") {
41-
t.Run("Provisioning", testProvisioning)
42-
}
38+
t.Run("Provisioning", testProvisioning)
4339

4440
if !strings.Contains(minikubeRunner.StartArgs, "--vm-driver=none") {
4541
t.Run("EnvVars", testClusterEnv)

test/integration/pv_test.go

+22
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@ package integration
2020

2121
import (
2222
"fmt"
23+
"github.com/pkg/errors"
2324
"path/filepath"
2425
"testing"
2526
"time"
2627

28+
"k8s.io/apimachinery/pkg/labels"
2729
"k8s.io/kubernetes/pkg/api"
2830
"k8s.io/kubernetes/pkg/apis/storage"
31+
commonutil "k8s.io/minikube/pkg/util"
2932
"k8s.io/minikube/test/integration/util"
3033
)
3134

@@ -58,6 +61,25 @@ func testProvisioning(t *testing.T) {
5861
t.Fatalf("No default storage class: %s", err)
5962
}
6063

64+
// Check that the storage provisioner pod is running
65+
66+
checkPodRunning := func() error {
67+
client, err := commonutil.GetClient()
68+
if err != nil {
69+
return errors.Wrap(err, "getting kubernetes client")
70+
}
71+
selector := labels.SelectorFromSet(labels.Set(map[string]string{"integration-test": "storage-provisioner"}))
72+
73+
if err := commonutil.WaitForPodsWithLabelRunning(client, "kube-system", selector); err != nil {
74+
return err
75+
}
76+
return nil
77+
}
78+
79+
if err := checkPodRunning(); err != nil {
80+
t.Fatal("Check storage-provisioner pod running failed with error: ", err)
81+
}
82+
6183
// Now create the PVC
6284
pvcPath := filepath.Join(*testdataDir, "pvc.yaml")
6385
if _, err := kubectlRunner.RunCommand([]string{"create", "-f", pvcPath}); err != nil {

0 commit comments

Comments
 (0)