rbd: check for volume group existence

Signed-off-by: Praveen M <m.praveen@ibm.com>
This commit is contained in:
Praveen M 2025-03-03 13:49:08 +05:30 committed by nixpanic
parent 60ea14eed6
commit 727aad5682

View File

@ -66,7 +66,7 @@ type commonVolumeGroup struct {
}
// generateVolumeGroup generates a commonVolumeGroup structure from the volumeGroup identifier.
func (cvg *commonVolumeGroup) generateVolumeGroup(csiID util.CSIIdentifier) error {
func (cvg *commonVolumeGroup) generateVolumeGroup(ctx context.Context, csiID util.CSIIdentifier) error {
mons, err := util.Mons(util.CsiConfigFile, csiID.ClusterID)
if err != nil {
return fmt.Errorf("failed to get MONs for cluster id %q: %w", csiID.ClusterID, err)
@ -86,16 +86,25 @@ func (cvg *commonVolumeGroup) generateVolumeGroup(csiID util.CSIIdentifier) erro
cvg.namespace = namespace
cvg.pool = pool
// Check if the volume group exists in the journal.
_, err = cvg.getVolumeGroupAttributes(ctx)
if err != nil {
return err
}
return nil
}
// generateVolumeGroupFromMapping checks the clusterID and poolID mapping and
// generates commonVolumeGroup structure for the mapped clusterID and poolID.
// If the mapping is not found, it returns ErrGroupNotFound.
func (cvg *commonVolumeGroup) generateVolumeGroupFromMapping(
ctx context.Context,
csiID util.CSIIdentifier,
mapping *[]util.ClusterMappingInfo,
) error {
var volumeGroupGenerationError error
mcsiID := csiID
existingClusterID := csiID.ClusterID
existingPoolID := strconv.FormatInt(csiID.LocationID, 10)
@ -126,18 +135,18 @@ func (cvg *commonVolumeGroup) generateVolumeGroupFromMapping(
return err
}
mcsiID.LocationID = mPID
err = cvg.generateVolumeGroup(mcsiID)
if ShouldRetryVolumeGroupGeneration(err) {
continue
volumeGroupGenerationError = cvg.generateVolumeGroup(ctx, mcsiID)
if !ShouldRetryVolumeGroupGeneration(volumeGroupGenerationError) {
return volumeGroupGenerationError
}
return err
log.DebugLog(ctx, "volume group not found for poolID mapping %s: %v", cvg.id, mappedPoolID)
}
}
}
}
return util.ErrPoolNotFound
return rbderrors.ErrGroupNotFound
}
func (cvg *commonVolumeGroup) initCommonVolumeGroup(
@ -146,6 +155,7 @@ func (cvg *commonVolumeGroup) initCommonVolumeGroup(
csiDriver string,
creds *util.Credentials,
) error {
var volumeGroupGenerationError error
csiID := util.CSIIdentifier{}
err := csiID.DecomposeCSIID(id)
@ -160,15 +170,15 @@ func (cvg *commonVolumeGroup) initCommonVolumeGroup(
cvg.objectUUID = csiID.ObjectUUID
// cvg.monitors, cvg.namespace, cvg.pool are set in generateVolumeGroup
err = cvg.generateVolumeGroup(csiID)
volumeGroupGenerationError = cvg.generateVolumeGroup(ctx, csiID)
// If the error is not a retryable error, return from here.
if err != nil && !ShouldRetryVolumeGroupGeneration(err) {
return err
if volumeGroupGenerationError != nil && !ShouldRetryVolumeGroupGeneration(volumeGroupGenerationError) {
return volumeGroupGenerationError
}
// If the error is a retryable error, we should try to get the cluster mapping
// and generate the volume group from the mapping.
if ShouldRetryVolumeGroupGeneration(err) {
// If Volume Group doesn't exists or the error is a retryable error,
// we should try to get the cluster mapping and generate the volume group from the mapping.
if ShouldRetryVolumeGroupGeneration(volumeGroupGenerationError) {
mapping, err := util.GetClusterMappingInfo(csiID.ClusterID)
if err != nil {
return err
@ -424,7 +434,7 @@ func (cvg *commonVolumeGroup) GetCreationTime(ctx context.Context) (*time.Time,
//
// It checks if the given error matches any of the following known errors:
// - ErrPoolNotFound: The rbd pool where the volumegroup/omap is expected doesn't exist.
// - ErrRBDGroupNotFound: The volumegroup doesn't exist in the rbd pool.
// - ErrGroupNotFound: The volumegroup doesn't exist in the rbd pool.
// - rados.ErrPermissionDenied: Permissions to access the pool is denied.
//
// If any of these errors are encountered, the function returns `true`, indicating