@@ -764,52 +764,55 @@ func setBindingStatus(works map[string]*fleetv1beta1.Work, resourceBinding *flee
764764 resourceBinding .Status .DiffedPlacements = nil
765765 resourceBinding .Status .DriftedPlacements = nil
766766 // collect and set the failed resource placements to the binding if not all the works are available
767- if appliedCond .Status != metav1 .ConditionTrue || availableCond .Status != metav1 .ConditionTrue {
768- failedResourcePlacements := make ([]fleetv1beta1.FailedResourcePlacement , 0 , maxFailedResourcePlacementLimit ) // preallocate the memory
769- diffedResourcePlacements := make ([]fleetv1beta1.DiffedResourcePlacement , 0 , maxDiffedResourcePlacementLimit ) // preallocate the memory
770- driftedResourcePlacements := make ([]fleetv1beta1.DriftedResourcePlacement , 0 , maxDriftedResourcePlacementLimit ) // preallocate the memory
771- for _ , w := range works {
772- if w .DeletionTimestamp != nil {
773- klog .V (2 ).InfoS ("Ignoring the deleting work" , "clusterResourceBinding" , bindingRef , "work" , klog .KObj (w ))
774- continue // ignore the deleting work
775- }
767+ driftedResourcePlacements := make ([]fleetv1beta1.DriftedResourcePlacement , 0 , maxDriftedResourcePlacementLimit ) // preallocate the memory
768+ failedResourcePlacements := make ([]fleetv1beta1.FailedResourcePlacement , 0 , maxFailedResourcePlacementLimit ) // preallocate the memory
769+ diffedResourcePlacements := make ([]fleetv1beta1.DiffedResourcePlacement , 0 , maxDiffedResourcePlacementLimit ) // preallocate the memory
770+ for _ , w := range works {
771+ if w .DeletionTimestamp != nil {
772+ klog .V (2 ).InfoS ("Ignoring the deleting work" , "clusterResourceBinding" , bindingRef , "work" , klog .KObj (w ))
773+ continue // ignore the deleting work
774+ }
775+
776+ // Failed placements (resources that cannot be applied or failed to get available) will only appear when either
777+ // the Applied or Available conditions (on the work object) are set to False
778+ if appliedCond .Status != metav1 .ConditionTrue || availableCond .Status != metav1 .ConditionTrue {
776779 failedManifests := extractFailedResourcePlacementsFromWork (w )
777780 failedResourcePlacements = append (failedResourcePlacements , failedManifests ... )
778-
781+ }
782+ // Diffed placements can only appear when the Applied condition is set to False.
783+ if appliedCond .Status == metav1 .ConditionFalse {
779784 diffedManifests := extractDiffedResourcePlacementsFromWork (w )
780785 diffedResourcePlacements = append (diffedResourcePlacements , diffedManifests ... )
781-
782- driftedManifests := extractDriftedResourcePlacementsFromWork (w )
783- driftedResourcePlacements = append (driftedResourcePlacements , driftedManifests ... )
784- }
785- // cut the list to keep only the max limit
786- if len (failedResourcePlacements ) > maxFailedResourcePlacementLimit {
787- failedResourcePlacements = failedResourcePlacements [0 :maxFailedResourcePlacementLimit ]
788- }
789- resourceBinding .Status .FailedPlacements = failedResourcePlacements
790- if len (failedResourcePlacements ) > 0 {
791- klog .V (2 ).InfoS ("Populated failed manifests" , "clusterResourceBinding" , bindingRef , "numberOfFailedPlacements" , len (failedResourcePlacements ))
792- }
793-
794- // cut the list to keep only the max limit
795- if len (diffedResourcePlacements ) > maxDiffedResourcePlacementLimit {
796- diffedResourcePlacements = diffedResourcePlacements [0 :maxDiffedResourcePlacementLimit ]
797- }
798-
799- if len (diffedResourcePlacements ) > 0 {
800- resourceBinding .Status .DiffedPlacements = diffedResourcePlacements
801- klog .V (2 ).InfoS ("Populated diffed manifests" , "clusterResourceBinding" , bindingRef , "numberOfDiffedPlacements" , len (diffedResourcePlacements ))
802786 }
787+ // Drifted placements can appear in any situation (Applied condition is True or False)
788+ driftedManifests := extractDriftedResourcePlacementsFromWork (w )
789+ driftedResourcePlacements = append (driftedResourcePlacements , driftedManifests ... )
790+ }
791+ // cut the list to keep only the max limit
792+ if len (failedResourcePlacements ) > maxFailedResourcePlacementLimit {
793+ failedResourcePlacements = failedResourcePlacements [0 :maxFailedResourcePlacementLimit ]
794+ }
795+ resourceBinding .Status .FailedPlacements = failedResourcePlacements
796+ if len (failedResourcePlacements ) > 0 {
797+ klog .V (2 ).InfoS ("Populated failed manifests" , "clusterResourceBinding" , bindingRef , "numberOfFailedPlacements" , len (failedResourcePlacements ))
798+ }
803799
804- // cut the list to keep only the max limit
805- if len (driftedResourcePlacements ) > maxDriftedResourcePlacementLimit {
806- driftedResourcePlacements = driftedResourcePlacements [0 :maxDriftedResourcePlacementLimit ]
807- }
800+ // cut the list to keep only the max limit
801+ if len (diffedResourcePlacements ) > maxDiffedResourcePlacementLimit {
802+ diffedResourcePlacements = diffedResourcePlacements [0 :maxDiffedResourcePlacementLimit ]
803+ }
804+ if len (diffedResourcePlacements ) > 0 {
805+ resourceBinding .Status .DiffedPlacements = diffedResourcePlacements
806+ klog .V (2 ).InfoS ("Populated diffed manifests" , "clusterResourceBinding" , bindingRef , "numberOfDiffedPlacements" , len (diffedResourcePlacements ))
807+ }
808808
809- if len (driftedResourcePlacements ) > 0 {
810- resourceBinding .Status .DriftedPlacements = driftedResourcePlacements
811- klog .V (2 ).InfoS ("Populated drifted manifests" , "clusterResourceBinding" , bindingRef , "numberOfDriftedPlacements" , len (driftedResourcePlacements ))
812- }
809+ // cut the list to keep only the max limit
810+ if len (driftedResourcePlacements ) > maxDriftedResourcePlacementLimit {
811+ driftedResourcePlacements = driftedResourcePlacements [0 :maxDriftedResourcePlacementLimit ]
812+ }
813+ if len (driftedResourcePlacements ) > 0 {
814+ resourceBinding .Status .DriftedPlacements = driftedResourcePlacements
815+ klog .V (2 ).InfoS ("Populated drifted manifests" , "clusterResourceBinding" , bindingRef , "numberOfDriftedPlacements" , len (driftedResourcePlacements ))
813816 }
814817}
815818
@@ -1151,17 +1154,22 @@ func (r *Reconciler) SetupWithManager(mgr controllerruntime.Manager) error {
11511154 newAvailableCondition := meta .FindStatusCondition (newWork .Status .Conditions , fleetv1beta1 .WorkConditionTypeAvailable )
11521155
11531156 // we try to filter out events, we only need to handle the updated event if the applied or available condition flip between true and false
1154- // or the failed placements are changed.
1157+ // or the failed/diffed/drifted placements are changed.
11551158 if condition .EqualCondition (oldAppliedCondition , newAppliedCondition ) && condition .EqualCondition (oldAvailableCondition , newAvailableCondition ) {
1159+ oldDriftedPlacements := extractDriftedResourcePlacementsFromWork (oldWork )
1160+ newDriftedPlacements := extractDriftedResourcePlacementsFromWork (newWork )
1161+ driftsEqual := utils .IsDriftedResourcePlacementsEqual (oldDriftedPlacements , newDriftedPlacements )
11561162 if condition .IsConditionStatusFalse (newAppliedCondition , newWork .Generation ) || condition .IsConditionStatusFalse (newAvailableCondition , newWork .Generation ) {
1163+ diffsEqual := true
1164+ if condition .IsConditionStatusFalse (newAppliedCondition , newWork .Generation ) {
1165+ oldDiffedPlacements := extractDiffedResourcePlacementsFromWork (oldWork )
1166+ newDiffedPlacements := extractDiffedResourcePlacementsFromWork (newWork )
1167+ diffsEqual = utils .IsDiffedResourcePlacementsEqual (oldDiffedPlacements , newDiffedPlacements )
1168+ }
11571169 // we need to compare the failed placement if the work is not applied or available
11581170 oldFailedPlacements := extractFailedResourcePlacementsFromWork (oldWork )
11591171 newFailedPlacements := extractFailedResourcePlacementsFromWork (newWork )
1160- oldDiffedPlacements := extractDiffedResourcePlacementsFromWork (oldWork )
1161- newDiffedPlacements := extractDiffedResourcePlacementsFromWork (newWork )
1162- oldDriftedPlacements := extractDriftedResourcePlacementsFromWork (oldWork )
1163- newDriftedPlacements := extractDriftedResourcePlacementsFromWork (newWork )
1164- if utils .IsDriftedResourcePlacementsEqual (oldDriftedPlacements , newDriftedPlacements ) && utils .IsDiffedResourcePlacementsEqual (oldDiffedPlacements , newDiffedPlacements ) && utils .IsFailedResourcePlacementsEqual (oldFailedPlacements , newFailedPlacements ) {
1172+ if driftsEqual && diffsEqual && utils .IsFailedResourcePlacementsEqual (oldFailedPlacements , newFailedPlacements ) {
11651173 klog .V (2 ).InfoS ("The placement lists didn't change on failed work, no need to reconcile" , "oldWork" , klog .KObj (oldWork ), "newWork" , klog .KObj (newWork ))
11661174 return
11671175 }
@@ -1179,7 +1187,7 @@ func (r *Reconciler) SetupWithManager(mgr controllerruntime.Manager) error {
11791187 // When the normal update happens, the controller will set the applied condition as false and wait
11801188 // until the work condition has been changed.
11811189 // In this edge case, we need to requeue the binding to update the binding status.
1182- if oldResourceSnapshot == newResourceSnapshot {
1190+ if oldResourceSnapshot == newResourceSnapshot && driftsEqual {
11831191 klog .V (2 ).InfoS ("The work applied or available condition stayed as true, no need to reconcile" , "oldWork" , klog .KObj (oldWork ), "newWork" , klog .KObj (newWork ))
11841192 return
11851193 }
0 commit comments