Skip to content

Commit 0dbca73

Browse files
authored
[manila-csi-plugin] close GRPC connections (kubernetes#1473) (kubernetes#1480)
* close grpc connections * sanity: fakeCSIClientBuilder needs to create a grpc connection
1 parent 7daa30e commit 0dbca73

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

pkg/csi/manila/driver.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ func (d *Driver) initProxiedDriver() (csiNodeCapabilitySet, error) {
244244
if err != nil {
245245
return nil, fmt.Errorf("connecting to %s endpoint failed: %v", d.fwdEndpoint, err)
246246
}
247+
defer conn.Close()
247248

248249
identityClient := d.csiClientBuilder.NewIdentityServiceClient(conn)
249250

pkg/csi/manila/identityserver.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func (ids *identityServer) Probe(ctx context.Context, req *csi.ProbeRequest) (*c
4343
if err != nil {
4444
return nil, status.Error(codes.FailedPrecondition, fmtGrpcConnError(ids.d.fwdEndpoint, err))
4545
}
46+
defer csiConn.Close()
4647

4748
return ids.d.csiClientBuilder.NewIdentityServiceClient(csiConn).Probe(ctx, req)
4849
}

pkg/csi/manila/nodeserver.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
211211
if err != nil {
212212
return nil, status.Error(codes.Unavailable, fmtGrpcConnError(ns.d.fwdEndpoint, err))
213213
}
214+
defer csiConn.Close()
214215

215216
req.Secrets = secret
216217
req.VolumeContext = volumeCtx
@@ -227,6 +228,7 @@ func (ns *nodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu
227228
if err != nil {
228229
return nil, status.Error(codes.Unavailable, fmtGrpcConnError(ns.d.fwdEndpoint, err))
229230
}
231+
defer csiConn.Close()
230232

231233
return ns.d.csiClientBuilder.NewNodeServiceClient(csiConn).UnpublishVolume(ctx, req)
232234
}
@@ -285,6 +287,7 @@ func (ns *nodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol
285287
if err != nil {
286288
return nil, status.Error(codes.Unavailable, fmtGrpcConnError(ns.d.fwdEndpoint, err))
287289
}
290+
defer csiConn.Close()
288291

289292
req.Secrets = stageSecret
290293
req.VolumeContext = volumeCtx
@@ -305,6 +308,7 @@ func (ns *nodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstag
305308
if err != nil {
306309
return nil, status.Error(codes.Unavailable, fmtGrpcConnError(ns.d.fwdEndpoint, err))
307310
}
311+
defer csiConn.Close()
308312

309313
return ns.d.csiClientBuilder.NewNodeServiceClient(csiConn).UnstageVolume(ctx, req)
310314
}

tests/sanity/manila/fakecsiclient.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,12 @@ func (c fakeNodeSvcClient) UnpublishVolume(context.Context, *csi.NodeUnpublishVo
8080

8181
type fakeCSIClientBuilder struct{}
8282

83-
func (b fakeCSIClientBuilder) NewConnection(string) (*grpc.ClientConn, error) { return nil, nil }
83+
func (b fakeCSIClientBuilder) NewConnection(string) (*grpc.ClientConn, error) {
84+
return grpc.Dial("", grpc.WithInsecure())
85+
}
8486

8587
func (b fakeCSIClientBuilder) NewConnectionWithContext(context.Context, string) (*grpc.ClientConn, error) {
86-
return nil, nil
88+
return grpc.Dial("", grpc.WithInsecure())
8789
}
8890

8991
func (b fakeCSIClientBuilder) NewNodeServiceClient(conn *grpc.ClientConn) csiclient.Node {

0 commit comments

Comments
 (0)