@@ -70,10 +70,7 @@ func (r *AgentController) SetupWithManager(mgr ctrl.Manager) error {
7070 WithOptions (controller.Options {
7171 NeedLeaderElection : ptr .To (true ),
7272 }).
73- // Use custom predicate that always processes Create/Delete events,
74- // but filters Update events to only process when generation or labels change.
75- // This fixes a bug where some agents were not reconciled on startup.
76- For (& v1alpha2.Agent {}, builder .WithPredicates (agentPredicate {}))
73+ For (& v1alpha2.Agent {}, builder .WithPredicates (predicate .Or (predicate.GenerationChangedPredicate {}, predicate.LabelChangedPredicate {})))
7774
7875 // Setup owns relationships for resources created by the Agent controller -
7976 // for now ownership of agent resources is handled by the ADK translator
@@ -331,48 +328,3 @@ type typedOwnedObjectPredicate[object metav1.Object] struct {
331328func (typedOwnedObjectPredicate [object ]) Create (e event.TypedCreateEvent [object ]) bool {
332329 return false
333330}
334-
335- // agentPredicate is a custom predicate for Agent resources that:
336- // - Always processes Create events (ensures all agents are reconciled on startup)
337- // - Always processes Delete events
338- // - For Update events, only processes if generation or labels changed
339- // This fixes a bug where GenerationChangedPredicate combined with LabelChangedPredicate
340- // could inconsistently filter out Create events for some agents.
341- type agentPredicate struct {}
342-
343- func (agentPredicate ) Create (e event.CreateEvent ) bool {
344- // Always process Create events - this ensures all agents are reconciled on startup
345- return true
346- }
347-
348- func (agentPredicate ) Delete (e event.DeleteEvent ) bool {
349- // Always process Delete events
350- return true
351- }
352-
353- func (agentPredicate ) Update (e event.UpdateEvent ) bool {
354- if e .ObjectOld == nil || e .ObjectNew == nil {
355- return false
356- }
357- // Process if generation changed (spec was modified)
358- if e .ObjectNew .GetGeneration () != e .ObjectOld .GetGeneration () {
359- return true
360- }
361- // Process if labels changed
362- oldLabels := e .ObjectOld .GetLabels ()
363- newLabels := e .ObjectNew .GetLabels ()
364- if len (oldLabels ) != len (newLabels ) {
365- return true
366- }
367- for k , v := range oldLabels {
368- if newLabels [k ] != v {
369- return true
370- }
371- }
372- return false
373- }
374-
375- func (agentPredicate ) Generic (e event.GenericEvent ) bool {
376- // Always process Generic events
377- return true
378- }
0 commit comments