Skip to content

fix: do not revert HPA-managed replicas of MCPServer deployments - #144

Open
gaarutyunov wants to merge 1 commit into
kagent-dev:mainfrom
gaarutyunov:fix/preserve-replicas-for-hpa
Open

gaarutyunov wants to merge 1 commit into
kagent-dev:mainfrom
gaarutyunov:fix/preserve-replicas-for-hpa

Conversation

@gaarutyunov

@gaarutyunov gaarutyunov commented Nov 9, 2026 •

Copy link
Copy Markdown

Fixes #145

Problem

A HorizontalPodAutoscaler cannot scale the Deployment of an MCPServer:

  • The CRD defaults spec.deployment.replicas to 1, so the field is never empty.
  • upsertOutput replaces the whole Deployment on every reconcile.
  • The controller watches its Deployments (Owns(&appsv1.Deployment{})), so each HPA scale event triggers a reconcile that resets replicas to 1 right away.

Change

  • Drop +kubebuilder:default=1 from MCPServerDeployment.Replicas, and update both CRD copies (config/crd/bases and helm/kmcp-crds).
  • When the desired Deployment leaves replicas unset, upsertOutput keeps the live count. A new Deployment still starts at 1 through the Kubernetes default.
  • This matches how kagent treats Agent Deployments (mutateDeployment in kagent's translator/mutate.go).

An explicit replicas still wins, so existing manifests that set it behave as before.

Testing

  • Added TestUpsertOutputReplicas, using the controller-runtime fake client. It checks that an unset value keeps the live count of 3, and that an explicit 2 overrides it.
  • The CRD YAML was edited to match what controller-gen emits for the new comment, not regenerated with make manifests. Please let CI confirm.

🤖 Generated with Claude Code

The MCPServer CRD defaulted spec.deployment.replicas to 1 and the
controller fully replaced the Deployment on every reconcile. Because the
controller also watches its Deployments, every scale event from a
HorizontalPodAutoscaler triggered a reconcile that reset replicas to 1.

Drop the CRD default and keep the live replica count when the MCPServer
does not set one, matching how kagent handles Agent deployments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: German Arutyunov <garutyunov@tradingview.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HorizontalPodAutoscaler cannot scale MCPServer deployments: replicas reset to 1 on every reconcile

1 participant