Skip to content

Add Kubernetes event recording to AgentReconciler#82

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/add-event-recording-to-agent-reconciler
Draft

Add Kubernetes event recording to AgentReconciler#82
Copilot wants to merge 2 commits intomainfrom
copilot/add-event-recording-to-agent-reconciler

Conversation

Copy link
Contributor

Copilot AI commented Mar 17, 2026

AgentReconciler had no event emission despite RBAC markers already in place and the webhook layer already using events.EventRecorder. This adds observability into reconciliation activity via kubectl describe agent.

Changes

  • AgentReconciler struct — added Recorder events.EventRecorder field (same k8s.io/client-go/tools/events package as the webhook layer; no new dependencies)
  • emitEvent helper — nil-guarded wrapper around Recorder.Eventf so the field is optional
  • Event emission in the reconcile loop:
    • Normal/Created — Deployment or Service newly created
    • Normal/Updated — Deployment or Service updated; successful reconciliation
    • Warning/ReconcileFailed — subAgent/tool/AiGateway resolution failure, Deployment or Service reconciliation failure
  • cmd/main.go — wired recorder via mgr.GetEventRecorder("agent-controller")
  • 7 test filesBeforeEach blocks updated to supply &events.FakeRecorder{}

Example events visible after this change

kubectl describe agent my-agent
...
Events:
  Type    Reason    Age  From              Message
  ----    ------    ---  ----              -------
  Normal  Created   5s   agent-controller  Deployment my-agent created
  Normal  Created   5s   agent-controller  Service my-agent created
  Normal  Updated   3s   agent-controller  Agent reconciled successfully
Original prompt

This section details on the original issue you should resolve

<issue_title>Emit Kubernetes events from Agent controller on reconciliation</issue_title>
<issue_description>## Summary

The AgentReconciler currently does not emit Kubernetes events when reconciling Agent resources. Adding event recording would improve observability by surfacing reconciliation activity (e.g. agent updated, deployment created, reconcile failed) via kubectl describe agent <name> and kubectl get events.

Current State

  • RBAC markers for events and events.k8s.io are already in place (agent_reconciler.go lines 68-69)
  • The webhook layer already uses EventRecorder for recording events
  • The AgentReconciler struct has no Recorder field

Proposed Changes

  1. Add record.EventRecorder to AgentReconciler struct (internal/controller/agent_reconciler.go)
  2. Wire the recorder in cmd/main.go via mgr.GetEventRecorderFor("agent-controller")
  3. Emit events in the reconcile loop for key state transitions:
    • Normal / Updated — Agent spec reconciled successfully
    • Normal / Created — Deployment or Service created
    • Warning / ReconcileFailed — Reconciliation error
  4. Update tests to supply a fake recorder in BeforeEach blocks

Acceptance Criteria

  • kubectl describe agent <name> shows events for create/update/error
  • Existing tests pass with the recorder wired in
  • No new dependencies introduced (uses k8s.io/client-go/tools/record)</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

- Add Recorder events.EventRecorder field to AgentReconciler struct
- Emit Normal/Created and Normal/Updated events from ensureDeployment and ensureService
- Emit Normal/Updated event on successful reconciliation
- Emit Warning/ReconcileFailed events on resolution/reconciliation failures
- Wire recorder in cmd/main.go via mgr.GetEventRecorder
- Update all 7 test files to supply fake recorder in BeforeEach

Co-authored-by: fmallmann <30110193+fmallmann@users.noreply.github.com>
Copilot AI changed the title [WIP] Add event recording to AgentReconciler for improved observability Add Kubernetes event recording to AgentReconciler Mar 17, 2026
Copilot AI requested a review from fmallmann March 17, 2026 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Emit Kubernetes events from Agent controller on reconciliation

2 participants