Skip to content

Commit cc481ce

Browse files
committed
remove csi-common dependencies
1 parent e88a4ea commit cc481ce

File tree

8 files changed

+384
-88
lines changed

8 files changed

+384
-88
lines changed

cmd/nfsplugin/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,6 @@ func main() {
6565
}
6666

6767
func handle() {
68-
d := nfs.NewDriver(nodeID, endpoint)
68+
d := nfs.NewNFSdriver(nodeID, endpoint)
6969
d.Run()
7070
}

pkg/nfs/controllerserver.go

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,66 @@ package nfs
22

33
import (
44
"github.com/container-storage-interface/spec/lib/go/csi"
5-
"github.com/kubernetes-csi/drivers/pkg/csi-common"
5+
"github.com/golang/glog"
66
"golang.org/x/net/context"
77
"google.golang.org/grpc/codes"
88
"google.golang.org/grpc/status"
99
)
1010

1111
type ControllerServer struct {
12-
*csicommon.DefaultControllerServer
12+
Driver *nfsDriver
1313
}
1414

15-
func (cs ControllerServer) ControllerExpandVolume(ctx context.Context, req *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) {
15+
func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error) {
1616
return nil, status.Error(codes.Unimplemented, "")
1717
}
1818

19-
func getControllerServer(csiDriver *csicommon.CSIDriver) ControllerServer {
20-
return ControllerServer{
21-
csicommon.NewDefaultControllerServer(csiDriver),
22-
}
19+
func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest) (*csi.DeleteVolumeResponse, error) {
20+
return nil, status.Error(codes.Unimplemented, "")
21+
}
22+
23+
func (cs *ControllerServer) ControllerPublishVolume(ctx context.Context, req *csi.ControllerPublishVolumeRequest) (*csi.ControllerPublishVolumeResponse, error) {
24+
return nil, status.Error(codes.Unimplemented, "")
25+
}
26+
27+
func (cs *ControllerServer) ControllerUnpublishVolume(ctx context.Context, req *csi.ControllerUnpublishVolumeRequest) (*csi.ControllerUnpublishVolumeResponse, error) {
28+
return nil, status.Error(codes.Unimplemented, "")
29+
}
30+
31+
func (cs *ControllerServer) ValidateVolumeCapabilities(ctx context.Context, req *csi.ValidateVolumeCapabilitiesRequest) (*csi.ValidateVolumeCapabilitiesResponse, error) {
32+
return nil, status.Error(codes.Unimplemented, "")
33+
}
34+
35+
func (cs *ControllerServer) ListVolumes(ctx context.Context, req *csi.ListVolumesRequest) (*csi.ListVolumesResponse, error) {
36+
return nil, status.Error(codes.Unimplemented, "")
37+
}
38+
39+
func (cs *ControllerServer) GetCapacity(ctx context.Context, req *csi.GetCapacityRequest) (*csi.GetCapacityResponse, error) {
40+
return nil, status.Error(codes.Unimplemented, "")
41+
}
42+
43+
// ControllerGetCapabilities implements the default GRPC callout.
44+
// Default supports all capabilities
45+
func (cs *ControllerServer) ControllerGetCapabilities(ctx context.Context, req *csi.ControllerGetCapabilitiesRequest) (*csi.ControllerGetCapabilitiesResponse, error) {
46+
glog.V(5).Infof("Using default ControllerGetCapabilities")
47+
48+
return &csi.ControllerGetCapabilitiesResponse{
49+
Capabilities: cs.Driver.cscap,
50+
}, nil
51+
}
52+
53+
func (cs *ControllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequest) (*csi.CreateSnapshotResponse, error) {
54+
return nil, status.Error(codes.Unimplemented, "")
55+
}
56+
57+
func (cs *ControllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteSnapshotRequest) (*csi.DeleteSnapshotResponse, error) {
58+
return nil, status.Error(codes.Unimplemented, "")
59+
}
60+
61+
func (cs *ControllerServer) ListSnapshots(ctx context.Context, req *csi.ListSnapshotsRequest) (*csi.ListSnapshotsResponse, error) {
62+
return nil, status.Error(codes.Unimplemented, "")
63+
}
64+
65+
func (cs *ControllerServer) ControllerExpandVolume(ctx context.Context, req *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) {
66+
return nil, status.Error(codes.Unimplemented, "")
2367
}

pkg/nfs/driver.go

Lines changed: 0 additions & 78 deletions
This file was deleted.

pkg/nfs/indentityserver.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package nfs
2+
3+
import (
4+
"github.com/container-storage-interface/spec/lib/go/csi"
5+
"github.com/golang/glog"
6+
"golang.org/x/net/context"
7+
"google.golang.org/grpc/codes"
8+
"google.golang.org/grpc/status"
9+
)
10+
11+
type IdentityServer struct {
12+
Driver *nfsDriver
13+
}
14+
15+
func (ids *IdentityServer) GetPluginInfo(ctx context.Context, req *csi.GetPluginInfoRequest) (*csi.GetPluginInfoResponse, error) {
16+
glog.V(5).Infof("Using default GetPluginInfo")
17+
18+
if ids.Driver.name == "" {
19+
return nil, status.Error(codes.Unavailable, "Driver name not configured")
20+
}
21+
22+
if ids.Driver.version == "" {
23+
return nil, status.Error(codes.Unavailable, "Driver is missing version")
24+
}
25+
26+
return &csi.GetPluginInfoResponse{
27+
Name: ids.Driver.name,
28+
VendorVersion: ids.Driver.version,
29+
}, nil
30+
}
31+
32+
func (ids *IdentityServer) Probe(ctx context.Context, req *csi.ProbeRequest) (*csi.ProbeResponse, error) {
33+
return &csi.ProbeResponse{}, nil
34+
}
35+
36+
func (ids *IdentityServer) GetPluginCapabilities(ctx context.Context, req *csi.GetPluginCapabilitiesRequest) (*csi.GetPluginCapabilitiesResponse, error) {
37+
glog.V(5).Infof("Using default capabilities")
38+
return &csi.GetPluginCapabilitiesResponse{
39+
Capabilities: []*csi.PluginCapability{
40+
{
41+
Type: &csi.PluginCapability_Service_{
42+
Service: &csi.PluginCapability_Service{
43+
Type: csi.PluginCapability_Service_CONTROLLER_SERVICE,
44+
},
45+
},
46+
},
47+
},
48+
}, nil
49+
}

pkg/nfs/nfs.go

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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 nfs
18+
19+
import (
20+
"github.com/container-storage-interface/spec/lib/go/csi"
21+
"github.com/golang/glog"
22+
)
23+
24+
type nfsDriver struct {
25+
name string
26+
nodeID string
27+
version string
28+
29+
endpoint string
30+
31+
//ids *identityServer
32+
ns *nodeServer
33+
cap []*csi.VolumeCapability_AccessMode
34+
cscap []*csi.ControllerServiceCapability
35+
}
36+
37+
const (
38+
driverName = "csi-nfsplugin"
39+
)
40+
41+
var (
42+
version = "1.0.0-rc2"
43+
)
44+
45+
func NewNFSdriver(nodeID, endpoint string) *nfsDriver {
46+
glog.Infof("Driver: %v version: %v", driverName, version)
47+
48+
n := &nfsDriver{
49+
name: driverName,
50+
version: version,
51+
nodeID: nodeID,
52+
endpoint: endpoint,
53+
}
54+
55+
n.AddVolumeCapabilityAccessModes([]csi.VolumeCapability_AccessMode_Mode{csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER})
56+
// NFS plugin does not support ControllerServiceCapability now.
57+
// If support is added, it should set to appropriate
58+
// ControllerServiceCapability RPC types.
59+
n.AddControllerServiceCapabilities([]csi.ControllerServiceCapability_RPC_Type{csi.ControllerServiceCapability_RPC_UNKNOWN})
60+
61+
return n
62+
}
63+
64+
func NewNodeServer(n *nfsDriver) *nodeServer {
65+
return &nodeServer{
66+
Driver: n,
67+
}
68+
}
69+
70+
func (n *nfsDriver) Run() {
71+
s := NewNonBlockingGRPCServer()
72+
s.Start(n.endpoint,
73+
NewDefaultIdentityServer(n),
74+
// NFS plugin has not implemented ControllerServer
75+
// using default controllerserver.
76+
NewControllerServer(n),
77+
NewNodeServer(n))
78+
s.Wait()
79+
}
80+
81+
func (n *nfsDriver) AddVolumeCapabilityAccessModes(vc []csi.VolumeCapability_AccessMode_Mode) []*csi.VolumeCapability_AccessMode {
82+
var vca []*csi.VolumeCapability_AccessMode
83+
for _, c := range vc {
84+
glog.Infof("Enabling volume access mode: %v", c.String())
85+
vca = append(vca, &csi.VolumeCapability_AccessMode{Mode: c})
86+
}
87+
n.cap = vca
88+
return vca
89+
}
90+
91+
func (n *nfsDriver) AddControllerServiceCapabilities(cl []csi.ControllerServiceCapability_RPC_Type) {
92+
var csc []*csi.ControllerServiceCapability
93+
94+
for _, c := range cl {
95+
glog.Infof("Enabling controller service capability: %v", c.String())
96+
csc = append(csc, NewControllerServiceCapability(c))
97+
}
98+
99+
n.cscap = csc
100+
101+
return
102+
}

pkg/nfs/nodeserver.go

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ package nfs
1818

1919
import (
2020
"fmt"
21+
"github.com/golang/glog"
2122
"os"
2223
"strings"
2324

2425
"github.com/container-storage-interface/spec/lib/go/csi"
25-
"github.com/kubernetes-csi/drivers/pkg/csi-common"
2626
"golang.org/x/net/context"
2727
"google.golang.org/grpc/codes"
2828
"google.golang.org/grpc/status"
2929
"k8s.io/kubernetes/pkg/util/mount"
3030
)
3131

3232
type nodeServer struct {
33-
*csicommon.DefaultNodeServer
33+
Driver *nfsDriver
3434
}
3535

3636
func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) {
@@ -98,6 +98,34 @@ func (ns *nodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu
9898
return &csi.NodeUnpublishVolumeResponse{}, nil
9999
}
100100

101+
func (ns *nodeServer) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error) {
102+
glog.V(5).Infof("Using default NodeGetInfo")
103+
104+
return &csi.NodeGetInfoResponse{
105+
NodeId: ns.Driver.nodeID,
106+
}, nil
107+
}
108+
109+
func (ns *nodeServer) NodeGetCapabilities(ctx context.Context, req *csi.NodeGetCapabilitiesRequest) (*csi.NodeGetCapabilitiesResponse, error) {
110+
glog.V(5).Infof("Using default NodeGetCapabilities")
111+
112+
return &csi.NodeGetCapabilitiesResponse{
113+
Capabilities: []*csi.NodeServiceCapability{
114+
{
115+
Type: &csi.NodeServiceCapability_Rpc{
116+
Rpc: &csi.NodeServiceCapability_RPC{
117+
Type: csi.NodeServiceCapability_RPC_UNKNOWN,
118+
},
119+
},
120+
},
121+
},
122+
}, nil
123+
}
124+
125+
func (ns *nodeServer) NodeGetVolumeStats(ctx context.Context, in *csi.NodeGetVolumeStatsRequest) (*csi.NodeGetVolumeStatsResponse, error) {
126+
return nil, status.Error(codes.Unimplemented, "")
127+
}
128+
101129
func (ns *nodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstageVolumeRequest) (*csi.NodeUnstageVolumeResponse, error) {
102130
return &csi.NodeUnstageVolumeResponse{}, nil
103131
}

0 commit comments

Comments
 (0)