refactor(agent/agentcontainers): implement API service (#17340)

This refactor improves separation of API and containers with minimal
changes to logic.

Highlights:

- Routes are now defined in `agentcontainers` package
- Handler renamed to API
- API lazy init was moved into NewAPI
- Tests that don't need to be internal were made external
This commit is contained in:
Mathias Fredriksson
2025-04-11 11:41:13 +03:00
committed by GitHub
parent 7bca3e237a
commit 60fbe675ed
9 changed files with 827 additions and 771 deletions
+8 -3
View File
@@ -36,10 +36,15 @@ func (a *agent) apiHandler() http.Handler {
ignorePorts: cpy,
cacheDuration: cacheDuration,
}
ch := agentcontainers.New(agentcontainers.WithLister(a.lister))
containerAPI := agentcontainers.NewAPI(
a.logger.Named("containers"),
agentcontainers.WithLister(a.lister),
)
promHandler := PrometheusMetricsHandler(a.prometheusRegistry, a.logger)
r.Get("/api/v0/containers", ch.List)
r.Post("/api/v0/containers/{id}/recreate", ch.Recreate)
r.Mount("/api/v0/containers", containerAPI.Routes())
r.Get("/api/v0/listening-ports", lp.handler)
r.Get("/api/v0/netcheck", a.HandleNetcheck)
r.Post("/api/v0/list-directory", a.HandleLS)