@@ -589,9 +589,6 @@ func (d *DependenciesDistributor) createOrUpdateAttachedBinding(attachedBinding
589589
590590		mergedRequiredBy  :=  mergeBindingSnapshot (existBinding .Spec .RequiredBy , attachedBinding .Spec .RequiredBy )
591591
592- 		conflictDetected  :=  false 
593- 		var  conflictReasons  []string 
594- 
595592		// If the spec.Placement is nil, this means that existBinding is generated by the dependency mechanism. 
596593		// If the spec.Placement is not nil, then it must be generated by PropagationPolicy. 
597594		if  existBinding .Spec .Placement  ==  nil  {
@@ -600,20 +597,14 @@ func (d *DependenciesDistributor) createOrUpdateAttachedBinding(attachedBinding
600597				klog .Errorf ("Failed to check conflict for resourceBinding(%s): %v" , bindingKey , err )
601598				return  err 
602599			}
603- 			if  crConflictDetected  {
604- 				conflictDetected  =  true 
605- 				conflictReasons  =  append (conflictReasons , "ConflictResolution mismatch (Overwrite vs Abort)" )
606- 			}
607600
608601			preserveConflictDetected , err  :=  d .conflictDetectedForPreserveOnDeletion (mergedRequiredBy )
609602			if  err  !=  nil  {
610603				klog .Errorf ("Failed to check preserveOnDeletion conflict for resourceBinding(%s): %v" , bindingKey , err )
611604				return  err 
612605			}
613- 			if  preserveConflictDetected  {
614- 				conflictDetected  =  true 
615- 				conflictReasons  =  append (conflictReasons , "PreserveResourcesOnDeletion mismatch (true vs false)" )
616- 			}
606+ 
607+ 			d .recordEventIfPolicyConflict (existBinding , crConflictDetected , preserveConflictDetected )
617608
618609			existBinding .Spec .ConflictResolution  =  attachedBinding .Spec .ConflictResolution 
619610		}
@@ -623,13 +614,6 @@ func (d *DependenciesDistributor) createOrUpdateAttachedBinding(attachedBinding
623614		existBinding .Spec .Resource  =  attachedBinding .Spec .Resource 
624615		existBinding .Spec .PreserveResourcesOnDeletion  =  attachedBinding .Spec .PreserveResourcesOnDeletion 
625616
626- 		if  conflictDetected  &&  d .EventRecorder  !=  nil  {
627- 			// Emit a warning event indicating which policies conflicted. 
628- 			// Use placeholders to include the concrete conflicting dimensions in the message. 
629- 			message  :=  "Dependency policy conflict detected: %s." 
630- 			d .EventRecorder .Eventf (existBinding , corev1 .EventTypeWarning , events .EventReasonDependencyPolicyConflict , message , strings .Join (conflictReasons , "; " ))
631- 		}
632- 
633617		if  err  :=  d .Client .Update (context .TODO (), existBinding ); err  !=  nil  {
634618			klog .Errorf ("Failed to update resourceBinding(%s): %v" , bindingKey , err )
635619			return  err 
@@ -645,52 +629,26 @@ func (d *DependenciesDistributor) createOrUpdateAttachedBinding(attachedBinding
645629	return  d .Client .Create (context .TODO (), attachedBinding )
646630}
647631
648- // conflictDetectedForConflictResolution checks if there is a conflict in ConflictResolution from referencing ResourceBindings. 
649- // Rules: any Overwrite -> Overwrite; else Abort. Returns whether a conflict was detected. 
650- func  (d  * DependenciesDistributor ) conflictDetectedForConflictResolution (requiredBy  []workv1alpha2.BindingSnapshot ) (hasConflict  bool , err  error ) {
651- 	hasOverwrite  :=  false 
652- 	hasAbort  :=  false 
653- 
654- 	for  _ , snap  :=  range  requiredBy  {
655- 		refRB  :=  & workv1alpha2.ResourceBinding {}
656- 		if  err  :=  d .Client .Get (context .TODO (), client.ObjectKey {Namespace : snap .Namespace , Name : snap .Name }, refRB ); err  !=  nil  {
657- 			return  false , err 
658- 		}
632+ func  (d  * DependenciesDistributor ) recordEventIfPolicyConflict (existBinding  * workv1alpha2.ResourceBinding , crConflictDetected , preserveConflictDetected  bool ) {
633+ 	conflictDetected  :=  false 
634+ 	var  conflictReasons  []string 
659635
660- 		cr  :=  effectiveConflictResolution (refRB .Spec .ConflictResolution )
661- 		if  cr  ==  policyv1alpha1 .ConflictOverwrite  {
662- 			hasOverwrite  =  true 
663- 		} else  {
664- 			hasAbort  =  true 
665- 		}
636+ 	if  crConflictDetected  {
637+ 		conflictDetected  =  true 
638+ 		conflictReasons  =  append (conflictReasons , "ConflictResolution mismatch (Overwrite vs Abort)" )
666639	}
667640
668- 	hasConflict  =  hasOverwrite  &&  hasAbort 
669- 	return  hasConflict , nil 
670- }
671- 
672- // conflictDetectedForPreserveOnDeletion checks if there is a conflict in PreserveResourcesOnDeletion from referencing ResourceBindings. 
673- // Rules: any true -> true; else false. Returns whether a conflict was detected. 
674- func  (d  * DependenciesDistributor ) conflictDetectedForPreserveOnDeletion (requiredBy  []workv1alpha2.BindingSnapshot ) (hasConflict  bool , err  error ) {
675- 	seenTrue  :=  false 
676- 	seenFalse  :=  false 
677- 
678- 	for  _ , snap  :=  range  requiredBy  {
679- 		refRB  :=  & workv1alpha2.ResourceBinding {}
680- 		if  err  :=  d .Client .Get (context .TODO (), client.ObjectKey {Namespace : snap .Namespace , Name : snap .Name }, refRB ); err  !=  nil  {
681- 			return  false , err 
682- 		}
683- 
684- 		pres  :=  ptr .Deref (refRB .Spec .PreserveResourcesOnDeletion , false )
685- 		if  pres  {
686- 			seenTrue  =  true 
687- 		} else  {
688- 			seenFalse  =  true 
689- 		}
641+ 	if  preserveConflictDetected  {
642+ 		conflictDetected  =  true 
643+ 		conflictReasons  =  append (conflictReasons , "PreserveResourcesOnDeletion mismatch (true vs false)" )
690644	}
691645
692- 	hasConflict  =  seenTrue  &&  seenFalse 
693- 	return  hasConflict , nil 
646+ 	if  conflictDetected  {
647+ 		// Emit a warning event indicating which policies conflicted. 
648+ 		// Use placeholders to include the concrete conflicting dimensions in the message. 
649+ 		message  :=  "Dependency policy conflict detected: %s." 
650+ 		d .EventRecorder .Eventf (existBinding , corev1 .EventTypeWarning , events .EventReasonDependencyPolicyConflict , message , strings .Join (conflictReasons , "; " ))
651+ 	}
694652}
695653
696654// Start runs the distributor, never stop until context canceled. 
0 commit comments