Skip to content

Add default resource limits for MCPRemoteProxy - #7137

Merged
ChrisJBurns merged 5 commits into
mainfrom
ChrisJBurns/toolhive-pr-5998-complete
Nov 16, 2026
Merged

ChrisJBurns merged 5 commits into
mainfrom
ChrisJBurns/toolhive-pr-5998-complete

Conversation

@ChrisJBurns

@ChrisJBurns ChrisJBurns commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

MCPRemoteProxy has no default resource requests or limits, so a proxy whose CR omits spec.resources runs unbounded. That is the same operational and security gap #2873 closed for VirtualMCPServer. This picks up #5998 by @clxstart (their commit is preserved) and addresses the open review feedback on it.

  • Apply proxy-runner defaults (requests 50m CPU / 64Mi memory, limits 200m CPU / 256Mi memory) to any field left unset in spec.resources, with user values overriding per field.
  • Layer resources from the toolhive container in podTemplateSpec over spec.resources (podTemplateSpec wins) before the strategic merge patch runs. Without this, a podTemplateSpec that set only requests kept the default limits, and the apiserver rejected the Deployment.
  • Keep standard Kubernetes request defaulting. If the user sets a limit without a request, from either source, the default request is dropped, so Kubernetes copies the limit into the request at Pod creation, as it does today. A limits-only proxy keeps Guaranteed QoS and its full reservation.
  • Raise a defaulted limit to meet a user's request, so a partial override can't produce request > limit. For example, requests.memory: 512Mi on its own now yields a 512Mi limit rather than the 256Mi default, which the apiserver would reject. A null in podTemplateSpec removes the default instead. If a user sets both sides inconsistently, their values are passed through unchanged.
  • Use the same effective-resources calculation in drift detection and compare with equality.Semantic.DeepEqual, the same check MCPServer uses for container resources. With reflect.DeepEqual, a non-canonical override such as cpu: "0.2" (stored by the apiserver as 200m) reported drift on every reconcile and caused an endless update loop.
  • Document the defaults on the CRD field, in the generated CRD API reference, and in the operator architecture doc.

Fixes #3131
Supersedes #5998

Type of change

  • New feature

Test plan

  • Unit tests (task operator-test)
  • Linting: gofmt, go vet, and codespell on the changed files. task lint-fix panics locally inside staticcheck under go1.27 (a toolchain issue that exists on main, unrelated to this change), so CI's lint job is the authoritative check.

New tests cover default injection, per-field merge, limit raising, dropping the default request for limits-only overrides, pass-through of inconsistent user values, no aliasing of inputs, a drift check against apiserver-canonicalized quantities, and resource overrides set through podTemplateSpec. I confirmed that the drift test fails when the comparison is reverted to reflect.DeepEqual, and that the podTemplateSpec override tests fail without the podTemplateSpec input.

API Compatibility

  • This PR does not break the v1beta1 API, OR the api-break-allowed label is applied and the migration guidance is described above.

Only the description of spec.resources changes; the schema itself is unchanged.

Does this introduce a user-facing change?

Yes.

  • Before: an MCPRemoteProxy without spec.resources got a proxy container with no CPU or memory requests or limits.
  • After: unset fields default to requests of 50m CPU / 64Mi memory and limits of 200m CPU / 256Mi memory. Explicit values still win per field, whether they're set in spec.resources or in podTemplateSpec. A proxy that sets only limits behaves exactly as before: its requests still equal its limits, so its QoS class and reservation don't change.

Upgrade impact: every existing MCPRemoteProxy that leaves any resource field unset rolls once after the operator upgrade and picks up these defaults, including a 256Mi memory limit it didn't have before. A proxy whose working set is above 256Mi (for example, a busy proxy with an embedded auth server) will be OOMKilled after the upgrade. Before upgrading, operators should check memory usage on heavy proxies and set spec.resources.limits.memory explicitly where needed.

Special notes for reviewers

  • The defaults match the values proposed in Add default resource limits to MCPRemoteProxy #3131 and are half of vMCP's (100m/500m, 128Mi/512Mi). That fits a single-upstream HTTP proxy, but it's the main thing to sanity-check given the upgrade impact above.
  • Deliberate deviation: MCPServer still applies no resource defaults. Bringing it in line would roll every MCPServer deployment on upgrade, so that change is left out of this PR.
  • VirtualMCPServer hard-codes its own defaults and has the same podTemplateSpec gap. That fix is tracked in Clamp VirtualMCPServer resource defaults against podTemplateSpec #7154 and will use the generic helper added here.
  • Possible follow-up: a CEL rule on the shared ResourceRequirements type to reject a request > limit that the user sets explicitly. That rule would also affect MCPServer, so it isn't in this PR.

🤖 Generated with Claude Code

clxstart and others added 2 commits November 13, 2026 17:39
Apply proxy-runner defaults when MCPRemoteProxy omits resource requests/limits,
merge user overrides on top of those defaults, and keep deployment drift detection
aligned with the same effective resource calculation.

Closes #3131
Address review feedback on the default resource limits change:

- Clamp the defaulted side of a request/limit pair so a partial
  override (e.g. only requests.memory: 512Mi) cannot produce a
  request above the default limit, which the apiserver rejects.
- Compare resources with equality.Semantic.DeepEqual in drift
  detection so non-canonical overrides such as cpu "0.2" do not
  trigger a perpetual reconcile/update loop.
- Document the defaults on the CRD field and in the operator
  architecture doc, and regenerate CRD manifests and API docs.
- Fix gofmt and codespell failures.

Co-Authored-By: xing <echoecho_2024@qq.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the size/M Medium PR: 300-599 lines changed label Nov 14, 2026
@codecov

codecov Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.12195% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.40%. Comparing base (74fbd9b) to head (9dd3025).

Files with missing lines Patch % Lines
...-operator/controllers/mcpremoteproxy_deployment.go 80.00% 2 Missing ⚠️
...-operator/controllers/mcpremoteproxy_controller.go 75.00% 1 Missing ⚠️
cmd/thv-operator/pkg/controllerutil/resources.go 98.52% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7137      +/-   ##
==========================================
- Coverage   81.44%   81.40%   -0.04%     
==========================================
  Files         890      890              
  Lines       90622    90701      +79     
==========================================
+ Hits        73803    73839      +36     
- Misses      16814    16857      +43     
  Partials        5        5              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

The podTemplateSpec is applied as a strategic merge patch after the
defaults are set, and that patch merges requests and limits key by
key. A podTemplateSpec that set only requests kept the default limits,
so the request could exceed the limit and the apiserver rejected the
Deployment. On main the same CR was valid because there were no
defaults to collide with.

Add a generic controllerutil.BuildContainerResourceRequirements that
layers defaults, the CRD resources field and the podTemplateSpec
container resources (podTemplateSpec wins), then clamps. A null entry
in the podTemplateSpec drops that key, matching what the patch does.
Defaults are passed in so VirtualMCPServer can adopt it later.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added size/L Large PR: 600-999 lines changed and removed size/M Medium PR: 300-599 lines changed size/L Large PR: 600-999 lines changed labels Nov 16, 2026
aponcedeleonch
aponcedeleonch previously approved these changes Nov 16, 2026
When a container sets a limit without a request, Kubernetes copies
the limit into the request at Pod creation. Filling that gap with our
default request instead silently turned a limits-only proxy from
Guaranteed into Burstable QoS and shrank its reservation (for example
from 2Gi to 64Mi) on upgrade.

Drop the default request whenever the user sets a limit without one,
in spec.resources or podTemplateSpec. That leaves raising a defaulted
limit to meet a user's request as the only remaining adjustment.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added size/L Large PR: 600-999 lines changed and removed size/L Large PR: 600-999 lines changed labels Nov 16, 2026
@github-actions github-actions Bot added size/L Large PR: 600-999 lines changed and removed size/L Large PR: 600-999 lines changed labels Nov 16, 2026
@ChrisJBurns
ChrisJBurns merged commit 35b31f0 into main Nov 16, 2026
48 checks passed
@ChrisJBurns
ChrisJBurns deleted the ChrisJBurns/toolhive-pr-5998-complete branch November 16, 2026 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Large PR: 600-999 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add default resource limits to MCPRemoteProxy

3 participants