Skip to content

Commit

Permalink
[manila-csi-plugin] close GRPC connections (#1473) (#1480)
Browse files Browse the repository at this point in the history
* close grpc connections

* sanity: fakeCSIClientBuilder needs to create a grpc connection
  • Loading branch information
gman0 committed Apr 13, 2021
1 parent 7daa30e commit 0dbca73
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions pkg/csi/manila/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ func (d *Driver) initProxiedDriver() (csiNodeCapabilitySet, error) {
if err != nil {
return nil, fmt.Errorf("connecting to %s endpoint failed: %v", d.fwdEndpoint, err)
}
defer conn.Close()

identityClient := d.csiClientBuilder.NewIdentityServiceClient(conn)

Expand Down
1 change: 1 addition & 0 deletions pkg/csi/manila/identityserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func (ids *identityServer) Probe(ctx context.Context, req *csi.ProbeRequest) (*c
if err != nil {
return nil, status.Error(codes.FailedPrecondition, fmtGrpcConnError(ids.d.fwdEndpoint, err))
}
defer csiConn.Close()

return ids.d.csiClientBuilder.NewIdentityServiceClient(csiConn).Probe(ctx, req)
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/csi/manila/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
if err != nil {
return nil, status.Error(codes.Unavailable, fmtGrpcConnError(ns.d.fwdEndpoint, err))
}
defer csiConn.Close()

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

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

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

return ns.d.csiClientBuilder.NewNodeServiceClient(csiConn).UnstageVolume(ctx, req)
}
Expand Down
6 changes: 4 additions & 2 deletions tests/sanity/manila/fakecsiclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ func (c fakeNodeSvcClient) UnpublishVolume(context.Context, *csi.NodeUnpublishVo

type fakeCSIClientBuilder struct{}

func (b fakeCSIClientBuilder) NewConnection(string) (*grpc.ClientConn, error) { return nil, nil }
func (b fakeCSIClientBuilder) NewConnection(string) (*grpc.ClientConn, error) {
return grpc.Dial("", grpc.WithInsecure())
}

func (b fakeCSIClientBuilder) NewConnectionWithContext(context.Context, string) (*grpc.ClientConn, error) {
return nil, nil
return grpc.Dial("", grpc.WithInsecure())
}

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

0 comments on commit 0dbca73

Please sign in to comment.