Skip to content

Commit 1b1b569

Browse files
authored
Merge pull request #56 from NickrenREN/plugin-controller-service
PluginCapability update for external-provisioner
2 parents f63a371 + 6f417cf commit 1b1b569

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

pkg/controller/controller.go

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,33 @@ func getDriverName(conn *grpc.ClientConn, timeout time.Duration) (string, error)
131131
return name, nil
132132
}
133133

134+
func supportsPluginControllerService(conn *grpc.ClientConn, timeout time.Duration) (bool, error) {
135+
ctx, cancel := context.WithTimeout(context.Background(), timeout)
136+
defer cancel()
137+
138+
client := csi.NewIdentityClient(conn)
139+
req := csi.GetPluginCapabilitiesRequest{}
140+
141+
rsp, err := client.GetPluginCapabilities(ctx, &req)
142+
if err != nil {
143+
return false, err
144+
}
145+
caps := rsp.GetCapabilities()
146+
for _, cap := range caps {
147+
if cap == nil {
148+
continue
149+
}
150+
service := cap.GetService()
151+
if service == nil {
152+
continue
153+
}
154+
if service.GetType() == csi.PluginCapability_Service_CONTROLLER_SERVICE {
155+
return true, nil
156+
}
157+
}
158+
return false, nil
159+
}
160+
134161
func supportsControllerCreateVolume(conn *grpc.ClientConn, timeout time.Duration) (bool, error) {
135162
ctx, cancel := context.WithTimeout(context.Background(), timeout)
136163
defer cancel()
@@ -163,7 +190,14 @@ func NewCSIProvisioner(client kubernetes.Interface, csiEndpoint string, connecti
163190
if err != nil || grpcClient == nil {
164191
glog.Fatalf("failed to connect to csi endpoint :%v", err)
165192
}
166-
ok, err := supportsControllerCreateVolume(grpcClient, connectionTimeout)
193+
ok, err := supportsPluginControllerService(grpcClient, connectionTimeout)
194+
if err != nil {
195+
glog.Fatalf("failed to get support info :%v", err)
196+
}
197+
if !ok {
198+
glog.Fatalf("no plugin controller service support detected")
199+
}
200+
ok, err = supportsControllerCreateVolume(grpcClient, connectionTimeout)
167201
if err != nil {
168202
glog.Fatalf("failed to get support info :%v", err)
169203
}

0 commit comments

Comments
 (0)