Skip to content
This repository was archived by the owner on Mar 22, 2018. It is now read-only.

Commit 391a2a0

Browse files
authored
Merge pull request #74 from dims/add-support-for-csi
Add support for csi
2 parents 692c16e + e77320e commit 391a2a0

27 files changed

Lines changed: 2380 additions & 16 deletions

Makefile

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ endif
3131
depend-update: work
3232
cd $(DEST) && glide update
3333

34-
build: openstack-cloud-controller-manager cinder-provisioner cinder-flex-volume-driver k8s-keystone-auth
34+
build: openstack-cloud-controller-manager cinder-provisioner cinder-flex-volume-driver cinder-csi-plugin k8s-keystone-auth
3535

3636
openstack-cloud-controller-manager: depend $(SOURCES)
3737
cd $(DEST) && CGO_ENABLED=0 GOOS=$(GOOS) go build \
@@ -45,6 +45,12 @@ cinder-provisioner: depend $(SOURCES)
4545
-o cinder-provisioner \
4646
cmd/cinder-provisioner/main.go
4747

48+
cinder-csi-plugin: depend $(SOURCES)
49+
cd $(DEST) && CGO_ENABLED=0 GOOS=$(GOOS) go build \
50+
-ldflags "-X 'main.version=${VERSION}'" \
51+
-o cinder-csi-plugin \
52+
cmd/cinder-csi-plugin/main.go
53+
4854
cinder-flex-volume-driver: depend $(SOURCES)
4955
cd $(DEST) && CGO_ENABLED=0 GOOS=$(GOOS) go build \
5056
-ldflags "-X 'main.version=${VERSION}'" \
@@ -123,7 +129,7 @@ install-distro-packages:
123129
tools/install-distro-packages.sh
124130

125131
clean:
126-
rm -rf .bindep openstack-cloud-controller-manager cinder-flex-volume-driver cinder-provisioner k8s-keystone-auth
132+
rm -rf .bindep openstack-cloud-controller-manager cinder-flex-volume-driver cinder-provisioner cinder-csi-plugin k8s-keystone-auth
127133

128134
realclean: clean
129135
rm -rf vendor
@@ -134,7 +140,7 @@ realclean: clean
134140
shell: work
135141
cd $(DEST) && $(SHELL) -i
136142

137-
images: image-controller-manager image-flex-volume-driver image-provisioner image-k8s-keystone-auth
143+
images: image-controller-manager image-flex-volume-driver image-provisioner image-csi-plugin image-k8s-keystone-auth
138144

139145
image-controller-manager: depend openstack-cloud-controller-manager
140146
ifeq ($(GOOS),linux)
@@ -163,6 +169,15 @@ else
163169
$(error Please set GOOS=linux for building the image)
164170
endif
165171

172+
image-csi-plugin: depend cinder-csi-plugin
173+
ifeq ($(GOOS),linux)
174+
cp cinder-csi-plugin cluster/images/cinder-csi-plugin
175+
docker build -t $(REGISTRY)/cinder-csi-plugin:$(VERSION) cluster/images/cinder-csi-plugin
176+
rm cluster/images/cinder-csi-plugin/cinder-csi-plugin
177+
else
178+
$(error Please set GOOS=linux for building the image)
179+
endif
180+
166181
image-k8s-keystone-auth: depend k8s-keystone-auth
167182
ifeq ($(GOOS),linux)
168183
cp k8s-keystone-auth cluster/images/webhook
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Based on centos
2+
FROM centos:7.4.1708
3+
LABEL maintainers="Kubernetes Authors"
4+
LABEL description="Cinder CSI Plugin"
5+
6+
# Install e4fsprogs for format
7+
RUN yum -y install e4fsprogs
8+
9+
ADD cinder-csi-plugin /bin/
10+
11+
CMD ["/bin/cinder-csi-plugin"]

cmd/cinder-csi-plugin/main.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
Copyright 2017 The Kubernetes Authors.
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+
"fmt"
22+
"os"
23+
24+
"git.openstack.org/openstack/openstack-cloud-controller-manager/pkg/csi/cinder"
25+
"github.com/spf13/cobra"
26+
)
27+
28+
var (
29+
endpoint string
30+
nodeID string
31+
cloudconfig string
32+
)
33+
34+
func init() {
35+
flag.Set("logtostderr", "true")
36+
}
37+
38+
func main() {
39+
40+
flag.CommandLine.Parse([]string{})
41+
42+
cmd := &cobra.Command{
43+
Use: "Cinder",
44+
Short: "CSI based Cinder driver",
45+
Run: func(cmd *cobra.Command, args []string) {
46+
handle()
47+
},
48+
}
49+
50+
cmd.Flags().AddGoFlagSet(flag.CommandLine)
51+
52+
cmd.PersistentFlags().StringVar(&nodeID, "nodeid", "", "node id")
53+
cmd.MarkPersistentFlagRequired("nodeid")
54+
55+
cmd.PersistentFlags().StringVar(&endpoint, "endpoint", "", "CSI endpoint")
56+
cmd.MarkPersistentFlagRequired("endpoint")
57+
58+
cmd.PersistentFlags().StringVar(&cloudconfig, "cloud-config", "", "CSI driver cloud config")
59+
cmd.MarkPersistentFlagRequired("cloud-config")
60+
61+
if err := cmd.Execute(); err != nil {
62+
fmt.Fprintf(os.Stderr, "%s", err.Error())
63+
os.Exit(1)
64+
}
65+
66+
os.Exit(0)
67+
}
68+
69+
func handle() {
70+
d := cinder.NewDriver(nodeID, endpoint, cloudconfig)
71+
d.Run()
72+
}

docs/using-cinder-csi-plugin.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# CSI Cinder driver
2+
3+
## Kubernetes
4+
5+
### Requirements
6+
7+
The following feature gates and runtime config have to be enabled to deploy the driver.
8+
9+
```
10+
FEATURE_GATES=CSIPersistentVolume=true,MountPropagation=true
11+
RUNTIME_CONFIG="storage.k8s.io/v1alpha1=true"
12+
```
13+
14+
Mountprogpation requires support for privileged containers. So, make sure privileged containers are enabled in the cluster.
15+
16+
### Example local-up-cluster.sh
17+
18+
```ALLOW_PRIVILEGED=true FEATURE_GATES=CSIPersistentVolume=true,MountPropagation=true RUNTIME_CONFIG="storage.k8s.io/v1alpha1=true" LOG_LEVEL=5 hack/local-up-cluster.sh```
19+
20+
### Deploy
21+
22+
Encode your ```cloud.conf``` file content using base64.
23+
24+
```base64 -w 0 cloud.conf```
25+
26+
Update ```cloud.conf``` configuration in ```deploy/kubernetes/csi-secret-cinderplugin.yaml``` file
27+
by using the result of the above command.
28+
29+
```kubectl -f deploy/kubernetes create```
30+
31+
### Example Nginx application
32+
33+
```kubectl -f examples/kubernetes/nginx.yaml create```
34+
35+
## Using CSC tool
36+
37+
### Start Cinder driver
38+
```
39+
$ sudo ./_output/cinderplugin --endpoint tcp://127.0.0.1:10000 --cloud-config /etc/cloud.conf --nodeid CSINodeID
40+
```
41+
42+
### Test using csc
43+
Get ```csc``` tool from https://github.com/thecodeteam/gocsi/tree/master/csc
44+
45+
#### Get plugin info
46+
```
47+
$ csc identity plugin-info --endpoint tcp://127.0.0.1:10000
48+
"csi-cinderplugin" "0.1.0"
49+
```
50+
51+
#### Get supported versions
52+
```
53+
$ csc identity supported-versions --endpoint tcp://127.0.0.1:10000
54+
0.1.0
55+
```
56+
57+
#### Create a volume
58+
```
59+
$ csc controller new --endpoint tcp://127.0.0.1:10000 CSIVolumeName
60+
CSIVolumeID
61+
```
62+
63+
#### Delete a volume
64+
```
65+
$ csc controller del --endpoint tcp://127.0.0.1:10000 CSIVolumeID
66+
CSIVolumeID
67+
```
68+
69+
#### ControllerPublish a volume
70+
```
71+
$ csc controller publish --endpoint tcp://127.0.0.1:10000 --node-id=CSINodeID CSIVolumeID
72+
CSIVolumeID "DevicePath"="/dev/xxx"
73+
```
74+
75+
#### ControllerUnpublish a volume
76+
```
77+
$ csc controller unpublish --endpoint tcp://127.0.0.1:10000 --node-id=CSINodeID CSIVolumeID
78+
CSIVolumeID
79+
```
80+
81+
#### NodePublish a volume
82+
```
83+
$ csc node publish --endpoint tcp://127.0.0.1:10000 --target-path /mnt/cinder --pub-info DevicePath="/dev/xxx" CSIVolumeID
84+
CSIVolumeID
85+
```
86+
87+
#### NodeUnpublish a volume
88+
```
89+
$ csc node unpublish --endpoint tcp://127.0.0.1:10000 --target-path /mnt/cinder CSIVolumeID
90+
CSIVolumeID
91+
```
92+
93+
#### Get NodeID
94+
```
95+
$ csc node get-id --endpoint tcp://127.0.0.1:10000
96+
CSINodeID
97+
```
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# This YAML file contains nginx & csi cinder driver objects,
2+
# which are necessary to run nginx with csi cinder driver.
3+
4+
apiVersion: storage.k8s.io/v1
5+
kind: StorageClass
6+
metadata:
7+
name: csi-sc-cinderplugin
8+
provisioner: csi-cinderplugin
9+
parameters:
10+
11+
---
12+
apiVersion: v1
13+
kind: PersistentVolumeClaim
14+
metadata:
15+
name: csi-pvc-cinderplugin
16+
spec:
17+
accessModes:
18+
- ReadWriteOnce
19+
resources:
20+
requests:
21+
storage: 1Gi
22+
storageClassName: csi-sc-cinderplugin
23+
24+
---
25+
apiVersion: v1
26+
kind: Pod
27+
metadata:
28+
name: nginx
29+
spec:
30+
containers:
31+
- image: nginx
32+
imagePullPolicy: IfNotPresent
33+
name: nginx
34+
ports:
35+
- containerPort: 80
36+
protocol: TCP
37+
volumeMounts:
38+
- mountPath: /var/lib/www/html
39+
name: csi-data-cinderplugin
40+
volumes:
41+
- name: csi-data-cinderplugin
42+
persistentVolumeClaim:
43+
claimName: csi-pvc-cinderplugin
44+
readOnly: false

glide.lock

Lines changed: 38 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)