From 790f69cc774bef98a66661f23a48d5502a03d11c Mon Sep 17 00:00:00 2001 From: Justin Jin Date: Tue, 14 Dec 2021 20:43:18 +0800 Subject: [PATCH] chore: enable blob csi driver to reuse csicommon implementation for unimplemented APIs --- pkg/blob/blob.go | 11 +++++ pkg/blob/controllerserver.go | 42 ------------------- pkg/blob/controllerserver_test.go | 14 +++---- pkg/blob/nodeserver.go | 5 --- pkg/csi-common/controllerserver-default.go | 22 +++++----- .../controllerserver-default_test.go | 22 +++++----- pkg/csi-common/nodeserver-default.go | 12 +++--- pkg/csi-common/nodeserver-default_test.go | 12 +++--- 8 files changed, 52 insertions(+), 88 deletions(-) diff --git a/pkg/blob/blob.go b/pkg/blob/blob.go index 39b6ad124..eb79d91cc 100644 --- a/pkg/blob/blob.go +++ b/pkg/blob/blob.go @@ -126,6 +126,13 @@ type DriverOptions struct { // Driver implements all interfaces of CSI drivers type Driver struct { csicommon.CSIDriver + + // Embed these structs to inherit interfaces implementation from csicommon + // Each of them contains a pointer to CSIDriver struct + csicommon.DefaultIdentityServer + csicommon.DefaultControllerServer + csicommon.DefaultNodeServer + cloud *azure.Cloud cloudConfigSecretName string cloudConfigSecretNamespace string @@ -174,6 +181,10 @@ func NewDriver(options *DriverOptions) *Driver { d.Version = driverVersion d.NodeID = options.NodeID + d.DefaultControllerServer.Driver = &d.CSIDriver + d.DefaultIdentityServer.Driver = &d.CSIDriver + d.DefaultNodeServer.Driver = &d.CSIDriver + var err error getter := func(key string) (interface{}, error) { return nil, nil } if d.accountSearchCache, err = azcache.NewTimedcache(time.Minute, getter); err != nil { diff --git a/pkg/blob/controllerserver.go b/pkg/blob/controllerserver.go index bcd453c8d..08980b085 100644 --- a/pkg/blob/controllerserver.go +++ b/pkg/blob/controllerserver.go @@ -411,48 +411,6 @@ func (d *Driver) ControllerGetCapabilities(ctx context.Context, req *csi.Control }, nil } -// GetCapacity returns the capacity of the total available storage pool -func (d *Driver) GetCapacity(ctx context.Context, req *csi.GetCapacityRequest) (*csi.GetCapacityResponse, error) { - return nil, status.Error(codes.Unimplemented, "") -} - -// ListVolumes return all available volumes -func (d *Driver) ListVolumes(ctx context.Context, req *csi.ListVolumesRequest) (*csi.ListVolumesResponse, error) { - return nil, status.Error(codes.Unimplemented, "") -} - -// ControllerGetVolume get volume -func (d *Driver) ControllerGetVolume(context.Context, *csi.ControllerGetVolumeRequest) (*csi.ControllerGetVolumeResponse, error) { - return nil, status.Error(codes.Unimplemented, "") -} - -// ControllerPublishVolume make a volume available on some required node -// N/A for blob driver -func (d *Driver) ControllerPublishVolume(ctx context.Context, req *csi.ControllerPublishVolumeRequest) (*csi.ControllerPublishVolumeResponse, error) { - return nil, status.Error(codes.Unimplemented, "") -} - -// ControllerUnpublishVolume make the volume unavailable on a specified node -// N/A for blob driver -func (d *Driver) ControllerUnpublishVolume(ctx context.Context, req *csi.ControllerUnpublishVolumeRequest) (*csi.ControllerUnpublishVolumeResponse, error) { - return nil, status.Error(codes.Unimplemented, "") -} - -// CreateSnapshot create a snapshot (todo) -func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequest) (*csi.CreateSnapshotResponse, error) { - return nil, status.Error(codes.Unimplemented, "") -} - -// DeleteSnapshot delete a snapshot (todo) -func (d *Driver) DeleteSnapshot(ctx context.Context, req *csi.DeleteSnapshotRequest) (*csi.DeleteSnapshotResponse, error) { - return nil, status.Error(codes.Unimplemented, "") -} - -// ListSnapshots list all snapshots (todo) -func (d *Driver) ListSnapshots(ctx context.Context, req *csi.ListSnapshotsRequest) (*csi.ListSnapshotsResponse, error) { - return nil, status.Error(codes.Unimplemented, "") -} - // ControllerExpandVolume controller expand volume func (d *Driver) ControllerExpandVolume(ctx context.Context, req *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) { if len(req.GetVolumeId()) == 0 { diff --git a/pkg/blob/controllerserver_test.go b/pkg/blob/controllerserver_test.go index 4dc79b71a..df86970f5 100644 --- a/pkg/blob/controllerserver_test.go +++ b/pkg/blob/controllerserver_test.go @@ -492,7 +492,7 @@ func TestGetCapacity(t *testing.T) { req := csi.GetCapacityRequest{} resp, err := d.GetCapacity(context.Background(), &req) assert.Nil(t, resp) - if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "")) { + if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "GetCapacity is not yet implemented")) { t.Errorf("Unexpected error: %v", err) } } @@ -502,7 +502,7 @@ func TestListVolumes(t *testing.T) { req := csi.ListVolumesRequest{} resp, err := d.ListVolumes(context.Background(), &req) assert.Nil(t, resp) - if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "")) { + if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "ListVolumes is not yet implemented")) { t.Errorf("Unexpected error: %v", err) } } @@ -512,7 +512,7 @@ func TestControllerPublishVolume(t *testing.T) { req := csi.ControllerPublishVolumeRequest{} resp, err := d.ControllerPublishVolume(context.Background(), &req) assert.Nil(t, resp) - if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "")) { + if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "ControllerPublishVolume is not yet implemented")) { t.Errorf("Unexpected error: %v", err) } } @@ -522,7 +522,7 @@ func TestControllerUnpublishVolume(t *testing.T) { req := csi.ControllerUnpublishVolumeRequest{} resp, err := d.ControllerUnpublishVolume(context.Background(), &req) assert.Nil(t, resp) - if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "")) { + if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "ControllerUnpublishVolume is not yet implemented")) { t.Errorf("Unexpected error: %v", err) } } @@ -532,7 +532,7 @@ func TestCreateSnapshots(t *testing.T) { req := csi.CreateSnapshotRequest{} resp, err := d.CreateSnapshot(context.Background(), &req) assert.Nil(t, resp) - if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "")) { + if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "CreateSnapshot is not yet implemented")) { t.Errorf("Unexpected error: %v", err) } } @@ -541,7 +541,7 @@ func TestDeleteSnapshots(t *testing.T) { req := csi.DeleteSnapshotRequest{} resp, err := d.DeleteSnapshot(context.Background(), &req) assert.Nil(t, resp) - if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "")) { + if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "DeleteSnapshot is not yet implemented")) { t.Errorf("Unexpected error: %v", err) } } @@ -551,7 +551,7 @@ func TestListSnapshots(t *testing.T) { req := csi.ListSnapshotsRequest{} resp, err := d.ListSnapshots(context.Background(), &req) assert.Nil(t, resp) - if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "")) { + if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "ListSnapshots is not yet implemented")) { t.Errorf("Unexpected error: %v", err) } } diff --git a/pkg/blob/nodeserver.go b/pkg/blob/nodeserver.go index c8f161d77..8bdc2360e 100644 --- a/pkg/blob/nodeserver.go +++ b/pkg/blob/nodeserver.go @@ -446,11 +446,6 @@ func (d *Driver) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVolumeS }, nil } -// NodeExpandVolume node expand volume -func (d *Driver) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandVolumeRequest) (*csi.NodeExpandVolumeResponse, error) { - return nil, status.Error(codes.Unimplemented, "NodeExpandVolume is not yet implemented") -} - // ensureMountPoint: create mount point if not exists // return if it's already a mounted point otherwise return func (d *Driver) ensureMountPoint(target string) (bool, error) { diff --git a/pkg/csi-common/controllerserver-default.go b/pkg/csi-common/controllerserver-default.go index 93b154dd3..976cdcf0c 100644 --- a/pkg/csi-common/controllerserver-default.go +++ b/pkg/csi-common/controllerserver-default.go @@ -28,19 +28,19 @@ type DefaultControllerServer struct { } func (cs *DefaultControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error) { - return nil, status.Error(codes.Unimplemented, "") + return nil, status.Error(codes.Unimplemented, "CreateVolume is not yet implemented") } func (cs *DefaultControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest) (*csi.DeleteVolumeResponse, error) { - return nil, status.Error(codes.Unimplemented, "") + return nil, status.Error(codes.Unimplemented, "DeleteVolume is not yet implemented") } func (cs *DefaultControllerServer) ControllerPublishVolume(ctx context.Context, req *csi.ControllerPublishVolumeRequest) (*csi.ControllerPublishVolumeResponse, error) { - return nil, status.Error(codes.Unimplemented, "") + return nil, status.Error(codes.Unimplemented, "ControllerPublishVolume is not yet implemented") } func (cs *DefaultControllerServer) ControllerUnpublishVolume(ctx context.Context, req *csi.ControllerUnpublishVolumeRequest) (*csi.ControllerUnpublishVolumeResponse, error) { - return nil, status.Error(codes.Unimplemented, "") + return nil, status.Error(codes.Unimplemented, "ControllerUnpublishVolume is not yet implemented") } func (cs *DefaultControllerServer) ValidateVolumeCapabilities(ctx context.Context, req *csi.ValidateVolumeCapabilitiesRequest) (*csi.ValidateVolumeCapabilitiesResponse, error) { @@ -63,11 +63,11 @@ func (cs *DefaultControllerServer) ValidateVolumeCapabilities(ctx context.Contex } func (cs *DefaultControllerServer) ListVolumes(ctx context.Context, req *csi.ListVolumesRequest) (*csi.ListVolumesResponse, error) { - return nil, status.Error(codes.Unimplemented, "") + return nil, status.Error(codes.Unimplemented, "ListVolumes is not yet implemented") } func (cs *DefaultControllerServer) GetCapacity(ctx context.Context, req *csi.GetCapacityRequest) (*csi.GetCapacityResponse, error) { - return nil, status.Error(codes.Unimplemented, "") + return nil, status.Error(codes.Unimplemented, "GetCapacity is not yet implemented") } // ControllerGetCapabilities implements the default GRPC callout. @@ -79,21 +79,21 @@ func (cs *DefaultControllerServer) ControllerGetCapabilities(ctx context.Context } func (cs *DefaultControllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequest) (*csi.CreateSnapshotResponse, error) { - return nil, status.Error(codes.Unimplemented, "") + return nil, status.Error(codes.Unimplemented, "CreateSnapshot is not yet implemented") } func (cs *DefaultControllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteSnapshotRequest) (*csi.DeleteSnapshotResponse, error) { - return nil, status.Error(codes.Unimplemented, "") + return nil, status.Error(codes.Unimplemented, "DeleteSnapshot is not yet implemented") } func (cs *DefaultControllerServer) ListSnapshots(ctx context.Context, req *csi.ListSnapshotsRequest) (*csi.ListSnapshotsResponse, error) { - return nil, status.Error(codes.Unimplemented, "") + return nil, status.Error(codes.Unimplemented, "ListSnapshots is not yet implemented") } func (cs *DefaultControllerServer) ControllerExpandVolume(ctx context.Context, req *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) { - return nil, status.Error(codes.Unimplemented, "") + return nil, status.Error(codes.Unimplemented, "ControllerExpandVolume is not yet implemented") } func (cs *DefaultControllerServer) ControllerGetVolume(ctx context.Context, req *csi.ControllerGetVolumeRequest) (*csi.ControllerGetVolumeResponse, error) { - return nil, status.Error(codes.Unimplemented, "") + return nil, status.Error(codes.Unimplemented, "ControllerGetVolume is not yet implemented") } diff --git a/pkg/csi-common/controllerserver-default_test.go b/pkg/csi-common/controllerserver-default_test.go index 775db1a6a..9aed877c2 100644 --- a/pkg/csi-common/controllerserver-default_test.go +++ b/pkg/csi-common/controllerserver-default_test.go @@ -80,7 +80,7 @@ func TestCreateVolume(t *testing.T) { req := csi.CreateVolumeRequest{} resp, err := cs.CreateVolume(context.Background(), &req) assert.Nil(t, resp) - if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "")) { + if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "CreateVolume is not yet implemented")) { t.Errorf("Unexpected error: %v", err) } } @@ -91,7 +91,7 @@ func TestDeleteVolume(t *testing.T) { req := csi.DeleteVolumeRequest{} resp, err := cs.DeleteVolume(context.Background(), &req) assert.Nil(t, resp) - if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "")) { + if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "DeleteVolume is not yet implemented")) { t.Errorf("Unexpected error: %v", err) } } @@ -102,7 +102,7 @@ func TestControllerPublishVolume(t *testing.T) { req := csi.ControllerPublishVolumeRequest{} resp, err := cs.ControllerPublishVolume(context.Background(), &req) assert.Nil(t, resp) - if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "")) { + if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "ControllerPublishVolume is not yet implemented")) { t.Errorf("Unexpected error: %v", err) } } @@ -113,7 +113,7 @@ func TestControllerUnpublishVolume(t *testing.T) { req := csi.ControllerUnpublishVolumeRequest{} resp, err := cs.ControllerUnpublishVolume(context.Background(), &req) assert.Nil(t, resp) - if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "")) { + if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "ControllerUnpublishVolume is not yet implemented")) { t.Errorf("Unexpected error: %v", err) } } @@ -124,7 +124,7 @@ func TestGetCapacity(t *testing.T) { req := csi.GetCapacityRequest{} resp, err := cs.GetCapacity(context.Background(), &req) assert.Nil(t, resp) - if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "")) { + if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "GetCapacity is not yet implemented")) { t.Errorf("Unexpected error: %v", err) } } @@ -135,7 +135,7 @@ func TestListVolumes(t *testing.T) { req := csi.ListVolumesRequest{} resp, err := cs.ListVolumes(context.Background(), &req) assert.Nil(t, resp) - if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "")) { + if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "ListVolumes is not yet implemented")) { t.Errorf("Unexpected error: %v", err) } } @@ -146,7 +146,7 @@ func TestCreateSnapshot(t *testing.T) { req := csi.CreateSnapshotRequest{} resp, err := cs.CreateSnapshot(context.Background(), &req) assert.Nil(t, resp) - if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "")) { + if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "CreateSnapshot is not yet implemented")) { t.Errorf("Unexpected error: %v", err) } } @@ -157,7 +157,7 @@ func TestDeleteSnapshot(t *testing.T) { req := csi.DeleteSnapshotRequest{} resp, err := cs.DeleteSnapshot(context.Background(), &req) assert.Nil(t, resp) - if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "")) { + if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "DeleteSnapshot is not yet implemented")) { t.Errorf("Unexpected error: %v", err) } } @@ -168,7 +168,7 @@ func TestListSnapshots(t *testing.T) { req := csi.ListSnapshotsRequest{} resp, err := cs.ListSnapshots(context.Background(), &req) assert.Nil(t, resp) - if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "")) { + if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "ListSnapshots is not yet implemented")) { t.Errorf("Unexpected error: %v", err) } } @@ -179,7 +179,7 @@ func TestControllerExpandVolume(t *testing.T) { req := csi.ControllerExpandVolumeRequest{} resp, err := cs.ControllerExpandVolume(context.Background(), &req) assert.Nil(t, resp) - if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "")) { + if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "ControllerExpandVolume is not yet implemented")) { t.Errorf("Unexpected error: %v", err) } } @@ -190,7 +190,7 @@ func TestControllerGetVolume(t *testing.T) { req := csi.ControllerGetVolumeRequest{} resp, err := cs.ControllerGetVolume(context.Background(), &req) assert.Nil(t, resp) - if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "")) { + if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "ControllerGetVolume is not yet implemented")) { t.Errorf("Unexpected error: %v", err) } } diff --git a/pkg/csi-common/nodeserver-default.go b/pkg/csi-common/nodeserver-default.go index 9ff8df267..6ccf4b25b 100644 --- a/pkg/csi-common/nodeserver-default.go +++ b/pkg/csi-common/nodeserver-default.go @@ -40,25 +40,25 @@ func (ns *DefaultNodeServer) NodeGetCapabilities(ctx context.Context, req *csi.N } func (ns *DefaultNodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRequest) (*csi.NodeStageVolumeResponse, error) { - return nil, status.Error(codes.Unimplemented, "") + return nil, status.Error(codes.Unimplemented, "NodeStageVolume is not yet implemented") } func (ns *DefaultNodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstageVolumeRequest) (*csi.NodeUnstageVolumeResponse, error) { - return nil, status.Error(codes.Unimplemented, "") + return nil, status.Error(codes.Unimplemented, "NodeUnstageVolume is not yet implemented") } func (ns *DefaultNodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) { - return nil, status.Error(codes.Unimplemented, "") + return nil, status.Error(codes.Unimplemented, "NodePublishVolume is not yet implemented") } func (ns *DefaultNodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error) { - return nil, status.Error(codes.Unimplemented, "") + return nil, status.Error(codes.Unimplemented, "NodeUnpublishVolume is not yet implemented") } func (ns *DefaultNodeServer) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVolumeStatsRequest) (*csi.NodeGetVolumeStatsResponse, error) { - return nil, status.Error(codes.Unimplemented, "") + return nil, status.Error(codes.Unimplemented, "NodeGetVolumeStats is not yet implemented") } func (ns *DefaultNodeServer) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandVolumeRequest) (*csi.NodeExpandVolumeResponse, error) { - return nil, status.Error(codes.Unimplemented, "") + return nil, status.Error(codes.Unimplemented, "NodeExpandVolume is not yet implemented") } diff --git a/pkg/csi-common/nodeserver-default_test.go b/pkg/csi-common/nodeserver-default_test.go index 73fdd4d9c..e7f203d95 100644 --- a/pkg/csi-common/nodeserver-default_test.go +++ b/pkg/csi-common/nodeserver-default_test.go @@ -56,7 +56,7 @@ func TestNodeStageVolume(t *testing.T) { req := csi.NodeStageVolumeRequest{} resp, err := ns.NodeStageVolume(context.Background(), &req) assert.Nil(t, resp) - if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "")) { + if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "NodeStageVolume is not yet implemented")) { t.Errorf("Unexpected error: %v", err) } } @@ -67,7 +67,7 @@ func TestNodeUnstageVolume(t *testing.T) { req := csi.NodeUnstageVolumeRequest{} resp, err := ns.NodeUnstageVolume(context.Background(), &req) assert.Nil(t, resp) - if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "")) { + if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "NodeUnstageVolume is not yet implemented")) { t.Errorf("Unexpected error: %v", err) } } @@ -78,7 +78,7 @@ func TestNodePublishVolume(t *testing.T) { req := csi.NodePublishVolumeRequest{} resp, err := ns.NodePublishVolume(context.Background(), &req) assert.Nil(t, resp) - if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "")) { + if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "NodePublishVolume is not yet implemented")) { t.Errorf("Unexpected error: %v", err) } } @@ -89,7 +89,7 @@ func TestNodeUnpublishVolume(t *testing.T) { req := csi.NodeUnpublishVolumeRequest{} resp, err := ns.NodeUnpublishVolume(context.Background(), &req) assert.Nil(t, resp) - if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "")) { + if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "NodeUnpublishVolume is not yet implemented")) { t.Errorf("Unexpected error: %v", err) } } @@ -100,7 +100,7 @@ func TestNodeGetVolumeStats(t *testing.T) { req := csi.NodeGetVolumeStatsRequest{} resp, err := ns.NodeGetVolumeStats(context.Background(), &req) assert.Nil(t, resp) - if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "")) { + if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "NodeGetVolumeStats is not yet implemented")) { t.Errorf("Unexpected error: %v", err) } } @@ -111,7 +111,7 @@ func TestNodeExpandVolume(t *testing.T) { req := csi.NodeExpandVolumeRequest{} resp, err := ns.NodeExpandVolume(context.Background(), &req) assert.Nil(t, resp) - if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "")) { + if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "NodeExpandVolume is not yet implemented")) { t.Errorf("Unexpected error: %v", err) } }