Skip to content

Commit c20f6f6

Browse files
committed
GoCSI
This patch provides a Go-based CSI client and server capable of supporting additional storage platforms at runtime via Go plug-ins.
1 parent a4b578a commit c20f6f6

File tree

219 files changed

+70927
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

219 files changed

+70927
-2
lines changed

.travis.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
go_import_path: github.com/container-storage-interface/examples
2+
3+
language: go
4+
5+
go:
6+
- 1.8.x
7+
8+
env:
9+
global:
10+
- CSI_ENDPOINT=tcp://127.0.0.1:4210
11+
12+
before_install:
13+
- curl -LO https://github.com/google/protobuf/releases/download/v3.3.0/protoc-3.3.0-linux-x86_64.zip
14+
- unzip protoc-3.3.0-linux-x86_64.zip
15+
- chmod +x bin/protoc
16+
- export PATH="$(pwd)/bin:$PATH"
17+
18+
install:
19+
- go get -u github.com/golang/protobuf/proto
20+
- go get -u github.com/golang/protobuf/protoc-gen-go
21+
- go get -u google.golang.org/grpc
22+
- make -C gocsi goget
23+
24+
script:
25+
- make -C gocsi build
26+
- make -C gocsi test
27+
28+
after_failure:
29+
- if [ -e "gocsi/csd.log" ]; then cat gocsi/csd.log; fi

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
# examples
2-
Reference plugin implementations
1+
# Container Storage Interface (CSI) Examples [![build status](https://travis-ci.org/container-storage-interface/examples.svg?branch=master)](https://travis-ci.org/container-storage-interface/examples)
2+
This project contains examples CSI examples.
3+
4+
| Name | Description |
5+
|------|-------------|
6+
| [gocsi](./gocsi) | A Go-based CSI client and server capable of supporting additional storage platforms at runtime via Go plug-ins. |

gocsi/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.build/
2+
.DS_Store
3+
csd.log

gocsi/Makefile

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
SHELL := $(shell env which bash)
2+
3+
all: build
4+
5+
# load the go bits
6+
include go.mk
7+
8+
# configure and load the csi protobuf generator
9+
CSI_PROTO_DIR := csi
10+
include csi.mk
11+
12+
# the name of the program being built
13+
PROG := $(PKG_DIR_GO)/$(IMPORT_PATH).a
14+
15+
# the target for building the gocsi library
16+
$(PROG):$(CSI_GOSRC) \
17+
$(filter-out %_test.go,$(wildcard *.go)) \
18+
| $(GOGET) $(PKG_DIR_GO)
19+
go install -pkgdir $(abspath $(PKG_DIR_GO))
20+
@echo $@
21+
22+
# a list of sub-projects to make
23+
SUB_PROJS := $(subst /,,$(dir $(wildcard */Makefile)))
24+
25+
# prints a list of the projects to make
26+
projs:
27+
@echo . $(SUB_PROJS)
28+
29+
build: $(PROG)
30+
$(foreach d,$(SUB_PROJS),$(MAKE) -C $d $@;)
31+
32+
clean:
33+
go clean -i
34+
$(foreach d,$(SUB_PROJS),$(MAKE) -C $d $@;)
35+
36+
clobber: clean
37+
rm -fr $(CSI_PROTO_DIR) $(BUILD_DIR)
38+
$(foreach d,$(SUB_PROJS),$(MAKE) -C $d $@;)
39+
40+
goget: $(GOGET)
41+
$(foreach d,$(SUB_PROJS),$(MAKE) -C $d $@;)
42+
43+
test: build
44+
CSI_PLUGINS=$$(pwd)/mod/moc/moc-csi-plugin.so csd/csd mock > csd.log 2>&1 &
45+
sleep 2s
46+
csc/csc ls
47+
csc/csc new -o norootsquash,uid=500,gid=500 \
48+
-t ext4 -requiredBytes 107374182400 \
49+
-params color=purple,up=down \
50+
"My New Volume"
51+
csc/csc ls
52+
kill $$(ps aux | grep '[c]sd' | awk '{print $$2}')
53+
cat csd.log
54+
55+
benchmark: $(PROG)
56+
go test -benchmem -parallel 100 -bench .
57+
58+
.PHONY: projs build clean clobber goget test benchmark

gocsi/README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# gocsi
2+
This project provides a Go-based CSI client and server capable of
3+
supporting additional storage platforms at runtime via Go plug-ins.
4+
5+
```bash
6+
# get and install the sources
7+
$ go get github.com/container-storage-interface/examples/gocsi
8+
9+
# build the client
10+
$ go install github.com/container-storage-interface/examples/gocsi/csc
11+
12+
# build the server
13+
$ go install github.com/container-storage-interface/examples/gocsi/csd
14+
15+
# build the mock server plug-in
16+
$ go build -o mock.so -buildmode plugin github.com/container-storage-interface/examples/gocsi/mod/moc
17+
18+
# export the CSI endpoint
19+
$ export CSI_ENDPOINT=tcp://127.0.0.1:8080
20+
21+
# start the server (assuming $GOPATH/bin is in the PATH)
22+
$ CSI_PLUGINS=$(pwd)/mock.so csd mock > csd.log 2>&1 &
23+
[1] 19050
24+
25+
# use the client to ask for a list of volumes
26+
$ csc ls
27+
id=1 name=Mock Volume 1
28+
id=2 name=Mock Volume 2
29+
id=3 name=Mock Volume 3
30+
31+
# create a new volume
32+
$ csc new "My New Volume"
33+
id=4 name=My New Volume
34+
35+
# query the volume list again
36+
$ csc ls
37+
id=1 name=Mock Volume 1
38+
id=2 name=Mock Volume 2
39+
id=3 name=Mock Volume 3
40+
id=4 name=My New Volume
41+
42+
# kill the server
43+
kill -HUP $(ps aux | grep '[c]sd' | awk '{print $2}')
44+
45+
# view the server log
46+
$ cat csd.log
47+
2017/06/26 01:54:48 loaded plug-in: mock.so
48+
2017/06/26 01:54:48 registered endpoint: mock
49+
2017/06/26 01:54:48 mock.Serve
50+
2017/06/26 01:55:36 csd.ListVolumes
51+
2017/06/26 01:55:36 ...Volume.ID=1
52+
2017/06/26 01:55:36 ...Volume.ID=2
53+
2017/06/26 01:55:36 ...Volume.ID=3
54+
2017/06/26 01:55:47 csd.CreateVolume
55+
2017/06/26 01:55:47 CreateVolume.CapacityRange=<nil>
56+
2017/06/26 01:55:47 CreateVolume.Name=My New Volume
57+
2017/06/26 01:55:47 CreateVolume.Parameters=map[]
58+
2017/06/26 01:55:47 CreateVolume.VolumeCapabilities=[]
59+
2017/06/26 01:55:47 ...Volume.ID=4
60+
2017/06/26 01:56:04 csd.ListVolumes
61+
2017/06/26 01:56:04 ...Volume.ID=1
62+
2017/06/26 01:56:04 ...Volume.ID=2
63+
2017/06/26 01:56:04 ...Volume.ID=3
64+
2017/06/26 01:56:04 ...Volume.ID=4
65+
received signal: terminated: shutting down
66+
server stopped gracefully
67+
```

0 commit comments

Comments
 (0)