feat(runtime): add Kagent deployment and discovery adapter - #655
feat(runtime): add Kagent deployment and discovery adapter#655xytian315 wants to merge 14 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a first-party Kagent runtime integration to AgentRegistry, covering workload translation, apply/remove behavior, REST client wiring, and discovery so Kagent-managed Agents/MCPServers can be deployed and correlated back to AgentRegistry Deployments.
Changes:
- Introduces a new
pkg/runtimes/kagentadapter with translation logic (BYO Agents + MCPServer tool servers), REST client, status handling, desired fingerprinting, and discovery. - Registers
Kagentas a known runtime type and hooks runtime config validation intoRuntime.Validate(). - Wires Kagent into the registry app defaults and adds a DB-backed Deployment finder used to resolve source-backed MCPServer dependencies.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pkg/runtimes/kagent/translate.go | Translates AgentRegistry resources into Kagent REST payloads; resolves model + MCP wiring. |
| pkg/runtimes/kagent/translate_test.go | Unit tests for translation, model resolution, and MCP dependency wiring. |
| pkg/runtimes/kagent/status.go | Maps translation/apply outcomes into AgentRegistry ApplyResult conditions + runtime metadata. |
| pkg/runtimes/kagent/status_test.go | Tests condition builders for success/failure/removal. |
| pkg/runtimes/kagent/rest_types.go | Defines private Kagent REST wire payload structs/constants. |
| pkg/runtimes/kagent/fake_client_test.go | Fake Kagent client used by adapter/discovery tests. |
| pkg/runtimes/kagent/discover.go | Implements runtime discovery for Agents and MCPServers from Kagent. |
| pkg/runtimes/kagent/discover_test.go | Tests discovery behavior, namespace filtering, and real ID response shape. |
| pkg/runtimes/kagent/config.go | Runtime/deploy config decoding + admission-time validation helpers. |
| pkg/runtimes/kagent/config_test.go | Tests config decoding/validation and admission registration behavior. |
| pkg/runtimes/kagent/client.go | REST client for Kagent API (create/update/delete/list). |
| pkg/runtimes/kagent/client_test.go | Tests REST client request/response behavior and replacement flows. |
| pkg/runtimes/kagent/adapter.go | Main adapter: Apply/Remove/Discover/DesiredFingerprint + auth token sourcing. |
| pkg/runtimes/kagent/adapter_test.go | Adapter tests for apply/remove, metadata, labels, fingerprint behavior, and auth resolution. |
| pkg/api/v1alpha1/runtime_validate.go | Adds RuntimeConfigValidators and invokes per-runtime config validators during Runtime.Validate(). |
| internal/registry/registry_app.go | Registers Kagent adapter/discovery source by default and wires Deployment finder + optional secret resolver. |
| internal/registry/database/resolvers.go | Adds DB-backed NewKagentDeploymentFinder used to locate managed deployments for MCP dependencies. |
| internal/registry/database/resolvers_integration_test.go | Integration test for the Kagent deployment finder SQL filtering/matching. |
| internal/cli/common/deployments.go | Improves CLI DeploymentStatus derivation for Ready=false failures. |
| internal/cli/common/deployments_test.go | Adds coverage for Ready=false/Failed mapping to “failed”. |
| Makefile | Updates Kagent version and Helm install flags for the newer chart layout. |
Suppressed comments (1)
pkg/runtimes/kagent/config.go:213
- decodeDeployConfig guards
secretRefsby checking only the exact map key"secretRefs". Since JSON unmarshal is case-insensitive, a user could specify"SecretRefs"and have it populate cfg.SecretRefs without triggering the kind check, allowing unsupported deploy config fields to slip through validation for non-MCPServer targets.
func decodeDeployConfig(m map[string]any, targetKind string) (deployConfig, error) {
if _, found := m["secretRefs"]; found && targetKind != v1alpha1.KindMCPServer {
return deployConfig{}, fmt.Errorf("secretRefs is only supported for MCPServer deployments")
}
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
4bbebb6 to
fad7df7
Compare
NewStoreDeploymentFinder takes a Deployment store directly; the generic database package no longer carries Kagent-specific lookup code.
Exports ErrAuthExpired, ErrDependencyNotReady, and FailedApplyResult; adds finder coverage for namespace mismatches.
fad7df7 to
9e30614
Compare
timflannagan
left a comment
There was a problem hiding this comment.
As always, thanks for running this work down Kristy. One generic question that was hard to capture as an inline review comments. How much of this code can be moved into internal vs. exposed via pkg/? I think some of that will inform whether pkg/runtimes/kagent is a net new package we should introduce here vs. follow existing patterns in the codebase.
| if ready := dep.Status.GetCondition("Ready"); ready != nil { | ||
| if ready.Status == v1alpha1.ConditionTrue { | ||
| return "deployed" | ||
| } | ||
| if ready.Status == v1alpha1.ConditionFalse && ready.Reason == "Failed" { | ||
| return "failed" | ||
| } |
There was a problem hiding this comment.
Let's update pkg/status and use the existing constants or expand it
There was a problem hiding this comment.
I'll highlight this here instead of where it's defined. My preference is adding another method on the DeploymentController that was refactored recently. Ex: DeploymentApplied, instead of maintaining another separate type definition and introducing more indirection.
There was a problem hiding this comment.
How much of this testing could be reduced to a single table-driven test?
| // RuntimeConfigValidators lets runtime packages register admission checks | ||
| // without coupling the API package to concrete adapter implementations. | ||
| var RuntimeConfigValidators = map[string]func(map[string]any) error{} |
There was a problem hiding this comment.
Fine for now, but this comment suggests a smell with our admission/validation logic
| var _ types.DeploymentAdapter = (*adapter)(nil) | ||
| var _ types.DeploymentDiscoverySource = (*adapter)(nil) | ||
| var _ types.DeploymentDesiredFingerprinter = (*adapter)(nil) |
There was a problem hiding this comment.
Same thing as above, fine for now, having to satisfy these many interfaces is a clear smell in our abstractions to me.
| Name: w.Name, | ||
| RuntimeMetadata: map[string]string{ | ||
| types.RuntimeMetadataRemoteIDKey: w.Name, | ||
| "namespace": w.Namespace, |
There was a problem hiding this comment.
Should we add a constant for this?
| } | ||
|
|
||
| // WithWorkloadLabels adds labels to pod-backed Kagent resources. | ||
| func WithWorkloadLabels(labels map[string]string) Option { |
There was a problem hiding this comment.
Surprised we need this type of wiring. Can't this be derived from runtime or deployment config? Or even hardcoded via code?
There was a problem hiding this comment.
thanks! moved to runtimeDeploymentConfig in this commit 67d030b
| if !ok || input.Deployment == nil { | ||
| return types.DefaultApplyFingerprint(ctx, input, options) | ||
| } | ||
| hasMCPDependencies := len(agent.Spec.MCPServers) > 0 || |
There was a problem hiding this comment.
While we're at it, we should talk about this spec.deploymentRefs field and the future of whether it's still beneficial here.
There was a problem hiding this comment.
Yeah want to talk about this more. The assumption going forward is that every adapter will need to implement if it it's in the API surface. This PR just highlights this logic and not something and not a blocker for merging. The issue is I now have N ways to source an MCP server via the Agents API.
|
|
||
| const ( | ||
| kagentV1Alpha2APIVersion = "kagent.dev/v1alpha2" | ||
| kagentV1Alpha1APIVersion = "kagent.dev/v1alpha1" |
There was a problem hiding this comment.
I'd almost be in favor of dropping this tbh. Our approach is best effort anyways.
# Conflicts: # internal/cli/common/deployments_test.go
Description
Add a built-in Kagent runtime adapter for deployment and discovery.
Change Type
/kind feature
Changelog
Additional Notes
Targeted development and smoke testing use Kagent v0.10.0-rc3.
Agent deployment currently supports prebuilt A2A workloads defined with
spec.source.image. Harness-based deployments and Agents without a prebuilt image are not supported.Manual smoke coverage included BYO Agent deployment, remote MCPServer deployment, and out-of-band Agent discovery.