Skip to content

Commit 7eb8a15

Browse files
committed
feat: Watch for AgentRuntimeConfiguration changes to enqueue all agents
1 parent e8ce981 commit 7eb8a15

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

internal/controller/agent_reconciler.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,10 @@ func (r *AgentReconciler) SetupWithManager(mgr ctrl.Manager) error {
353353
Watches(
354354
&runtimev1alpha1.ToolServer{},
355355
handler.EnqueueRequestsFromMapFunc(r.findAgentsReferencingToolServer),
356+
).
357+
Watches(
358+
&runtimev1alpha1.AgentRuntimeConfiguration{},
359+
handler.EnqueueRequestsFromMapFunc(r.findAllAgentsForRuntimeConfiguration),
356360
)
357361

358362
// Only watch AiGateway if the CRD is installed
@@ -369,6 +373,32 @@ func (r *AgentReconciler) SetupWithManager(mgr ctrl.Manager) error {
369373
return builder.Named("agent").Complete(r)
370374
}
371375

376+
// findAllAgentsForRuntimeConfiguration enqueues all agents when an AgentRuntimeConfiguration changes,
377+
// since the configuration may affect the template image used by any agent.
378+
func (r *AgentReconciler) findAllAgentsForRuntimeConfiguration(ctx context.Context, obj client.Object) []ctrl.Request {
379+
var agentList runtimev1alpha1.AgentList
380+
if err := r.List(ctx, &agentList); err != nil {
381+
logf.FromContext(ctx).Error(err, "Failed to list agents for AgentRuntimeConfiguration watch")
382+
return nil
383+
}
384+
385+
requests := make([]ctrl.Request, 0, len(agentList.Items))
386+
for _, agent := range agentList.Items {
387+
requests = append(requests, ctrl.Request{
388+
NamespacedName: types.NamespacedName{
389+
Name: agent.Name,
390+
Namespace: agent.Namespace,
391+
},
392+
})
393+
}
394+
395+
logf.FromContext(ctx).Info("Enqueuing all agents due to AgentRuntimeConfiguration change",
396+
"config", obj.GetName(),
397+
"agentCount", len(requests))
398+
399+
return requests
400+
}
401+
372402
// isAiGatewayCRDInstalled checks if the AiGateway CRD is installed in the cluster
373403
func isAiGatewayCRDInstalled(mgr ctrl.Manager) bool {
374404
gvk := runtimev1alpha1.GroupVersion.WithKind("AiGateway")

0 commit comments

Comments
 (0)