rbd: check for volume group existence

Signed-off-by: Praveen M <m.praveen@ibm.com>
(cherry picked from commit 8d9f353f15674bd4831e44eae298fc4948286395)

# Conflicts:
#	internal/rbd/group/util.go
This commit is contained in:
Praveen M 2025-03-03 13:49:08 +05:30 committed by Mergify
parent 4dcb9d3a45
commit 4442465fcf

View File

@ -64,6 +64,7 @@ type commonVolumeGroup struct {
journal journal.VolumeGroupJournal
}
<<<<<<< HEAD
func (cvg *commonVolumeGroup) initCommonVolumeGroup(
ctx context.Context,
id string,
@ -76,6 +77,10 @@ func (cvg *commonVolumeGroup) initCommonVolumeGroup(
return fmt.Errorf("failed to decompose volume group id %q: %w", id, err)
}
=======
// generateVolumeGroup generates a commonVolumeGroup structure from the volumeGroup identifier.
func (cvg *commonVolumeGroup) generateVolumeGroup(ctx context.Context, csiID util.CSIIdentifier) error {
>>>>>>> 8d9f353f (rbd: check for volume group existence)
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)
@ -98,16 +103,25 @@ func (cvg *commonVolumeGroup) initCommonVolumeGroup(
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)
@ -138,18 +152,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(
@ -158,6 +172,7 @@ func (cvg *commonVolumeGroup) initCommonVolumeGroup(
csiDriver string,
creds *util.Credentials,
) error {
var volumeGroupGenerationError error
csiID := util.CSIIdentifier{}
err := csiID.DecomposeCSIID(id)
@ -178,15 +193,15 @@ func (cvg *commonVolumeGroup) initCommonVolumeGroup(
=======
// 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
@ -443,7 +458,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