Skip to content

Commit

Permalink
Merge pull request #587 from jusjin-org/user/jusjin/refactorblobstruct
Browse files Browse the repository at this point in the history
chore: enable blob csi driver to reuse csicommon implementation for unimplemented APIs
  • Loading branch information
k8s-ci-robot authored Dec 15, 2021
2 parents 86d6419 + 790f69c commit 0c2047d
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 88 deletions.
11 changes: 11 additions & 0 deletions pkg/blob/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
42 changes: 0 additions & 42 deletions pkg/blob/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 7 additions & 7 deletions pkg/blob/controllerserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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)
}
}
Expand All @@ -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)
}
}
Expand All @@ -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)
}
}
Expand All @@ -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)
}
}
Expand All @@ -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)
}
}
Expand All @@ -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)
}
}
Expand Down
5 changes: 0 additions & 5 deletions pkg/blob/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <true, nil> if it's already a mounted point otherwise return <false, nil>
func (d *Driver) ensureMountPoint(target string) (bool, error) {
Expand Down
22 changes: 11 additions & 11 deletions pkg/csi-common/controllerserver-default.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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.
Expand All @@ -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")
}
22 changes: 11 additions & 11 deletions pkg/csi-common/controllerserver-default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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)
}
}
Expand All @@ -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)
}
}
Expand All @@ -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)
}
}
Expand All @@ -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)
}
}
Expand All @@ -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)
}
}
Expand All @@ -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)
}
}
Expand All @@ -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)
}
}
Expand All @@ -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)
}
}
Expand All @@ -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)
}
}
Expand All @@ -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)
}
}
12 changes: 6 additions & 6 deletions pkg/csi-common/nodeserver-default.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
12 changes: 6 additions & 6 deletions pkg/csi-common/nodeserver-default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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)
}
}
Expand All @@ -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)
}
}
Expand All @@ -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)
}
}
Expand All @@ -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)
}
}
Expand All @@ -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)
}
}

0 comments on commit 0c2047d

Please sign in to comment.