Skip to content

Implement namespace scoping for /api/agents#1878

Open
maazghani wants to merge 3 commits into
kagent-dev:mainfrom
maazghani:maazghani/implement-namespace-kagent-filtering
Open

Implement namespace scoping for /api/agents#1878
maazghani wants to merge 3 commits into
kagent-dev:mainfrom
maazghani:maazghani/implement-namespace-kagent-filtering

Conversation

@maazghani
Copy link
Copy Markdown

@maazghani maazghani commented May 15, 2026

Addresses #1812 and @EItanya's feedback to implement server side. If this PR lands, I'll wire the UI into it next.

Adds GET /api/agents/{namespace} to work like kubectl get agent -n kagent, and leaving GET /api/agents as kubectl get agent -A.

Re-use existing namespace validation pattern to return invalid namespaces as 400 bad request.

  • implemented HandleListAgentsForNamespace handler with tests
  • DRY'd out Agent + AgentHarness aggregation logic into a shared helper
  • registered route for /{namespace} in server.go
  • updated ListAgents to hit path-based /api/agents/${namespace}

Ran e2e tests using kind-backed env successfully, and validated namespace-filtering works.

Signed-off-by: Maaz Ghani <mghani@lululemon.com>
@maazghani maazghani force-pushed the maazghani/implement-namespace-kagent-filtering branch from 32a94d8 to 95c5b81 Compare May 15, 2026 19:46
@maazghani
Copy link
Copy Markdown
Author

maazghani commented May 15, 2026

Verification performed so far:

$ kubectl get agent -n kagent
NAME                             TYPE          RUNTIME   READY   ACCEPTED
argo-rollouts-conversion-agent   Declarative   python    True    True
cilium-debug-agent               Declarative   python    True    True
cilium-manager-agent             Declarative   python    True    True
cilium-policy-agent              Declarative   python    True    True
helm-agent                       Declarative   python    True    True
istio-agent                      Declarative   python    True    True
k8s-agent                        Declarative   python    True    True
kebab-agent                      BYO                     True    True
kgateway-agent                   Declarative   python    True    True
observability-agent              Declarative   python    True    True
promql-agent                     Declarative   python    True    True
test-agent-dqm5m                 Declarative   go        True    True
test-agent-p8mfv                 Declarative   python    True    True
$ curl -s $KAGENT_URL/api/agents/kagent | jq '[.data[].agent.metadata.name]'
[
  "kebab-agent",
  "test-agent-p8mfv",
  "cilium-manager-agent",
  "istio-agent",
  "k8s-agent",
  "observability-agent",
  "promql-agent",
  "cilium-policy-agent",
  "kgateway-agent",
  "test-agent-dqm5m",
  "argo-rollouts-conversion-agent",
  "helm-agent",
  "cilium-debug-agent"
]

$ curl -s $KAGENT_URL/api/agents/default | jq .
{
  "error": false,
  "message": "Successfully listed agents"
}

$ curl -s $KAGENT_URL/api/agents/invalid!
{"error":"invalid namespace \"invalid!\": a lowercase RFC 1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name',  or '123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?'): invalid namespace \"invalid!\": a lowercase RFC 1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name',  or '123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?')"}

@maazghani maazghani marked this pull request as ready for review May 15, 2026 23:58
@maazghani maazghani requested a review from supreme-gg-gg as a code owner May 15, 2026 23:58
Copilot AI review requested due to automatic review settings May 15, 2026 23:58
@maazghani maazghani marked this pull request as draft May 15, 2026 23:58
@maazghani
Copy link
Copy Markdown
Author

maazghani commented May 15, 2026

@claude please review as well. Edit: or not

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds namespace-scoped agent listing support by introducing a new /api/agents/{namespace} endpoint, wiring it into both the UI’s getAgents action and the Go API client, and adding handler tests to validate the filtering behavior.

Changes:

  • Add GET /api/agents/{namespace} route and handler to list Agents/AgentHarnesses restricted to a namespace (with namespace validation).
  • Update UI getAgents action to optionally call the namespace-scoped endpoint.
  • Extend Go API client to support listing agents for a specific namespace and add handler test coverage.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
ui/src/app/actions/agents.ts Add optional namespace parameter to getAgents() to call a namespace-scoped agents endpoint.
go/core/internal/httpserver/server.go Register a new GET /api/agents/{namespace} route.
go/core/internal/httpserver/handlers/agents.go Implement HandleListAgentsForNamespace with Kubernetes namespace validation and namespace-scoped listing.
go/core/internal/httpserver/handlers/agents_test.go Add tests ensuring namespace-scoped listing filters both Agents and AgentHarnesses.
go/api/client/agent.go Add a client method (and interface entry) for listing agents by namespace.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread go/core/internal/httpserver/handlers/agents.go
Comment thread go/api/client/agent.go
Comment thread go/core/internal/httpserver/server.go
@maazghani maazghani force-pushed the maazghani/implement-namespace-kagent-filtering branch from 7035655 to b6ed0c8 Compare May 16, 2026 00:28
@maazghani
Copy link
Copy Markdown
Author

maazghani commented May 16, 2026

Please ignore my force-pushes I forgot to sign the commit(s).

@maazghani maazghani marked this pull request as ready for review May 16, 2026 00:48
@maazghani maazghani changed the title Draft: Implement namespace filtering for /api/agents Implement namespace filtering for /api/agents May 16, 2026
@maazghani maazghani marked this pull request as draft May 16, 2026 01:56
Signed-off-by: Codex <codex@openai.com>
Signed-off-by: Maaz Ghani <maazghani@gmail.com>
@maazghani maazghani force-pushed the maazghani/implement-namespace-kagent-filtering branch from 54ada34 to 0c54895 Compare May 16, 2026 20:44
@maazghani maazghani changed the title Implement namespace filtering for /api/agents Implement namespace scoping for /api/agents May 16, 2026
@maazghani maazghani requested a review from Copilot May 16, 2026 21:20
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment thread go/core/internal/httpserver/handlers/agents.go Outdated
Comment thread go/api/client/agent.go
Signed-off-by: Maaz Ghani <maazghani@gmail.com>
@maazghani maazghani marked this pull request as ready for review May 16, 2026 22:30
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.

3 participants