Skip to content

Instantly share code, notes, and snippets.

@lpabon
Created November 29, 2017 19:55
Show Gist options
  • Save lpabon/03f57d5eb1e5c1a551a7028d2815a08e to your computer and use it in GitHub Desktop.
Save lpabon/03f57d5eb1e5c1a551a7028d2815a08e to your computer and use it in GitHub Desktop.
Use CSI server on libopenstorage/openstorage
From 74efc642b42a2b3217facc0b8bf98e6ed965fd66 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Luis=20Pab=C3=B3n?= <luis@portworx.com>
Date: Tue, 28 Nov 2017 18:03:12 -0500
Subject: [PATCH] MAIN
---
cmd/osd/main.go | 25 +++++++++++++++++++++++++
csi/csi.go | 2 +-
etc/config/config.yaml | 2 +-
3 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/cmd/osd/main.go b/cmd/osd/main.go
index 8662c19..8b494db 100644
--- a/cmd/osd/main.go
+++ b/cmd/osd/main.go
@@ -17,6 +17,7 @@ import (
osdcli "github.com/libopenstorage/openstorage/cli"
"github.com/libopenstorage/openstorage/cluster"
"github.com/libopenstorage/openstorage/config"
+ "github.com/libopenstorage/openstorage/csi"
"github.com/libopenstorage/openstorage/graph/drivers"
"github.com/libopenstorage/openstorage/volume"
"github.com/libopenstorage/openstorage/volume/drivers"
@@ -171,6 +172,8 @@ func start(c *cli.Context) error {
}
isDefaultSet := false
+ csiServers := make(map[string]csi.Server)
+
// Start the volume drivers.
for d, v := range cfg.Osd.Drivers {
dlog.Infof("Starting volume driver: %v", d)
@@ -178,6 +181,28 @@ func start(c *cli.Context) error {
return fmt.Errorf("Unable to start volume driver: %v, %v", d, err)
}
+ // Start CSI server for driver
+ clusterInstance, err := cluster.Inst()
+ if err != nil {
+ return fmt.Errorf("Unable to get cluster instance: %v", err)
+ }
+ csiServer, err := csi.NewOsdCsiServer(&csi.OsdCsiServerConfig{
+ Net: "tcp",
+ Address: "127.0.0.1:0",
+ DriverName: d,
+ DriverParams: v,
+ Cluster: clusterInstance,
+ })
+ if err != nil {
+ return fmt.Errorf("Unable to create CSI server: %s", err.Error())
+ }
+ err = csiServer.Start()
+ if err != nil {
+ return fmt.Errorf("Unable to start CSI server: %s", err.Error())
+ }
+ csiServers[d] = csiServer
+ dlog.Infof("CSI server for driver %s on %s", d, csiServer.Address())
+
var mgmtPort, pluginPort uint64
if port, ok := v[config.MgmtPortKey]; ok {
mgmtPort, err = strconv.ParseUint(port, 10, 16)
diff --git a/csi/csi.go b/csi/csi.go
index 4ff143b..fb9d9ed 100644
--- a/csi/csi.go
+++ b/csi/csi.go
@@ -74,7 +74,7 @@ func NewOsdCsiServer(config *OsdCsiServerConfig) (Server, error) {
// Register driver name and initialize it using the parameters provided
err := volumedrivers.Register(config.DriverName, config.DriverParams)
- if err != nil {
+ if err != nil && err != volume.ErrExist {
return nil, fmt.Errorf("Unable to setup driver %s: %s", config.DriverName, err.Error())
}
diff --git a/etc/config/config.yaml b/etc/config/config.yaml
index 38b7750..fbbc6d6 100644
--- a/etc/config/config.yaml
+++ b/etc/config/config.yaml
@@ -10,7 +10,7 @@ osd:
# pluginPort: "2377"
nfs:
server: "127.0.0.1"
- path: "/nfs"
+ path: "/scratch"
# btrfs:
# home: "/var/lib/openstorage/btrfs"
# aws:
--
2.13.6
@lpabon
Copy link
Author

lpabon commented Nov 29, 2017

THIS IS ALL TEMPORARY UNTIL THE MAIN.GO OFFICIALLY STARTS THE SERVER

I then setup a terminal with the following:

$ make install
$ sudo $GOPATH/bin/osd -d -f configbuse.yaml

configbuse.yaml looks like:

osd:
  cluster:
    nodeid: "1"
    clusterid: "deadbeeef"
  drivers:
    buse:

Then on another window, I use csc (installing by using go get github.com/thecodeteam/gocsi/csc):

# Set CSI server port from the output of the osd logs
$ export CSI_ENDPOINT=tcp://127.0.0.1:<port from osd>

# Create a volume
$ csc controller new --cap 2,1 --req-bytes 10000000 myvol -v 0.1.0 --endpoint $CSI_ENDPOINT

# List volume
$ csc controller list-volumes -v 0.1.0 --endpoint $CSI_ENDPOINT

# Mount volume
$ csc node publish --cap 2,1 --target-path /mnt myvol -v 0.1.0 --endpoint $CSI_ENDPOINT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment