feat(core): emit Kubernetes Events on Agent/ModelConfig/MCPServerTool/RemoteMCPServer reconciles#2150
Open
braghettos wants to merge 1 commit into
Open
Conversation
Add an optional EventRecorder to the Agent, ModelConfig, MCPServerTool and RemoteMCPServer controllers so reconcile outcomes are visible via 'kubectl describe', mirroring the pattern already used by the agentharness-substrate controller. Emitted events: - Agent / ModelConfig / RemoteMCPServer: Normal Accepted on success, Warning ReconcileFailed on error. - MCPServerTool: Normal ToolsDiscovered on success, Warning ValidationFailed for spec validation errors, Warning ReconcileFailed for transient errors. Recording is nil-guarded on both the Recorder and Client, so it is a no-op when either is unwired (e.g. in tests) and behaviour is unchanged. RBAC is already covered by the leader-election role (events: create,patch). Recorders are wired from pkg/app/app.go via mgr.GetEventRecorder. Refs: kagent-dev#2148 Signed-off-by: Diego Braga <diego.braga86@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds Kubernetes Event emission to several go/core controllers so reconcile outcomes are visible via kubectl describe / kubectl get events, wiring recorders from the controller manager.
Changes:
- Wire
Client+EventRecorderinto Agent/ModelConfig/MCPServerTool/RemoteMCPServer controllers frompkg/app/app.go. - Emit Normal/Warning Kubernetes Events on reconcile success/failure for those controllers via a nil-guarded
recordEventhelper. - Add a unit test covering MCPServerTool event emission paths.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| go/core/pkg/app/app.go | Wires manager client + event recorders into the four controllers. |
| go/core/internal/controller/agent_controller.go | Emits Accepted/ReconcileFailed Events for Agent reconciles via recordEvent. |
| go/core/internal/controller/modelconfig_controller.go | Emits Accepted/ReconcileFailed Events for ModelConfig reconciles via recordEvent. |
| go/core/internal/controller/mcp_server_tool_controller.go | Emits ToolsDiscovered/ValidationFailed/ReconcileFailed Events for MCPServer tool discovery reconciles. |
| go/core/internal/controller/remote_mcp_server_controller.go | Emits Accepted/ReconcileFailed Events for RemoteMCPServer reconciles via recordEvent. |
| go/core/internal/controller/mcp_server_tool_controller_events_test.go | Adds tests validating MCPServerTool emits expected event type/reason. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+75
to
79
| r.recordEvent(ctx, req, "Normal", "ToolsDiscovered", "Reconcile", "MCPServer tools discovered successfully") | ||
| // Success - requeue after 60s to refresh tool server status | ||
| return ctrl.Result{ | ||
| RequeueAfter: 60 * time.Second, | ||
| }, nil |
Comment on lines
+71
to
75
| r.recordEvent(ctx, req, "Normal", "Accepted", "Reconcile", "RemoteMCPServer reconciled successfully") | ||
| // Success - requeue after 60s to refresh tool server status | ||
| return ctrl.Result{ | ||
| RequeueAfter: 60 * time.Second, | ||
| }, nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds Kubernetes Events on reconcile to the Agent, ModelConfig, MCPServerTool, and RemoteMCPServer controllers, so users can see reconcile outcomes with
kubectl describe/kubectl get events. This is the second of the three observability gaps proposed in #2148.Today these four controllers emit no Events (unlike
agentharness-substrate-controller, which already does), so a bad Agent/ModelConfig/MCPServer gives no signal inkubectl describe.How
Each controller gains an optional
Client+Recorder events.EventRecorderand a small nil-guardedrecordEventhelper that re-fetches the reconciled object and emits an Event against it, mirroring the existing substrate-controller pattern.Emitted events:
Normal AcceptedWarning ReconcileFailedNormal AcceptedWarning ReconcileFailedNormal AcceptedWarning ReconcileFailedNormal ToolsDiscoveredWarning ValidationFailed(spec validation) /Warning ReconcileFailed(transient)Recorders are wired from
pkg/app/app.goviamgr.GetEventRecorder(...).Additive / no behaviour change
recordEventis a no-op when eitherRecorderorClientis nil, so existing tests and any caller that doesn't wire them are unaffected.events: create,patch), so no RBAC changes are needed.go.modunchanged);k8s.io/client-go/tools/eventsandapierrorsare already used in-tree.Testing
mcp_server_tool_controller_events_test.go— asserts the correct event type/reason is emitted for each of the three MCPServerTool outcomes (ToolsDiscovered / ValidationFailed / ReconcileFailed) using a fake client +events.NewFakeRecorder, plus a no-Recorder no-panic case.go build ./core/...,go test -race -skip 'TestE2E.*' ./core/internal/controller/..., andgolangci-lint runall pass.Notes
Opening as draft / work-in-progress per CONTRIBUTING; happy to adjust event reasons/actions. The remaining gap from #2148 (controller log→OTLP bridge) will follow as a separate PR. Companion PR for gap 1 (token metrics): #2149.
Refs: #2148