Repository navigation
Description
Summary
A VirtualMCPServer with an embedded auth server (spec.authServerConfig) causes the operator to issue a no-op Deployment Update on every reconcile, indefinitely. With the controller's periodic backend re-discovery driving reconciles every ~30s, this is a steady ~8 Deployment updates/minute per affected vMCP. vMCPs without authServerConfig are unaffected.
On a small cluster the aggregate API churn is very visible: in a demo kind cluster with two such vMCPs, kube-apiserver sat at ~125m CPU steady-state and the node hovered around 50% with no user traffic. The pods never restart (no new ReplicaSet, stable runconfig-checksum, stable ConfigMap), so the symptom is pure control-plane churn rather than workload disruption, which makes it easy to miss.
Root cause
The desired-Deployment builder and the drift checker disagree about the container's env vars when authServerConfig is set.
The builder, deploymentForVirtualMCPServer, calls buildEnvVarsForVmcp(...) and then appends the auth-server env vars on top (cmd/thv-operator/controllers/virtualmcpserver_deployment.go:155,178-184):
env, err := r.buildEnvVarsForVmcp(ctx, vmcp, telemetryCfg, typedWorkloads)
...
if vmcp.Spec.AuthServerConfig != nil {
authServerVolumes, authServerMounts := ctrlutil.GenerateAuthServerVolumes(vmcp.Spec.AuthServerConfig)
authServerEnvVars := ctrlutil.GenerateAuthServerEnvVars(vmcp.Spec.AuthServerConfig)
volumes = append(volumes, authServerVolumes...)
volumeMounts = append(volumeMounts, authServerMounts...)
env = append(env, authServerEnvVars...) // <-- auth-server env appended here
}But buildEnvVarsForVmcp itself (virtualmcpserver_deployment.go:334-388) never appends those env vars. So the drift checker, containerNeedsUpdate, which builds its expected set from buildEnvVarsForVmcp alone, is always missing them (virtualmcpserver_controller.go:1667-1673):
expectedEnv, err := r.buildEnvVarsForVmcp(ctx, vmcp, telemetryCfg, typedWorkloads)
if err != nil {
return true
}
if !reflect.DeepEqual(container.Env, expectedEnv) {
return true
}The live container always carries the auth-server env var (e.g. TOOLHIVE_UPSTREAM_CLIENT_SECRET_OKTA from GenerateAuthServerEnvVars, pkg/controllerutil/authserver.go:356), expectedEnv never does, so reflect.DeepEqual is always false. containerNeedsUpdate returns true, deploymentNeedsUpdate returns true, and r.Update fires unconditionally. Next reconcile, repeat.
Reproduction
- Apply a
VirtualMCPServerwithspec.authServerConfigset (an upstream OAuth2 provider with aclientSecretRefis enough to makeGenerateAuthServerEnvVarsemit aTOOLHIVE_UPSTREAM_CLIENT_SECRET_<PROVIDER>env var). - Watch the operator logs:
Updating Deployment ... controller=virtualmcpserverfires every reconcile. - Confirm it's a no-op: the Deployment's
spec.template.metadata.annotations.toolhive.stacklok.dev/runconfig-checksumand the backing ConfigMap'sresourceVersionare stable, and no new ReplicaSet is created.
Suggested fix
Make the builder and the checker share one source of truth by moving the auth-server env injection into buildEnvVarsForVmcp, and dropping the env = append(...) line from deploymentForVirtualMCPServer (keeping the volume/mount injection there). Since both paths then derive env identically, reflect.DeepEqual matches and the loop stops.
Secondary observation (not the loop)
deploymentNeedsUpdate never compares volumes or volumeMounts at all. The auth-server volumes injected at virtualmcpserver_deployment.go:179-182 therefore wouldn't self-heal on drift. This doesn't cause the loop, but it's the same build/diff asymmetry in the volume dimension and worth closing at the same time.
Affected versions
Present on main and through v0.30.1.
Activity
Fix vMCP Deployment update loop with embedded auth server (#5617)