Skip to content

Commit

Permalink
Merge pull request #56 from NickrenREN/plugin-controller-service
Browse files Browse the repository at this point in the history
PluginCapability update for external-provisioner
  • Loading branch information
jsafrane authored Mar 13, 2018
2 parents f63a371 + 6f417cf commit 1b1b569
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,33 @@ func getDriverName(conn *grpc.ClientConn, timeout time.Duration) (string, error)
return name, nil
}

func supportsPluginControllerService(conn *grpc.ClientConn, timeout time.Duration) (bool, error) {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

client := csi.NewIdentityClient(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 supportsControllerCreateVolume(conn *grpc.ClientConn, timeout time.Duration) (bool, error) {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
Expand Down Expand Up @@ -163,7 +190,14 @@ func NewCSIProvisioner(client kubernetes.Interface, csiEndpoint string, connecti
if err != nil || grpcClient == nil {
glog.Fatalf("failed to connect to csi endpoint :%v", err)
}
ok, err := supportsControllerCreateVolume(grpcClient, connectionTimeout)
ok, err := supportsPluginControllerService(grpcClient, connectionTimeout)
if err != nil {
glog.Fatalf("failed to get support info :%v", err)
}
if !ok {
glog.Fatalf("no plugin controller service support detected")
}
ok, err = supportsControllerCreateVolume(grpcClient, connectionTimeout)
if err != nil {
glog.Fatalf("failed to get support info :%v", err)
}
Expand Down

0 comments on commit 1b1b569

Please sign in to comment.