Skip to content

Commit

Permalink
Fail DRPC reconciliation if DRPolicy is marked for deletion
Browse files Browse the repository at this point in the history
Signed-off-by: Elena Gershkovich <[email protected]>
(cherry picked from commit 703b2a0)
  • Loading branch information
ELENAGER authored and ShyamsundarR committed Aug 30, 2023
1 parent d0bdb2d commit f89367d
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions controllers/drplacementcontrol_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ func (r *DRPlacementControlReconciler) setLastSyncBytesMetric(syncDataBytesMetri
syncDataBytesMetrics.LastSyncDataBytes.Set(float64(*b))
}

//nolint:funlen
//nolint:funlen,cyclop
func (r *DRPlacementControlReconciler) createDRPCInstance(
ctx context.Context,
drpc *rmn.DRPlacementControl,
Expand All @@ -744,6 +744,13 @@ func (r *DRPlacementControlReconciler) createDRPCInstance(
return nil, fmt.Errorf("failed to get DRPolicy %w", err)
}

if !drPolicy.ObjectMeta.DeletionTimestamp.IsZero() {
// If drpolicy is deleted then return
// error to fail drpc reconciliation
return nil, fmt.Errorf("drPolicy '%s' referred by the DRPC is deleted, DRPC reconciliation would fail",
drpc.Spec.DRPolicyRef.Name)
}

if err := r.addLabelsAndFinalizers(ctx, drpc, placementObj, log); err != nil {
return nil, err
}
Expand Down Expand Up @@ -894,14 +901,6 @@ func (r *DRPlacementControlReconciler) getDRPolicy(ctx context.Context,
return nil, fmt.Errorf("%w", err)
}

if !drPolicy.ObjectMeta.DeletionTimestamp.IsZero() &&
!controllerutil.ContainsFinalizer(drpc, DRPCFinalizer) {
// If drpolicy is deleted and drpc finalizer is not present then return
// error to fail drpc reconciliation
return nil, fmt.Errorf("drPolicy '%s/%s' referred by the DRPC is deleted, DRPC reconciliation would fail",
name, namespace)
}

return drPolicy, nil
}

Expand Down

0 comments on commit f89367d

Please sign in to comment.