Skip to content

Commit

Permalink
Ordered initialization for the DRPC condition array
Browse files Browse the repository at this point in the history
Introduce ordered initialization for the condition array in the DRPC module.
This change ensures that the conditions are consistently located in the array,
allowing for easier management and maintenance. Additionally, the updates made
to the code now properly preserve the order of the conditions, providing more
reliable and predictable behavior.

Signed-off-by: Benamar Mekhissi <[email protected]>
(cherry picked from commit e9a78fc)
  • Loading branch information
Benamar Mekhissi authored and raghavendra-talur committed Aug 6, 2023
1 parent 39dd05a commit 88fed3d
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions controllers/drplacementcontrol_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,8 @@ func (r *DRPlacementControlReconciler) Reconcile(ctx context.Context, req ctrl.R
// Save a copy of the instance status to be used for the VRG status update comparison
drpc.Status.DeepCopyInto(&r.savedInstanceStatus)

ensureDRPCConditionsInited(&drpc.Status.Conditions, drpc.Generation, "Initialization")

placementObj, err := r.ownPlacementOrPlacementRule(ctx, drpc, logger)
if err != nil && !(errors.IsNotFound(err) && !drpc.GetDeletionTimestamp().IsZero()) {
r.recordFailure(drpc, placementObj, "Error", err.Error(), nil, logger)
Expand Down Expand Up @@ -1823,3 +1825,30 @@ func addOrUpdateCondition(conditions *[]metav1.Condition, conditionType string,

return false
}

// Initial creation of the DRPC status condition. This will also preserve the ordering of conditions in the array
func ensureDRPCConditionsInited(conditions *[]metav1.Condition, observedGeneration int64, message string) {
const DRPCTotalConditions = 2
if len(*conditions) == DRPCTotalConditions {
return
}

time := metav1.NewTime(time.Now())

setStatusConditionIfNotFound(conditions, metav1.Condition{
Type: rmn.ConditionAvailable,
Reason: string(rmn.Initiating),
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
LastTransitionTime: time,
Message: message,
})
setStatusConditionIfNotFound(conditions, metav1.Condition{
Type: rmn.ConditionPeerReady,
Reason: string(rmn.Initiating),
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
LastTransitionTime: time,
Message: message,
})
}

0 comments on commit 88fed3d

Please sign in to comment.