Skip to content

Commit

Permalink
Merge pull request kubernetes-csi#318 from yeya24/use-csi-client
Browse files Browse the repository at this point in the history
reuse same CSI controller client
  • Loading branch information
k8s-ci-robot authored Aug 4, 2021
2 parents f523b0f + 67cf03d commit 0691388
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
12 changes: 4 additions & 8 deletions pkg/attacher/attacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type Attacher interface {
}

type attacher struct {
conn *grpc.ClientConn
client csi.ControllerClient
capabilities []csi.ControllerServiceCapability
}

Expand All @@ -53,13 +53,11 @@ var (
// NewAttacher provides a new Attacher object.
func NewAttacher(conn *grpc.ClientConn) Attacher {
return &attacher{
conn: conn,
client: csi.NewControllerClient(conn),
}
}

func (a *attacher) Attach(ctx context.Context, volumeID string, readOnly bool, nodeID string, caps *csi.VolumeCapability, context, secrets map[string]string) (metadata map[string]string, detached bool, err error) {
client := csi.NewControllerClient(a.conn)

req := csi.ControllerPublishVolumeRequest{
VolumeId: volumeID,
NodeId: nodeID,
Expand All @@ -69,23 +67,21 @@ func (a *attacher) Attach(ctx context.Context, volumeID string, readOnly bool, n
Secrets: secrets,
}

rsp, err := client.ControllerPublishVolume(ctx, &req)
rsp, err := a.client.ControllerPublishVolume(ctx, &req)
if err != nil {
return nil, isFinalError(err), err
}
return rsp.PublishContext, false, nil
}

func (a *attacher) Detach(ctx context.Context, volumeID string, nodeID string, secrets map[string]string) error {
client := csi.NewControllerClient(a.conn)

req := csi.ControllerUnpublishVolumeRequest{
VolumeId: volumeID,
NodeId: nodeID,
Secrets: secrets,
}

_, err := client.ControllerUnpublishVolume(ctx, &req)
_, err := a.client.ControllerUnpublishVolume(ctx, &req)
return err
}

Expand Down
8 changes: 3 additions & 5 deletions pkg/attacher/lister.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,22 @@ import (
)

type CSIVolumeLister struct {
conn *grpc.ClientConn
client csi.ControllerClient
}

// NewVolumeLister provides a new VolumeLister object.
func NewVolumeLister(conn *grpc.ClientConn) *CSIVolumeLister {
return &CSIVolumeLister{
conn: conn,
client: csi.NewControllerClient(conn),
}
}

func (a *CSIVolumeLister) ListVolumes(ctx context.Context) (map[string]([]string), error) {
client := csi.NewControllerClient(a.conn)

p := map[string][]string{}

tok := ""
for {
rsp, err := client.ListVolumes(ctx, &csi.ListVolumesRequest{
rsp, err := a.client.ListVolumes(ctx, &csi.ListVolumesRequest{
StartingToken: tok,
})
if err != nil {
Expand Down

0 comments on commit 0691388

Please sign in to comment.