stacklok / stacklok/toolhive

Batch MCPServer status updates to reduce API calls per reconciliation

Open
#4,630 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug go kubernetes operator
Dominant language
Go
Stars
2.2k
Forks
300
Avg merge
1d 15h
Merged PRs (30d)
184

Description

Summary

The MCPServer controller calls r.Status().Update() from many independent validation helpers, resulting in 6+ distinct status update API calls on a single happy-path reconcile. This causes unnecessary API server load, conflict errors from consecutive racing updates, and wasted work when later updates overwrite earlier ones.

Severity: MUST FIX
Area: Controller Logic
Breaking: No

Location

  • cmd/thv-operator/controllers/mcpserver_controller.go

Problem

The controller makes separate r.Status().Update() calls from many independent helpers:

  • validateGroupRef (line 577)
  • updateCABundleStatus (line 674)
  • validateAndUpdatePodTemplateStatus (lines 737, 756)
  • setImageValidationCondition + update (lines 267, 279, 293, 304)
  • handleToolConfig (line 952)
  • Multiple others in status reconciliation paths

35 total call sites exist; 6+ distinct on the happy path. On error paths, even more.

Impact

  • API server load: 6-12 status update calls per reconcile instead of 1
  • Conflict errors when consecutive updates race
  • Wasted work when a later update overwrites an earlier one

Recommended Fix

Adopt the StatusManager/StatusCollector pattern already used by VirtualMCPServer and MCPRegistry:

  1. Collect all condition/status mutations during reconciliation
  2. Apply them in a single batch at the end
  3. Remove independent Status().Update() calls from validation helpers

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in cmd/thv-operator/controllers/mcpserver_controller.go and compare the StatusManager/StatusCollector pattern already used by VirtualMCPServer and MCPRegistry. Trace the listed validation and status reconciliation helpers, then verify that their mutations are collected and applied in one batch instead of independent Status().Update() calls.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, kubernetes
Domain
backend, infrastructure
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.