Skip to content

Commit f287a3b

Browse files
committed
Add ControllerGetVolume implementation
1 parent 7361943 commit f287a3b

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

pkg/csi/cinder/controllerserver.go

+28-2
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,34 @@ func (cs *controllerServer) GetCapacity(ctx context.Context, req *csi.GetCapacit
533533
return nil, status.Error(codes.Unimplemented, fmt.Sprintf("GetCapacity is not yet implemented"))
534534
}
535535

536-
func (cs *controllerServer) ControllerGetVolume(context.Context, *csi.ControllerGetVolumeRequest) (*csi.ControllerGetVolumeResponse, error) {
537-
return nil, status.Error(codes.Unimplemented, fmt.Sprintf("ControllerGetVolume is not yet implemented"))
536+
func (cs *controllerServer) ControllerGetVolume(ctx context.Context, req *csi.ControllerGetVolumeRequest) (*csi.ControllerGetVolumeResponse, error) {
537+
volumeID := req.GetVolumeId()
538+
if len(volumeID) == 0 {
539+
return nil, status.Error(codes.InvalidArgument, "Volume ID not provided")
540+
}
541+
542+
volume, err := cs.Cloud.GetVolume(volumeID)
543+
if err != nil {
544+
if cpoerrors.IsNotFound(err) {
545+
return nil, status.Error(codes.NotFound, "Volume not found")
546+
}
547+
return nil, status.Error(codes.Internal, fmt.Sprintf("ControllerGetVolume failed with error %v", err))
548+
}
549+
550+
ventry := csi.ControllerGetVolumeResponse{
551+
Volume: &csi.Volume{
552+
VolumeId: volumeID,
553+
CapacityBytes: int64(volume.Size * 1024 * 1024 * 1024),
554+
},
555+
}
556+
557+
status := &csi.ControllerGetVolumeResponse_VolumeStatus{}
558+
for _, attachment := range volume.Attachments {
559+
status.PublishedNodeIds = append(status.PublishedNodeIds, attachment.ServerID)
560+
}
561+
ventry.Status = status
562+
563+
return &ventry, nil
538564
}
539565

540566
func (cs *controllerServer) ControllerExpandVolume(ctx context.Context, req *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) {

pkg/csi/cinder/driver.go

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ func NewDriver(nodeID, endpoint, cluster string) *CinderDriver {
8080
csi.ControllerServiceCapability_RPC_EXPAND_VOLUME,
8181
csi.ControllerServiceCapability_RPC_CLONE_VOLUME,
8282
csi.ControllerServiceCapability_RPC_LIST_VOLUMES_PUBLISHED_NODES,
83+
csi.ControllerServiceCapability_RPC_GET_VOLUME,
8384
})
8485
d.AddVolumeCapabilityAccessModes([]csi.VolumeCapability_AccessMode_Mode{csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER})
8586

tests/sanity/cinder/sanity_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"path"
77
"testing"
88

9-
"github.com/kubernetes-csi/csi-test/v3/pkg/sanity"
9+
"github.com/kubernetes-csi/csi-test/pkg/sanity"
1010
"k8s.io/cloud-provider-openstack/pkg/csi/cinder"
1111
"k8s.io/cloud-provider-openstack/pkg/csi/cinder/openstack"
1212
)

0 commit comments

Comments
 (0)