Skip to content

Commit

Permalink
PluginCapability update for external-attacher
Browse files Browse the repository at this point in the history
  • Loading branch information
NickrenREN committed Mar 13, 2018
1 parent 341457a commit 0faf2a4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cmd/csi-attacher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@ func main() {
glog.Error(err.Error())
os.Exit(1)
}
if !supportsAttach {
supportsService, err := csiConn.SupportsPluginControllerService(ctx)
if err != nil {
glog.Error(err.Error())
os.Exit(1)
}
if !supportsAttach || !supportsService {
handler = controller.NewTrivialHandler(clientset)
glog.V(2).Infof("CSI driver does not support ControllerPublishUnpublish, using trivial handler")
} else {
Expand Down
28 changes: 28 additions & 0 deletions pkg/connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ type CSIConnection interface {
// PUBLISH_UNPUBLISH_VOLUME in ControllerGetCapabilities() gRPC call.
SupportsControllerPublish(ctx context.Context) (bool, error)

// SupportsPluginControllerService return true if the CSI driver reports
// CONTROLLER_SERVICE in GetPluginCapabilities() gRPC call.
SupportsPluginControllerService(ctx context.Context) (bool, error)

// Attach given volume to given node. Returns PublishVolumeInfo. Note that
// "detached" is returned on error and means that the volume is for sure
// detached from the node. "false" means that the volume may be either
Expand Down Expand Up @@ -164,6 +168,30 @@ func (c *csiConnection) SupportsControllerPublish(ctx context.Context) (bool, er
return false, nil
}

func (c *csiConnection) SupportsPluginControllerService(ctx context.Context) (bool, error) {
client := csi.NewIdentityClient(c.conn)
req := csi.GetPluginCapabilitiesRequest{}

rsp, err := client.GetPluginCapabilities(ctx, &req)
if err != nil {
return false, err
}
caps := rsp.GetCapabilities()
for _, cap := range caps {
if cap == nil {
continue
}
service := cap.GetService()
if service == nil {
continue
}
if service.GetType() == csi.PluginCapability_Service_CONTROLLER_SERVICE {
return true, nil
}
}
return false, nil
}

func (c *csiConnection) Attach(ctx context.Context, volumeID string, readOnly bool, nodeID string, caps *csi.VolumeCapability, attributes map[string]string) (metadata map[string]string, detached bool, err error) {
client := csi.NewControllerClient(c.conn)

Expand Down

0 comments on commit 0faf2a4

Please sign in to comment.