@@ -32,7 +32,6 @@ import (
32
32
"google.golang.org/grpc/status"
33
33
34
34
"github.com/container-storage-interface/spec/lib/go/csi"
35
- "github.com/kubernetes-csi/drivers/pkg/csi-common"
36
35
utilexec "k8s.io/utils/exec"
37
36
)
38
37
@@ -44,11 +43,22 @@ const (
44
43
)
45
44
46
45
type controllerServer struct {
47
- * csicommon.DefaultControllerServer
46
+ caps []* csi.ControllerServiceCapability
47
+ }
48
+
49
+ func NewControllerServer () * controllerServer {
50
+ return & controllerServer {
51
+ caps : getControllerServiceCapabilities (
52
+ []csi.ControllerServiceCapability_RPC_Type {
53
+ csi .ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME ,
54
+ csi .ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT ,
55
+ csi .ControllerServiceCapability_RPC_LIST_SNAPSHOTS ,
56
+ }),
57
+ }
48
58
}
49
59
50
60
func (cs * controllerServer ) CreateVolume (ctx context.Context , req * csi.CreateVolumeRequest ) (* csi.CreateVolumeResponse , error ) {
51
- if err := cs .Driver . ValidateControllerServiceRequest (csi .ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME ); err != nil {
61
+ if err := cs .validateControllerServiceRequest (csi .ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME ); err != nil {
52
62
glog .V (3 ).Infof ("invalid create volume req: %v" , req )
53
63
return nil , err
54
64
}
@@ -134,7 +144,7 @@ func (cs *controllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
134
144
return nil , status .Error (codes .InvalidArgument , "Volume ID missing in request" )
135
145
}
136
146
137
- if err := cs .Driver . ValidateControllerServiceRequest (csi .ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME ); err != nil {
147
+ if err := cs .validateControllerServiceRequest (csi .ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME ); err != nil {
138
148
glog .V (3 ).Infof ("invalid delete volume req: %v" , req )
139
149
return nil , err
140
150
}
@@ -146,14 +156,36 @@ func (cs *controllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
146
156
return & csi.DeleteVolumeResponse {}, nil
147
157
}
148
158
159
+ func (cs * controllerServer ) ControllerGetCapabilities (ctx context.Context , req * csi.ControllerGetCapabilitiesRequest ) (* csi.ControllerGetCapabilitiesResponse , error ) {
160
+ return & csi.ControllerGetCapabilitiesResponse {
161
+ Capabilities : cs .caps ,
162
+ }, nil
163
+ }
164
+
149
165
func (cs * controllerServer ) ValidateVolumeCapabilities (ctx context.Context , req * csi.ValidateVolumeCapabilitiesRequest ) (* csi.ValidateVolumeCapabilitiesResponse , error ) {
150
- return cs .DefaultControllerServer .ValidateVolumeCapabilities (ctx , req )
166
+ return nil , status .Error (codes .Unimplemented , "" )
167
+ }
168
+
169
+ func (cs * controllerServer ) ControllerPublishVolume (ctx context.Context , req * csi.ControllerPublishVolumeRequest ) (* csi.ControllerPublishVolumeResponse , error ) {
170
+ return nil , status .Error (codes .Unimplemented , "" )
171
+ }
172
+
173
+ func (cs * controllerServer ) ControllerUnpublishVolume (ctx context.Context , req * csi.ControllerUnpublishVolumeRequest ) (* csi.ControllerUnpublishVolumeResponse , error ) {
174
+ return nil , status .Error (codes .Unimplemented , "" )
175
+ }
176
+
177
+ func (cs * controllerServer ) GetCapacity (ctx context.Context , req * csi.GetCapacityRequest ) (* csi.GetCapacityResponse , error ) {
178
+ return nil , status .Error (codes .Unimplemented , "" )
179
+ }
180
+
181
+ func (cs * controllerServer ) ListVolumes (ctx context.Context , req * csi.ListVolumesRequest ) (* csi.ListVolumesResponse , error ) {
182
+ return nil , status .Error (codes .Unimplemented , "" )
151
183
}
152
184
153
185
// CreateSnapshot uses tar command to create snapshot for hostpath volume. The tar command can quickly create
154
186
// archives of entire directories. The host image must have "tar" binaries in /bin, /usr/sbin, or /usr/bin.
155
187
func (cs * controllerServer ) CreateSnapshot (ctx context.Context , req * csi.CreateSnapshotRequest ) (* csi.CreateSnapshotResponse , error ) {
156
- if err := cs .Driver . ValidateControllerServiceRequest (csi .ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT ); err != nil {
188
+ if err := cs .validateControllerServiceRequest (csi .ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT ); err != nil {
157
189
glog .V (3 ).Infof ("invalid create snapshot req: %v" , req )
158
190
return nil , err
159
191
}
@@ -232,7 +264,7 @@ func (cs *controllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteS
232
264
return nil , status .Error (codes .InvalidArgument , "Snapshot ID missing in request" )
233
265
}
234
266
235
- if err := cs .Driver . ValidateControllerServiceRequest (csi .ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT ); err != nil {
267
+ if err := cs .validateControllerServiceRequest (csi .ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT ); err != nil {
236
268
glog .V (3 ).Infof ("invalid delete snapshot req: %v" , req )
237
269
return nil , err
238
270
}
@@ -245,7 +277,7 @@ func (cs *controllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteS
245
277
}
246
278
247
279
func (cs * controllerServer ) ListSnapshots (ctx context.Context , req * csi.ListSnapshotsRequest ) (* csi.ListSnapshotsResponse , error ) {
248
- if err := cs .Driver . ValidateControllerServiceRequest (csi .ControllerServiceCapability_RPC_LIST_SNAPSHOTS ); err != nil {
280
+ if err := cs .validateControllerServiceRequest (csi .ControllerServiceCapability_RPC_LIST_SNAPSHOTS ); err != nil {
249
281
glog .V (3 ).Infof ("invalid list snapshot req: %v" , req )
250
282
return nil , err
251
283
}
@@ -365,3 +397,33 @@ func convertSnapshot(snap hostPathSnapshot) *csi.ListSnapshotsResponse {
365
397
366
398
return rsp
367
399
}
400
+
401
+ func (cs * controllerServer ) validateControllerServiceRequest (c csi.ControllerServiceCapability_RPC_Type ) error {
402
+ if c == csi .ControllerServiceCapability_RPC_UNKNOWN {
403
+ return nil
404
+ }
405
+
406
+ for _ , cap := range cs .caps {
407
+ if c == cap .GetRpc ().GetType () {
408
+ return nil
409
+ }
410
+ }
411
+ return status .Error (codes .InvalidArgument , fmt .Sprintf ("%s" , c ))
412
+ }
413
+
414
+ func getControllerServiceCapabilities (cl []csi.ControllerServiceCapability_RPC_Type ) []* csi.ControllerServiceCapability {
415
+ var csc []* csi.ControllerServiceCapability
416
+
417
+ for _ , cap := range cl {
418
+ glog .Infof ("Enabling controller service capability: %v" , cap .String ())
419
+ csc = append (csc , & csi.ControllerServiceCapability {
420
+ Type : & csi.ControllerServiceCapability_Rpc {
421
+ Rpc : & csi.ControllerServiceCapability_RPC {
422
+ Type : cap ,
423
+ },
424
+ },
425
+ })
426
+ }
427
+
428
+ return csc
429
+ }
0 commit comments