Skip to content

Refactor VirtualMCPServer controller to use runtime-reported status #2855

@JAORMX

Description

@JAORMX

Description

Refactor the VirtualMCPServer controller to delegate operational state management to the vMCP runtime. The controller should focus on infrastructure provisioning while the runtime owns backend discovery and health reporting.

Background

Currently the controller and runtime both discover backends:

  • Controller: discoverBackends() at reconcile time → status.discoveredBackends
  • Runtime: k8sDiscoverer at request time for routing

This creates duplication and stale status. Per team discussion: "the vmcp server should be k8s aware and do most of the work instead of operator needing to do it all."

Current vs Target State

Controller Responsibilities

Responsibility Current Target
RBAC, Deployment, Service, ConfigMap ✅ Keep ✅ Keep
Validate GroupRef exists ✅ Keep ✅ Keep
Set status.URL ✅ Keep ✅ Keep
Infrastructure conditions ✅ Keep ✅ Keep
Backend discovery ⚠️ Controller ❌ Remove
Backend health status ⚠️ Inferred ❌ Remove
status.discoveredBackends ⚠️ Controller ✅ Read from runtime
status.Phase ⚠️ Inferred ✅ Read from runtime

Runtime Responsibilities (via StatusReporter)

Responsibility Current Target
Dynamic backend discovery ✅ Has ✅ Keep
Backend health monitoring ⚠️ Partial ✅ Full ownership
Report status.discoveredBackends ❌ None ✅ Add
Report status.Phase ❌ None ✅ Add

Implementation

Phase 1: Enable Runtime Reporting

Depends on: #2854 (StatusReporter abstraction)

Phase 2: Controller Reads Runtime Status

  • Controller observes status changes via watch (already configured)
  • Remove redundant discoverBackends() call
  • Set infrastructure-only conditions

Files to Modify

cmd/thv-operator/controllers/virtualmcpserver_controller.go:

  • Remove discoverBackends() function
  • Remove backend health inference logic
  • Simplify Reconcile() to infrastructure-only

cmd/thv-operator/controllers/virtualmcpserver_deployment.go:

  • Add VMCP_NAME and VMCP_NAMESPACE env vars for runtime identity

Reconciliation Flow (After)

Reconcile()
├── Validate GroupRef exists
├── Ensure RBAC (ServiceAccount, Role, RoleBinding)
├── Ensure ConfigMap with vMCP config
├── Ensure Deployment (with env vars for identity)
├── Ensure Service
├── Set infrastructure conditions (DeploymentReady, ServiceReady)
├── Set status.URL
└── Done (runtime reports operational status)

Acceptance Criteria

  • Remove discoverBackends() from controller
  • Controller sets only infrastructure conditions
  • Runtime reports status.discoveredBackends via StatusReporter
  • Runtime reports status.Phase (Ready/Degraded/Failed)
  • No duplicate backend queries between controller and runtime
  • E2E test validates runtime status appears in CRD
  • Documentation updated for new responsibility split

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestgoPull requests that update go codekubernetesItems related to Kubernetesoperatortech-debtvmcpVirtual MCP Server related issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions