rbd: make pool optional in rbd sc if topologyconstraints are present

if rbd storage class is created with topologyconstraintspools
replicated pool was still mandatory, making the pool optional if the
topologyconstraintspools is requested

Closes: https://github.com/ceph/ceph-csi/issues/4380

Signed-off-by: parth-gr <partharora1010@gmail.com>
This commit is contained in:
parth-gr
2024-02-26 19:29:58 +05:30
committed by mergify[bot]
parent 5224d58c13
commit 063319f6e5
8 changed files with 42 additions and 16 deletions

View File

@ -76,12 +76,19 @@ func (cs *ControllerServer) validateVolumeReq(ctx context.Context, req *csi.Crea
}
options := req.GetParameters()
if value, ok := options["clusterID"]; !ok || value == "" {
return status.Error(codes.InvalidArgument, "missing or empty cluster ID to provision volume from")
return status.Error(codes.InvalidArgument, "empty cluster ID to provision volume from")
}
if value, ok := options["pool"]; !ok || value == "" {
poolValue, poolOK := options["pool"]
topologyConstrainedPoolsValue, topologyOK := options["topologyConstrainedPools"]
if !poolOK {
if topologyOK && topologyConstrainedPoolsValue == "" {
return status.Error(codes.InvalidArgument, "empty pool name or topologyConstrainedPools to provision volume")
} else if !topologyOK {
return status.Error(codes.InvalidArgument, "missing or empty pool name to provision volume from")
}
} else if poolValue == "" {
return status.Error(codes.InvalidArgument, "missing or empty pool name to provision volume from")
}
if value, ok := options["dataPool"]; ok && value == "" {
return status.Error(codes.InvalidArgument, "empty datapool name to provision volume from")
}
@ -244,6 +251,7 @@ func buildCreateVolumeResponse(req *csi.CreateVolumeRequest, rbdVol *rbdVolume)
VolumeContext: volumeContext,
ContentSource: req.GetVolumeContentSource(),
}
if rbdVol.Topology != nil {
volume.AccessibleTopology = []*csi.Topology{
{
@ -341,6 +349,11 @@ func (cs *ControllerServer) CreateVolume(
return nil, err
}
err = updateTopologyConstraints(rbdVol, rbdSnap)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
found, err := rbdVol.Exists(ctx, parentVol)
if err != nil {
return nil, getGRPCErrorForCreateVolume(err)
@ -358,7 +371,7 @@ func (cs *ControllerServer) CreateVolume(
return nil, err
}
err = reserveVol(ctx, rbdVol, rbdSnap, cr)
err = reserveVol(ctx, rbdVol, cr)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

View File

@ -76,6 +76,10 @@ func validateRbdVol(rbdVol *rbdVolume) error {
return err
}
if err = validateNonEmptyField(rbdVol.JournalPool, "JournalPool", "rbdVolume"); err != nil {
return err
}
if err = validateNonEmptyField(rbdVol.ClusterID, "ClusterID", "rbdVolume"); err != nil {
return err
}
@ -433,6 +437,7 @@ func updateTopologyConstraints(rbdVol *rbdVolume, rbdSnap *rbdSnapshot) error {
if rbdVol.Topology != nil {
rbdVol.Pool = poolName
rbdVol.DataPool = dataPoolName
rbdVol.JournalPool = poolName
}
return nil
@ -446,6 +451,7 @@ func updateTopologyConstraints(rbdVol *rbdVolume, rbdSnap *rbdSnapshot) error {
rbdVol.Pool = poolName
rbdVol.DataPool = dataPoolName
rbdVol.Topology = topology
rbdVol.JournalPool = poolName
}
return nil
@ -453,14 +459,9 @@ func updateTopologyConstraints(rbdVol *rbdVolume, rbdSnap *rbdSnapshot) error {
// reserveVol is a helper routine to request a rbdVolume name reservation and generate the
// volume ID for the generated name.
func reserveVol(ctx context.Context, rbdVol *rbdVolume, rbdSnap *rbdSnapshot, cr *util.Credentials) error {
func reserveVol(ctx context.Context, rbdVol *rbdVolume, cr *util.Credentials) error {
var err error
err = updateTopologyConstraints(rbdVol, rbdSnap)
if err != nil {
return err
}
journalPoolID, imagePoolID, err := util.GetPoolIDs(ctx, rbdVol.Monitors, rbdVol.JournalPool, rbdVol.Pool, cr)
if err != nil {
return err

View File

@ -1270,9 +1270,12 @@ func genVolFromVolumeOptions(
)
rbdVol := &rbdVolume{}
rbdVol.Pool, ok = volOptions["pool"]
if !ok {
return nil, errors.New("missing required parameter pool")
if _, ok = volOptions["topologyConstrainedPools"]; !ok {
return nil, errors.New("empty pool name or topologyConstrainedPools to provision volume")
}
}
rbdVol.DataPool = volOptions["dataPool"]