@@ -106,11 +106,9 @@ func (a *autogenReconciler) handleAgentDeletion(req ctrl.Request) error {
106106 req .Namespace , req .Name , err )
107107 }
108108
109- if team != nil {
110- if err = a .autogenClient .DeleteTeam (team .Id , team .UserID ); err != nil {
111- return fmt .Errorf ("failed to delete agent %s: %w" ,
112- req .NamespacedName .String (), err )
113- }
109+ if err = a .autogenClient .DeleteTeam (team .Id , team .UserID ); err != nil {
110+ return fmt .Errorf ("failed to delete agent %s: %w" ,
111+ req .NamespacedName .String (), err )
114112 }
115113
116114 reconcileLog .Info ("Agent was deleted" , "namespace" , req .Namespace , "name" , req .Name )
@@ -134,7 +132,8 @@ func (a *autogenReconciler) handleExistingAgent(ctx context.Context, agent *v1al
134132 "newGeneration" , agent .Generation )
135133 }
136134
137- if err := a .reconcileAgents (ctx , agent ); err != nil {
135+ err := a .reconcileAgents (ctx , agent )
136+ if err != nil {
138137 return fmt .Errorf ("failed to reconcile agent %s/%s: %w" ,
139138 req .Namespace , req .Name , err )
140139 }
@@ -145,7 +144,7 @@ func (a *autogenReconciler) handleExistingAgent(ctx context.Context, agent *v1al
145144 req .Namespace , req .Name , err )
146145 }
147146
148- return a .reconcileAgentStatus ( ctx , agent , a . reconcileTeams (ctx , teams ... ) )
147+ return a .reconcileTeams (ctx , teams ... )
149148}
150149
151150func (a * autogenReconciler ) reconcileAgentStatus (ctx context.Context , agent * v1alpha1.Agent , err error ) error {
@@ -472,28 +471,33 @@ func (a *autogenReconciler) reconcileTeams(ctx context.Context, teams ...*v1alph
472471}
473472
474473func (a * autogenReconciler ) reconcileAgents (ctx context.Context , agents ... * v1alpha1.Agent ) error {
475- errs := map [types. NamespacedName ] error {}
474+ var multiErr * multierror. Error
476475 for _ , agent := range agents {
477- autogenTeam , err := a .autogenTranslator . TranslateGroupChatForAgent (ctx , agent )
478- if err != nil {
479- errs [types. NamespacedName { Name : agent . Name , Namespace : agent . Namespace }] = fmt . Errorf (
480- "failed to translate agent %s/%s: %v" , agent . Namespace , agent . Name , err )
481- continue
476+ reconcileErr := a .reconcileAgent (ctx , agent )
477+ // Append error but still try to reconcile the agent status
478+ if reconcileErr != nil {
479+ multiErr = multierror . Append ( multiErr , fmt . Errorf (
480+ "failed to reconcile agent %s/%s: %v" , agent . Namespace , agent . Name , reconcileErr ))
482481 }
483- if err := a .reconcileA2A (ctx , autogenTeam , agent ); err != nil {
484- errs [types.NamespacedName {Name : agent .Name , Namespace : agent .Namespace }] = fmt .Errorf (
485- "failed to reconcile A2A for agent %s/%s: %v" , agent .Namespace , agent .Name , err )
486- continue
487- }
488- if err := a .upsertTeam (autogenTeam ); err != nil {
489- errs [types.NamespacedName {Name : agent .Name , Namespace : agent .Namespace }] = fmt .Errorf (
490- "failed to upsert agent %s/%s: %v" , agent .Namespace , agent .Name , err )
491- continue
482+ if err := a .reconcileAgentStatus (ctx , agent , reconcileErr ); err != nil {
483+ multiErr = multierror .Append (multiErr , fmt .Errorf (
484+ "failed to reconcile agent status %s/%s: %v" , agent .Namespace , agent .Name , err ))
492485 }
493486 }
494487
495- if len (errs ) > 0 {
496- return fmt .Errorf ("failed to reconcile agents: %v" , errs )
488+ return multiErr .ErrorOrNil ()
489+ }
490+
491+ func (a * autogenReconciler ) reconcileAgent (ctx context.Context , agent * v1alpha1.Agent ) error {
492+ autogenTeam , err := a .autogenTranslator .TranslateGroupChatForAgent (ctx , agent )
493+ if err != nil {
494+ return fmt .Errorf ("failed to translate agent %s/%s: %v" , agent .Namespace , agent .Name , err )
495+ }
496+ if err := a .reconcileA2A (ctx , autogenTeam , agent ); err != nil {
497+ return fmt .Errorf ("failed to reconcile A2A for agent %s/%s: %v" , agent .Namespace , agent .Name , err )
498+ }
499+ if err := a .upsertTeam (autogenTeam ); err != nil {
500+ return fmt .Errorf ("failed to upsert agent %s/%s: %v" , agent .Namespace , agent .Name , err )
497501 }
498502
499503 return nil
@@ -530,7 +534,7 @@ func (a *autogenReconciler) upsertTeam(team *autogen_client.Team) error {
530534
531535 // delete if team exists
532536 existingTeam , err := a .autogenClient .GetTeam (team .Component .Label , common .GetGlobalUserID ())
533- if err != nil {
537+ if err != nil && err != autogen_client . NotFoundError {
534538 return fmt .Errorf ("failed to get existing team %s: %v" , team .Component .Label , err )
535539 }
536540 if existingTeam != nil {
@@ -587,7 +591,7 @@ func (a *autogenReconciler) findAgentsUsingModel(ctx context.Context, req ctrl.R
587591 var agents []* v1alpha1.Agent
588592 for i := range agentsList .Items {
589593 agent := & agentsList .Items [i ]
590- agentNamespaced , err := common .ParseRefString (agent .Spec .ModelConfig , agent .Namespace );
594+ agentNamespaced , err := common .ParseRefString (agent .Spec .ModelConfig , agent .Namespace )
591595
592596 if err != nil {
593597 reconcileLog .Error (err , "failed to parse Agent ModelConfig" ,
@@ -668,7 +672,7 @@ func (a *autogenReconciler) findAgentsUsingMemory(ctx context.Context, req ctrl.
668672 for i := range agentsList .Items {
669673 agent := & agentsList .Items [i ]
670674 for _ , memory := range agent .Spec .Memory {
671- memoryNamespaced , err := common .ParseRefString (memory , agent .Namespace );
675+ memoryNamespaced , err := common .ParseRefString (memory , agent .Namespace )
672676
673677 if err != nil {
674678 reconcileLog .Error (err , "failed to parse Agent Memory" ,
@@ -700,7 +704,7 @@ func (a *autogenReconciler) findTeamsUsingAgent(ctx context.Context, req ctrl.Re
700704 for i := range teamsList .Items {
701705 team := & teamsList .Items [i ]
702706 for _ , participant := range team .Spec .Participants {
703- participantNamespaced , err := common .ParseRefString (participant , team .Namespace );
707+ participantNamespaced , err := common .ParseRefString (participant , team .Namespace )
704708
705709 if err != nil {
706710 reconcileLog .Error (err , "failed to parse Team participant" ,
@@ -768,7 +772,7 @@ func (a *autogenReconciler) findTeamsUsingApiKeySecret(ctx context.Context, req
768772 "model" , model .Name ,
769773 "namespace" , model .Namespace ,
770774 )
771- default :
775+ default :
772776 reconcileLog .Error (err , "failed to parse ModelConfig APIKeySecretRef" ,
773777 "errorDetails" , e .Error (),
774778 "model" , model .Name ,
0 commit comments