Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PluginCapability update for external-provisioner #56

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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