Updated vednor files

This commit is contained in:
Serguei Bezverkhi
2018-02-15 08:50:31 -05:00
parent 18a4ce4439
commit 1f1e8cea37
3299 changed files with 834 additions and 1051200 deletions

View File

@ -39,8 +39,8 @@ by using the result of the above command.
$ sudo ./_output/cinderplugin --endpoint tcp://127.0.0.1:10000 --cloud-config /etc/cloud.conf --nodeid CSINodeID
```
### Test
Get ```csc``` tool from https://github.com/chakri-nelluri/gocsi/tree/master/csc
### Test using csc
Get ```csc``` tool from https://github.com/thecodeteam/gocsi/tree/master/csc
#### Get plugin info
```

View File

@ -68,7 +68,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
glog.V(4).Infof("Create volume %s in Availability Zone: %s", resID, resAvailability)
return &csi.CreateVolumeResponse{
VolumeInfo: &csi.VolumeInfo{
Volume: &csi.Volume{
Id: resID,
Attributes: map[string]string{
"availability": resAvailability,
@ -137,7 +137,7 @@ func (cs *controllerServer) ControllerPublishVolume(ctx context.Context, req *cs
pvInfo["DevicePath"] = devicePath
return &csi.ControllerPublishVolumeResponse{
PublishVolumeInfo: pvInfo,
PublishInfo: pvInfo,
}, nil
}

View File

@ -61,11 +61,11 @@ func TestCreateVolume(t *testing.T) {
}
// Assert
assert.NotNil(actualRes.VolumeInfo)
assert.NotNil(actualRes.Volume)
assert.NotEqual(0, len(actualRes.VolumeInfo.Id), "Volume Id is nil")
assert.NotEqual(0, len(actualRes.Volume.Id), "Volume Id is nil")
assert.Equal(fakeAvailability, actualRes.VolumeInfo.Attributes["availability"])
assert.Equal(fakeAvailability, actualRes.Volume.Attributes["availability"])
}
// Test DeleteVolume
@ -126,7 +126,7 @@ func TestControllerPublishVolume(t *testing.T) {
// Expected Result
expectedRes := &csi.ControllerPublishVolumeResponse{
PublishVolumeInfo: map[string]string{
PublishInfo: map[string]string{
"DevicePath": fakeDevicePath,
},
}

View File

@ -26,7 +26,7 @@ var fakeConfig = "/etc/cloud.conf"
var fakeCtx = context.Background()
var fakeVolName = "CSIVolumeName"
var fakeVolID = "CSIVolumeID"
var fakeVolType = "lvmdriver-1"
var fakeAvailability = "nova"
var fakeVolType = ""
var fakeAvailability = ""
var fakeDevicePath = "/dev/xxx"
var fakeTargetPath = "/mnt/cinder"

View File

@ -31,7 +31,7 @@ type nodeServer struct {
*csicommon.DefaultNodeServer
}
func (ns *nodeServer) GetNodeID(ctx context.Context, req *csi.GetNodeIDRequest) (*csi.GetNodeIDResponse, error) {
func (ns *nodeServer) NodeGetId(ctx context.Context, req *csi.NodeGetIdRequest) (*csi.NodeGetIdResponse, error) {
// Get Mount Provider
m, err := mount.GetMountProvider()
@ -47,20 +47,20 @@ func (ns *nodeServer) GetNodeID(ctx context.Context, req *csi.GetNodeIDRequest)
}
if len(nodeID) > 0 {
return &csi.GetNodeIDResponse{
return &csi.NodeGetIdResponse{
NodeId: nodeID,
}, nil
}
// Using default function
return ns.DefaultNodeServer.GetNodeID(ctx, req)
return ns.DefaultNodeServer.NodeGetId(ctx, req)
}
func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) {
targetPath := req.GetTargetPath()
fsType := req.GetVolumeCapability().GetMount().GetFsType()
devicePath := req.GetPublishVolumeInfo()["DevicePath"]
devicePath := req.GetPublishInfo()["DevicePath"]
// Get Mount Provider
m, err := mount.GetMountProvider()

View File

@ -35,8 +35,8 @@ func init() {
}
}
// Test GetNodeID
func TestGetNodeID(t *testing.T) {
// Test NodeGetId
func TestNodeGetId(t *testing.T) {
// mock MountMock
mmock := new(mount.MountMock)
@ -48,19 +48,19 @@ func TestGetNodeID(t *testing.T) {
assert := assert.New(t)
// Expected Result
expectedRes := &csi.GetNodeIDResponse{
expectedRes := &csi.NodeGetIdResponse{
NodeId: fakeNodeID,
}
// Fake request
fakeReq := &csi.GetNodeIDRequest{
fakeReq := &csi.NodeGetIdRequest{
Version: &version,
}
// Invoke GetNodeID
actualRes, err := fakeNs.GetNodeID(fakeCtx, fakeReq)
// Invoke NodeGetId
actualRes, err := fakeNs.NodeGetId(fakeCtx, fakeReq)
if err != nil {
t.Errorf("failed to GetNodeID: %v", err)
t.Errorf("failed to NodeGetId: %v", err)
}
// Assert
@ -88,12 +88,12 @@ func TestNodePublishVolume(t *testing.T) {
// Fake request
fakeReq := &csi.NodePublishVolumeRequest{
Version: &version,
VolumeId: fakeVolID,
PublishVolumeInfo: map[string]string{"DevicePath": fakeDevicePath},
TargetPath: fakeTargetPath,
VolumeCapability: nil,
Readonly: false,
Version: &version,
VolumeId: fakeVolID,
PublishInfo: map[string]string{"DevicePath": fakeDevicePath},
TargetPath: fakeTargetPath,
VolumeCapability: nil,
Readonly: false,
}
// Invoke NodePublishVolume

View File

@ -90,6 +90,11 @@ func (cs *DefaultControllerServer) ControllerProbe(ctx context.Context, req *csi
func (cs *DefaultControllerServer) ControllerGetCapabilities(ctx context.Context, req *csi.ControllerGetCapabilitiesRequest) (*csi.ControllerGetCapabilitiesResponse, error) {
glog.V(5).Infof("Using default ControllerGetCapabilities")
// Check arguments
if req.GetVersion() == nil {
return nil, status.Error(codes.InvalidArgument, "Version missing in request")
}
return &csi.ControllerGetCapabilitiesResponse{
Capabilities: cs.Driver.cap,
}, nil

View File

@ -33,10 +33,10 @@ const (
var (
fakeVersion = csi.Version{Major: 5, Minor: 2, Patch: 0}
fakeVersionsSupported = []*csi.Version{
&csi.Version{
{
Major: 4, Minor: 0, Patch: 0,
},
&csi.Version{
{
Major: 4, Minor: 1, Patch: 0,
},
}
@ -45,10 +45,10 @@ var (
func NewFakeDriver() *CSIDriver {
fakeVersion = csi.Version{Major: 5, Minor: 2, Patch: 0}
fakeVersionsSupported = []*csi.Version{
&csi.Version{
{
Major: 4, Minor: 0, Patch: 0,
},
&csi.Version{
{
Major: 4, Minor: 1, Patch: 0,
},
}

View File

@ -44,15 +44,15 @@ func (ns *DefaultNodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.N
return nil, status.Error(codes.Unimplemented, "")
}
func (ns *DefaultNodeServer) GetNodeID(ctx context.Context, req *csi.GetNodeIDRequest) (*csi.GetNodeIDResponse, error) {
glog.V(5).Infof("Using default GetNodeID")
func (ns *DefaultNodeServer) NodeGetId(ctx context.Context, req *csi.NodeGetIdRequest) (*csi.NodeGetIdResponse, error) {
glog.V(5).Infof("Using default NodeGetId")
err := ns.Driver.CheckVersion(req.GetVersion())
if err != nil {
return nil, err
}
return &csi.GetNodeIDResponse{
return &csi.NodeGetIdResponse{
NodeId: ns.Driver.nodeID,
}, nil
}
@ -76,5 +76,15 @@ func (ns *DefaultNodeServer) NodeGetCapabilities(ctx context.Context, req *csi.N
return nil, err
}
return &csi.NodeGetCapabilitiesResponse{}, nil
return &csi.NodeGetCapabilitiesResponse{
Capabilities: []*csi.NodeServiceCapability{
{
Type: &csi.NodeServiceCapability_Rpc{
Rpc: &csi.NodeServiceCapability_RPC{
Type: csi.NodeServiceCapability_RPC_UNKNOWN,
},
},
},
},
}, nil
}

View File

@ -26,21 +26,21 @@ import (
"google.golang.org/grpc/status"
)
func TestGetNodeID(t *testing.T) {
func TestNodeGetId(t *testing.T) {
d := NewFakeDriver()
ns := NewDefaultNodeServer(d)
// Test invalid request
req := csi.GetNodeIDRequest{}
_, err := ns.GetNodeID(context.Background(), &req)
req := csi.NodeGetIdRequest{}
_, err := ns.NodeGetId(context.Background(), &req)
s, ok := status.FromError(err)
assert.True(t, ok)
assert.Equal(t, s.Code(), codes.InvalidArgument)
// Test valid request
req.Version = &fakeVersion
resp, err := ns.GetNodeID(context.Background(), &req)
resp, err := ns.NodeGetId(context.Background(), &req)
assert.NoError(t, err)
assert.Equal(t, resp.GetNodeId(), fakeNodeID)
}

View File

@ -41,7 +41,7 @@ func GetVersionString(v *csi.Version) string {
}
func GetVersionFromString(v string) (*csi.Version, error) {
var major, minor, patch uint32
var major, minor, patch int32
n, err := fmt.Sscanf(v, "%d.%d.%d", &major, &minor, &patch)
if err != nil {

View File

@ -31,9 +31,9 @@ func TestGetVersionFromString(t *testing.T) {
v, err := GetVersionFromString("1.2.3")
assert.NoError(t, err)
assert.Equal(t, v.GetMajor(), uint32(1))
assert.Equal(t, v.GetMinor(), uint32(2))
assert.Equal(t, v.GetPatch(), uint32(3))
assert.Equal(t, v.GetMajor(), int32(1))
assert.Equal(t, v.GetMinor(), int32(2))
assert.Equal(t, v.GetPatch(), int32(3))
// Invalid version
_, err = GetVersionFromString("1.2")

View File

@ -4,39 +4,39 @@
### Start Flexvolume adapter for simple nfs flexvolume driver
```
$ sudo ../_output/flexadapter --endpoint tcp://127.0.0.1:10000 --drivername simplenfs --driverpath ./examples/simple-nfs-flexdriver/nfs --nodeid CSINode
$ sudo ./_output/flexadapter --endpoint tcp://127.0.0.1:10000 --drivername simplenfs --driverpath ./pkg/flexadapter/examples/simplenfs-flexdriver/driver/nfs --nodeid CSINode -v=5
```
### Test using csc
Get ```csc``` tool from https://github.com/chakri-nelluri/gocsi/tree/master/csc
Get ```csc``` tool from https://github.com/thecodeteam/gocsi/tree/master/csc
#### Get plugin info
```
$ csc identity plugininfo --endpoint tcp://127.0.0.1:10000
$ csc identity plugin-info --endpoint tcp://127.0.0.1:10000
"simplenfs" "0.1.0"
```
### Get supported versions
```
$ csc identity supportedversions --endpoint tcp://127.0.0.1:10000
$ csc identity supported-versions --endpoint tcp://127.0.0.1:10000
0.1.0
```
#### NodePublish a volume
```
$ csc node publishvolume --endpoint tcp://127.0.0.1:10000 --target-path /mnt/nfs --attrib server=a.b.c.d --attrib share=nfs_share nfstestvol
$ csc node publish --endpoint tcp://127.0.0.1:10000 --target-path /mnt/nfs --attrib server=a.b.c.d --attrib share=nfs_share nfstestvol
nfstestvol
```
#### NodeUnpublish a volume
```
$ csc node unpublishvolume --endpoint tcp://127.0.0.1:10000 --target-path /mnt/nfs nfstestvol
$ csc node unpublish --endpoint tcp://127.0.0.1:10000 --target-path /mnt/nfs nfstestvol
nfstestvol
```
#### Get NodeID
```
$ csc node getid --endpoint tcp://127.0.0.1:10000
$ csc node get-id --endpoint tcp://127.0.0.1:10000
CSINode
```

View File

@ -32,6 +32,7 @@ const (
)
type controllerServer struct {
flexDriver *flexVolumeDriver
*csicommon.DefaultControllerServer
}
@ -44,9 +45,14 @@ func (cs *controllerServer) ControllerPublishVolume(ctx context.Context, req *cs
return nil, err
}
call := GetFlexAdapter().flexDriver.NewDriverCall(attachCmd)
cap := req.GetVolumeCapability()
fsType := "ext4"
if cap != nil {
mount := req.GetVolumeCapability().GetMount()
fsType = mount.FsType
}
fsType := req.GetVolumeCapability().GetMount().FsType
call := cs.flexDriver.NewDriverCall(attachCmd)
call.AppendSpec(req.GetVolumeId(), fsType, req.GetReadonly(), req.GetVolumeAttributes())
call.Append(req.GetNodeId())
@ -62,7 +68,7 @@ func (cs *controllerServer) ControllerPublishVolume(ctx context.Context, req *cs
pvInfo[deviceID] = callStatus.DevicePath
return &csi.ControllerPublishVolumeResponse{
PublishVolumeInfo: pvInfo,
PublishInfo: pvInfo,
}, nil
}
@ -71,7 +77,7 @@ func (cs *controllerServer) ControllerUnpublishVolume(ctx context.Context, req *
return nil, err
}
call := GetFlexAdapter().flexDriver.NewDriverCall(detachCmd)
call := cs.flexDriver.NewDriverCall(detachCmd)
call.Append(req.GetVolumeId())
call.Append(req.GetNodeId())

View File

@ -18,7 +18,6 @@ package flexadapter
import (
"os"
"sync"
"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/golang/glog"
@ -39,8 +38,6 @@ type flexAdapter struct {
}
var (
adapter *flexAdapter
runOnce sync.Once
version = csi.Version{
Minor: 1,
}
@ -50,15 +47,13 @@ func GetSupportedVersions() []*csi.Version {
return []*csi.Version{&version}
}
func GetFlexAdapter() *flexAdapter {
runOnce.Do(func() {
adapter = &flexAdapter{}
})
return adapter
func New() *flexAdapter {
return &flexAdapter{}
}
func NewControllerServer(d *csicommon.CSIDriver) *controllerServer {
func NewControllerServer(d *csicommon.CSIDriver, f *flexVolumeDriver) *controllerServer {
return &controllerServer{
flexDriver: f,
DefaultControllerServer: csicommon.NewDefaultControllerServer(d),
}
}
@ -76,22 +71,22 @@ func (f *flexAdapter) Run(driverName, driverPath, nodeID, endpoint string) {
glog.Infof("Driver: %v version: %v", driverName, GetVersionString(&version))
// Create flex volume driver
adapter.flexDriver, err = NewFlexVolumeDriver(driverName, driverPath)
f.flexDriver, err = NewFlexVolumeDriver(driverName, driverPath)
if err != nil {
glog.Errorf("Failed to initialize flex volume driver, error: %v", err.Error())
os.Exit(1)
}
// Initialize default library driver
adapter.driver = csicommon.NewCSIDriver(driverName, &version, GetSupportedVersions(), nodeID)
if adapter.flexDriver.capabilities.Attach {
adapter.driver.AddControllerServiceCapabilities([]csi.ControllerServiceCapability_RPC_Type{csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME})
f.driver = csicommon.NewCSIDriver(driverName, &version, GetSupportedVersions(), nodeID)
if f.flexDriver.capabilities.Attach {
f.driver.AddControllerServiceCapabilities([]csi.ControllerServiceCapability_RPC_Type{csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME})
}
adapter.driver.AddVolumeCapabilityAccessModes([]csi.VolumeCapability_AccessMode_Mode{csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER})
f.driver.AddVolumeCapabilityAccessModes([]csi.VolumeCapability_AccessMode_Mode{csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER})
// Create GRPC servers
f.ns = NewNodeServer(adapter.driver, adapter.flexDriver)
f.cs = NewControllerServer(adapter.driver)
f.ns = NewNodeServer(f.driver, f.flexDriver)
f.cs = NewControllerServer(f.driver, f.flexDriver)
csicommon.RunControllerandNodePublishServer(endpoint, adapter.driver, f.cs, f.ns)
csicommon.RunControllerandNodePublishServer(endpoint, f.driver, f.cs, f.ns)
}

View File

@ -58,8 +58,6 @@ func NewFlexVolumeDriver(driverName, driverPath string) (*flexVolumeDriver, erro
execPath: driverPath,
}
adapter.flexDriver = flexDriver
// Initialize the plugin and probe the capabilities
call := flexDriver.NewDriverCall(initCmd)
ds, err := call.Run()

View File

@ -46,7 +46,37 @@ func mountDevice(devicePath, targetPath, fsType string, readOnly bool, mountOpti
diskMounter := &mount.SafeFormatAndMount{Interface: mount.New(""), Exec: mount.NewOsExec()}
return diskMounter.FormatAndMount(deviceID, targetPath, fsType, options)
return diskMounter.FormatAndMount(devicePath, targetPath, fsType, options)
}
func (ns *nodeServer) waitForAttach(req *csi.NodePublishVolumeRequest, fsType string) error {
var dID string
if req.GetPublishInfo() != nil {
var ok bool
dID, ok = req.GetPublishInfo()[deviceID]
if !ok {
return status.Error(codes.InvalidArgument, "Missing device ID")
}
} else {
return status.Error(codes.InvalidArgument, "Missing publish info and device ID")
}
call := ns.flexDriver.NewDriverCall(waitForAttachCmd)
call.Append(dID)
call.AppendSpec(req.GetVolumeId(), fsType, req.GetReadonly(), req.GetVolumeAttributes())
_, err := call.Run()
if isCmdNotSupportedErr(err) {
return nil
}
if err != nil {
status.Error(codes.Internal, err.Error())
}
return nil
}
func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) {
@ -70,11 +100,24 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
return &csi.NodePublishVolumeResponse{}, nil
}
call := GetFlexAdapter().flexDriver.NewDriverCall(mountCmd)
var call *DriverCall
// Attachable driver.
if ns.flexDriver.capabilities.Attach {
err = ns.waitForAttach(req, fsType)
if err != nil {
return nil, err
}
call = ns.flexDriver.NewDriverCall(mountDeviceCmd)
} else {
call = ns.flexDriver.NewDriverCall(mountCmd)
}
call.Append(req.GetTargetPath())
if req.GetPublishVolumeInfo() != nil {
call.Append(req.GetPublishVolumeInfo()[deviceID])
if req.GetPublishInfo() != nil {
call.Append(req.GetPublishInfo()[deviceID])
}
call.AppendSpec(req.GetVolumeId(), fsType, req.GetReadonly(), req.GetVolumeAttributes())
@ -98,7 +141,12 @@ func unmountDevice(path string) error {
func (ns *nodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error) {
call := GetFlexAdapter().flexDriver.NewDriverCall(unmountCmd)
var call *DriverCall
if ns.flexDriver.capabilities.Attach {
call = ns.flexDriver.NewDriverCall(unmountDeviceCmd)
} else {
call = ns.flexDriver.NewDriverCall(unmountCmd)
}
call.Append(req.GetTargetPath())
_, err := call.Run()
@ -109,5 +157,6 @@ func (ns *nodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu
return nil, status.Error(codes.Internal, err.Error())
}
// WaitForDetach is ignored in current K8S plugins
return &csi.NodeUnpublishVolumeResponse{}, nil
}

View File

@ -0,0 +1,64 @@
# CSI Hostpath driver
## Usage:
### Build hostpathplugin
```
$ make hostpath
```
### Start Hostpath driver
```
$ sudo ./_output/hostpathplugin --endpoint tcp://127.0.0.1:10000 --nodeid CSINode -v=5
```
### Test using csc
Get ```csc``` tool from https://github.com/thecodeteam/gocsi/tree/master/csc
#### Get plugin info
```
$ csc identity plugin-info --endpoint tcp://127.0.0.1:10000
"csi-hostpath" "0.1.0"
```
#### Get supported versions
```
$ csc identity supported-versions --endpoint tcp://127.0.0.1:10000
0.1.0
```
#### Create a volume
```
$ csc controller new --endpoint tcp://127.0.0.1:10000 --cap 1,block CSIVolumeName
CSIVolumeID
```
#### Delete a volume
```
$ csc controller del --endpoint tcp://127.0.0.1:10000 CSIVolumeID
CSIVolumeID
```
#### Validate volume capabilities
```
$ csc controller validate-volume-capabilities --endpoint tcp://127.0.0.1:10000 --cap 1,block CSIVolumeID
CSIVolumeID true
```
#### NodePublish a volume
```
$ csc node publish --endpoint tcp://127.0.0.1:10000 --cap 1,block --target-path /mnt/hostpath CSIVolumeID
CSIVolumeID
```
#### NodeUnpublish a volume
```
$ csc node unpublish --endpoint tcp://127.0.0.1:10000 --target-path /mnt/hostpath CSIVolumeID
CSIVolumeID
```
#### Get NodeID
```
$ csc node get-id --endpoint tcp://127.0.0.1:10000
CSINode
```

View File

@ -23,6 +23,8 @@ import (
"github.com/golang/glog"
"github.com/pborman/uuid"
"golang.org/x/net/context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/kubernetes-csi/drivers/pkg/csi-common"
@ -42,6 +44,18 @@ func GetVersionString(ver *csi.Version) string {
}
func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error) {
// Check arguments
if req.GetVersion() == nil {
return nil, status.Error(codes.InvalidArgument, "Version missing in request")
}
if len(req.GetName()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Name missing in request")
}
if req.GetVolumeCapabilities() == nil {
return nil, status.Error(codes.InvalidArgument, "Volume Capabilities missing in request")
}
if err := cs.Driver.ValidateControllerServiceRequest(req.Version, csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME); err != nil {
glog.V(3).Infof("invalid create volume req: %v", req)
return nil, err
@ -55,13 +69,22 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
}
glog.V(4).Infof("create volume %s", path)
return &csi.CreateVolumeResponse{
VolumeInfo: &csi.VolumeInfo{
Volume: &csi.Volume{
Id: volumeId,
},
}, nil
}
func (cs *controllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest) (*csi.DeleteVolumeResponse, error) {
// Check arguments
if req.GetVersion() == nil {
return nil, status.Error(codes.InvalidArgument, "Version missing in request")
}
if len(req.GetVolumeId()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Volume ID missing in request")
}
if err := cs.Driver.ValidateControllerServiceRequest(req.Version, csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME); err != nil {
glog.V(3).Infof("invalid delete volume req: %v", req)
return nil, err
@ -75,6 +98,18 @@ func (cs *controllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
}
func (cs *controllerServer) ValidateVolumeCapabilities(ctx context.Context, req *csi.ValidateVolumeCapabilitiesRequest) (*csi.ValidateVolumeCapabilitiesResponse, error) {
// Check arguments
if req.GetVersion() == nil {
return nil, status.Error(codes.InvalidArgument, "Version missing in request")
}
if len(req.GetVolumeId()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Volume ID missing in request")
}
if req.GetVolumeCapabilities() == nil {
return nil, status.Error(codes.InvalidArgument, "Volume capabilities missing in request")
}
for _, cap := range req.VolumeCapabilities {
if cap.GetAccessMode().GetMode() != csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER {
return &csi.ValidateVolumeCapabilitiesResponse{Supported: false, Message: ""}, nil

View File

@ -37,7 +37,7 @@ type hostPath struct {
var (
hostPathDriver *hostPath
version = csi.Version{
Minor: 1,
Minor: 2,
}
)
@ -72,6 +72,9 @@ func (hp *hostPath) Run(driverName, nodeID, endpoint string) {
// Initialize default library driver
hp.driver = csicommon.NewCSIDriver(driverName, &version, GetSupportedVersions(), nodeID)
if hp.driver == nil {
glog.Fatalln("Failed to initialize CSI Driver.")
}
hp.driver.AddControllerServiceCapabilities([]csi.ControllerServiceCapability_RPC_Type{csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME})
hp.driver.AddVolumeCapabilityAccessModes([]csi.VolumeCapability_AccessMode_Mode{csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER})

View File

@ -35,6 +35,21 @@ type nodeServer struct {
}
func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) {
// Check arguments
if req.GetVersion() == nil {
return nil, status.Error(codes.InvalidArgument, "Version missing in request")
}
if req.GetVolumeCapability() == nil {
return nil, status.Error(codes.InvalidArgument, "Volume capability missing in request")
}
if len(req.GetVolumeId()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Volume ID missing in request")
}
if len(req.GetTargetPath()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Target path missing in request")
}
targetPath := req.GetTargetPath()
notMnt, err := mount.New("").IsLikelyNotMountPoint(targetPath)
if err != nil {
@ -55,8 +70,8 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
fsType := req.GetVolumeCapability().GetMount().GetFsType()
deviceId := ""
if req.GetPublishVolumeInfo() != nil {
deviceId = req.GetPublishVolumeInfo()[deviceID]
if req.GetPublishInfo() != nil {
deviceId = req.GetPublishInfo()[deviceID]
}
readOnly := req.GetReadonly()
@ -81,5 +96,17 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
}
func (ns *nodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error) {
// Check arguments
if req.GetVersion() == nil {
return nil, status.Error(codes.InvalidArgument, "Version missing in request")
}
if len(req.GetVolumeId()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Volume ID missing in request")
}
if len(req.GetTargetPath()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Target path missing in request")
}
return &csi.NodeUnpublishVolumeResponse{}, nil
}

View File

@ -4,11 +4,11 @@
### Start ISCSI driver
```
$ sudo ../_output/iscsidriver --endpoint tcp://127.0.0.1:10000 --nodeid CSINode
$ sudo ./_output/iscsidriver --endpoint tcp://127.0.0.1:10000 --nodeid CSINode
```
### Test using csc
Get ```csc``` tool from https://github.com/chakri-nelluri/gocsi/tree/master/csc
Get ```csc``` tool from https://github.com/thecodeteam/gocsi/tree/master/csc
#### Get plugin info
```

View File

@ -28,9 +28,14 @@ Please update the NFS Server & share information in nginx.yaml file.
## Using CSC tool
### Build nfsplugin
```
$ make nfs
```
### Start NFS driver
```
$ sudo ../../_output/flexadapter --endpoint tcp://127.0.0.1:10000 --drivername simplenfs --driverpath ./examples/simplenfs-flexdriver/driver/nfs --nodeid CSINode -v=3
$ sudo ./_output/nfsplugin --endpoint tcp://127.0.0.1:10000 --nodeid CSINode -v=5
```
## Test
@ -38,13 +43,13 @@ Get ```csc``` tool from https://github.com/thecodeteam/gocsi/tree/master/csc
#### Get plugin info
```
$ csc identity plugininfo --endpoint tcp://127.0.0.1:10000
$ csc identity plugin-info --endpoint tcp://127.0.0.1:10000
"NFS" "0.1.0"
```
### Get supported versions
```
$ csc identity supportedversions --endpoint tcp://127.0.0.1:10000
$ csc identity supported-versions --endpoint tcp://127.0.0.1:10000
0.1.0
```
@ -52,19 +57,19 @@ $ csc identity supportedversions --endpoint tcp://127.0.0.1:10000
```
$ export NFS_SERVER="Your Server IP (Ex: 10.10.10.10)"
$ export NFS_SHARE="Your NFS share"
$ csc node publishvolume --endpoint tcp://127.0.0.1:10000 --target-path /mnt/nfs --attrib server=$NFS_SERVER --attrib share=$NFS_SHARE nfstestvol
$ csc node publish --endpoint tcp://127.0.0.1:10000 --target-path /mnt/nfs --attrib server=$NFS_SERVER --attrib share=$NFS_SHARE nfstestvol
nfstestvol
```
#### NodeUnpublish a volume
```
$ csc node unpublishvolume --endpoint tcp://127.0.0.1:10000 --target-path /mnt/nfs nfstestvol
$ csc node unpublish --endpoint tcp://127.0.0.1:10000 --target-path /mnt/nfs nfstestvol
nfstestvol
```
#### Get NodeID
```
$ csc node getid --endpoint tcp://127.0.0.1:10000
$ csc node get-id --endpoint tcp://127.0.0.1:10000
CSINode
```

View File

@ -43,7 +43,7 @@ spec:
mountPath: /var/lib/csi/sockets/pluginproxy/
- name: nfs
image: docker.io/k8s/nfsplugin:v0.1
image: docker.io/k8scsi/nfsplugin:v0.1
args :
- "--nodeid=$(NODE_ID)"
- "--endpoint=$(CSI_ENDPOINT)"

View File

@ -37,7 +37,7 @@ spec:
capabilities:
add: ["SYS_ADMIN"]
allowPrivilegeEscalation: true
image: docker.io/k8s/nfsplugin:v0.1
image: docker.io/k8scsi/nfsplugin:v0.1
args :
- "--nodeid=$(NODE_ID)"
- "--endpoint=$(CSI_ENDPOINT)"

View File

@ -59,7 +59,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
}
s := req.GetVolumeAttributes()["server"]
ep := req.GetVolumeAttributes()["exportPath"]
ep := req.GetVolumeAttributes()["share"]
source := fmt.Sprintf("%s:%s", s, ep)
mounter := mount.New("")