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. // 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) mons, err := util.Mons(util.CsiConfigFile, csiID.ClusterID)
if err != nil { if err != nil {
return fmt.Errorf("failed to get MONs for cluster id %q: %w", csiID.ClusterID, err) 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.namespace = namespace
cvg.pool = pool cvg.pool = pool
// Check if the volume group exists in the journal.
_, err = cvg.getVolumeGroupAttributes(ctx)
if err != nil {
return err
}
return nil return nil
} }
// generateVolumeGroupFromMapping checks the clusterID and poolID mapping and // generateVolumeGroupFromMapping checks the clusterID and poolID mapping and
// generates commonVolumeGroup structure for the mapped clusterID and poolID. // generates commonVolumeGroup structure for the mapped clusterID and poolID.
// If the mapping is not found, it returns ErrGroupNotFound.
func (cvg *commonVolumeGroup) generateVolumeGroupFromMapping( func (cvg *commonVolumeGroup) generateVolumeGroupFromMapping(
ctx context.Context, ctx context.Context,
csiID util.CSIIdentifier, csiID util.CSIIdentifier,
mapping *[]util.ClusterMappingInfo, mapping *[]util.ClusterMappingInfo,
) error { ) error {
var volumeGroupGenerationError error
mcsiID := csiID mcsiID := csiID
existingClusterID := csiID.ClusterID existingClusterID := csiID.ClusterID
existingPoolID := strconv.FormatInt(csiID.LocationID, 10) existingPoolID := strconv.FormatInt(csiID.LocationID, 10)
@ -126,18 +135,18 @@ func (cvg *commonVolumeGroup) generateVolumeGroupFromMapping(
return err return err
} }
mcsiID.LocationID = mPID mcsiID.LocationID = mPID
err = cvg.generateVolumeGroup(mcsiID) volumeGroupGenerationError = cvg.generateVolumeGroup(ctx, mcsiID)
if ShouldRetryVolumeGroupGeneration(err) { if !ShouldRetryVolumeGroupGeneration(volumeGroupGenerationError) {
continue 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( func (cvg *commonVolumeGroup) initCommonVolumeGroup(
@ -146,6 +155,7 @@ func (cvg *commonVolumeGroup) initCommonVolumeGroup(
csiDriver string, csiDriver string,
creds *util.Credentials, creds *util.Credentials,
) error { ) error {
var volumeGroupGenerationError error
csiID := util.CSIIdentifier{} csiID := util.CSIIdentifier{}
err := csiID.DecomposeCSIID(id) err := csiID.DecomposeCSIID(id)
@ -160,15 +170,15 @@ func (cvg *commonVolumeGroup) initCommonVolumeGroup(
cvg.objectUUID = csiID.ObjectUUID cvg.objectUUID = csiID.ObjectUUID
// cvg.monitors, cvg.namespace, cvg.pool are set in generateVolumeGroup // 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 the error is not a retryable error, return from here.
if err != nil && !ShouldRetryVolumeGroupGeneration(err) { if volumeGroupGenerationError != nil && !ShouldRetryVolumeGroupGeneration(volumeGroupGenerationError) {
return err return volumeGroupGenerationError
} }
// If the error is a retryable error, we should try to get the cluster mapping // If Volume Group doesn't exists or the error is a retryable error,
// and generate the volume group from the mapping. // we should try to get the cluster mapping and generate the volume group from the mapping.
if ShouldRetryVolumeGroupGeneration(err) { if ShouldRetryVolumeGroupGeneration(volumeGroupGenerationError) {
mapping, err := util.GetClusterMappingInfo(csiID.ClusterID) mapping, err := util.GetClusterMappingInfo(csiID.ClusterID)
if err != nil { if err != nil {
return err 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: // 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. // - 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. // - rados.ErrPermissionDenied: Permissions to access the pool is denied.
// //
// If any of these errors are encountered, the function returns `true`, indicating // If any of these errors are encountered, the function returns `true`, indicating