mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-17 20:00:23 +00:00
sort volume ID's for rbd volume list
looping over a map is not guaranteet to be ordered. we need to sort the volume ID's for ListVolume rpc for rbd plugin. Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
parent
e861f12a60
commit
1cedbf0eee
@ -19,6 +19,7 @@ package rbd
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
@ -278,7 +279,7 @@ func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
|
|||||||
|
|
||||||
// ListVolumes returns a list of volumes stored in memory
|
// ListVolumes returns a list of volumes stored in memory
|
||||||
func (cs *ControllerServer) ListVolumes(ctx context.Context, req *csi.ListVolumesRequest) (*csi.ListVolumesResponse, error) {
|
func (cs *ControllerServer) ListVolumes(ctx context.Context, req *csi.ListVolumesRequest) (*csi.ListVolumesResponse, error) {
|
||||||
|
var startToken int
|
||||||
if err := cs.Driver.ValidateControllerServiceRequest(csi.ControllerServiceCapability_RPC_LIST_VOLUMES); err != nil {
|
if err := cs.Driver.ValidateControllerServiceRequest(csi.ControllerServiceCapability_RPC_LIST_VOLUMES); err != nil {
|
||||||
klog.Warningf("invalid list volume req: %v", req)
|
klog.Warningf("invalid list volume req: %v", req)
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -294,16 +295,26 @@ func (cs *ControllerServer) ListVolumes(ctx context.Context, req *csi.ListVolume
|
|||||||
if len(rbdVolumes) < int(i) {
|
if len(rbdVolumes) < int(i) {
|
||||||
return nil, status.Errorf(codes.Aborted, "invalid starting token %s", parseErr.Error())
|
return nil, status.Errorf(codes.Aborted, "invalid starting token %s", parseErr.Error())
|
||||||
}
|
}
|
||||||
|
startToken = int(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
var entries []*csi.ListVolumesResponse_Entry
|
var entries []*csi.ListVolumesResponse_Entry
|
||||||
|
|
||||||
for _, vol := range rbdVolumes {
|
keys := make([]string, 0)
|
||||||
|
for k := range rbdVolumes {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
sort.Strings(keys)
|
||||||
|
|
||||||
|
for index, k := range keys {
|
||||||
|
if index < startToken {
|
||||||
|
continue
|
||||||
|
}
|
||||||
entries = append(entries, &csi.ListVolumesResponse_Entry{
|
entries = append(entries, &csi.ListVolumesResponse_Entry{
|
||||||
Volume: &csi.Volume{
|
Volume: &csi.Volume{
|
||||||
VolumeId: vol.VolID,
|
VolumeId: rbdVolumes[k].VolID,
|
||||||
CapacityBytes: vol.VolSize,
|
CapacityBytes: rbdVolumes[k].VolSize,
|
||||||
VolumeContext: extractStoredVolOpt(vol),
|
VolumeContext: extractStoredVolOpt(rbdVolumes[k]),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user