Skip to content

Public constructor for a Kubernetes-backed dynamic BackendRegistry (no pkg/vmcp/k8s import for embedders) #5541

Closed

Description

@tgrunnagle

Part of the vMCP interface refactor (epic #5419).

Summary

Expose a public constructor that returns a live, Kubernetes-populated vmcp.BackendRegistry (a DynamicRegistry kept current by an internal BackendWatcher) plus a readiness/lifecycle handle, so an embedder gets dynamic backend discovery without importing pkg/vmcp/k8s or hand-wiring rest.InClusterConfig + NewBackendWatcher + the watcher goroutine. Scope is deliberately limited to the registry/discovery seam — not the full core/Serve assembly.

Motivation

Today an embedder that wants live discovery must replicate pkg/vmcp/cli/serve.go:210-248:

dynamicRegistry := vmcp.NewDynamicRegistry(backends)
restConfig, _ := rest.InClusterConfig()
backendWatcher, _ := k8s.NewBackendWatcher(restConfig, namespace, group, dynamicRegistry)
go backendWatcher.Start(ctx)

That forces a direct pkg/vmcp/k8s (+ k8s.io/client-go/rest) import. Per THV-0076/D9 the K8s-watch substrate should stay internal to vMCP; the embedder should depend only on a public registry constructor.

Note: the watcher runs in the embedder's Pod, so controller-runtime/k8s.io remain compiled into the binary — expected and unchanged. This issue is about the Go import surface and one-call ergonomics, not removing transitive deps.

Proposed shape (illustrative; home/types maintainers' call)

// Lives outside pkg/vmcp/k8s so callers don't import it.
func NewKubernetesBackendRegistry(
    ctx context.Context, namespace, group string, opts ...Option,
) (vmcp.BackendRegistry, server.Watcher, error)

Bundles NewDynamicRegistry + watcher construction + Start, defaulting restConfig to in-cluster (overridable via opt). The registry may start empty — the watcher's initial informer sync populates it — so the constructor needs only pkg/vmcp/k8s, not the static-discovery path's pkg/groups / pkg/container/runtime. The returned handle satisfies server.Watcher for /readyz cache-sync gating.

Embedder usage — no pkg/vmcp/k8s, no rest:

reg, watcher, _ := vmcpreg.NewKubernetesBackendRegistry(ctx, ns, group)
core, _ := core.New(&core.Config{BackendRegistry: reg, /* ... */})
srv, _ := server.Serve(ctx, core, &server.ServerConfig{
    BackendRegistry: reg, Watcher: watcher, /* ... */
})

Scope of work

  • Add the public constructor (registry + watcher + lifecycle), in-cluster restConfig by default with an override option.
  • Start empty + populate via the watcher's initial sync (avoid the static path's groups/container-runtime deps).
  • Optionally route cli.Serve's dynamic branch through it to dedupe cli/serve.go:210-248.

Acceptance criteria

  • Integration: an example/test embedder builds a live registry and serves, importing the new constructor but not pkg/vmcp/k8s or k8s.io/client-go/rest.
  • Import-graph (enforced by test): the embedder package does not import pkg/vmcp/k8s / k8s.io/client-go/rest.
  • Live updates: adding/removing an MCPServer CR updates the registry's backends (parity with current cli.Serve).

Out of scope

  • The broader config-driven Build() / full core+Serve assembly — the embedder keeps wiring aggregator/router/client itself.
  • The ListBackends/LookupBackend extension; the optimizer; any vmcpconfig.Config schema change.

References

Activity

  1. added
    vmcp
    on Jun 16, 2026
  2. added
    needs-triage
    on Jun 16, 2026
  3. removed
    needs-triage
    on Jun 16, 2026
  4. self-assigned this
    on Jun 16, 2026
  5. changed the title [-]Config-driven vMCP assembly so embedders avoid importing pkg/vmcp/k8s[/-] [+]Public constructor for a Kubernetes-backed dynamic BackendRegistry (no pkg/vmcp/k8s import for embedders)[/+] on Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

refactorvmcp

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions