Skip to content

fix(operator): recreate deleted MCPServer StatefulSet - #6379

Merged
reyortiz3 merged 5 commits into
stacklok:mainfrom
RaviTharuma:fix/recreate-deleted-mcpserver-sts
Aug 21, 2026
Merged

reyortiz3 merged 5 commits into
stacklok:mainfrom
RaviTharuma:fix/recreate-deleted-mcpserver-sts

Conversation

@RaviTharuma

@RaviTharuma RaviTharuma commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Cross-links

Summary

Deleting the runner-created MCPServer StatefulSet left the proxy Deployment
up and Ready=true. Clients hit a dead backend. The operator created the
Deployment but did not watch/adopt the STS, so orphan-cleanup scripts treated
it as leftover.

  • Watch ToolHive StatefulSets and adopt a controller owner-ref on the
    MCPServer
  • If the STS is missing and the proxy is already Available, bounce the proxy
    (existing restarted-at annotation, 2m cooldown) so the runner re-applies
  • If the proxy is not yet Available, only requeue (do not interrupt first
    boot)
  • Status: proxy running + STS missing → Pending, Ready=False
  • Document the dual Deployment + StatefulSet model

Fixes #6343

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe):

Test plan

  • go test -ldflags=-extldflags=-Wl,-w ./cmd/thv-operator/controllers/ -run 'TestEnsureWorkloadStatefulSet|TestMapStatefulSetToMCPServer|TestRecentlyBounced'
  • CI unit / operator tests
  • After merge: deleting the workload STS should bounce the proxy, recreate
    the STS, and keep MCPServer Pending until it is back

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.

No CRD schema change. RBAC already includes StatefulSets.

Does this introduce a user-facing change?

Yes. A deleted MCPServer workload StatefulSet is recreated on the next
reconcile, and Ready is no longer claimed on a proxy-only stack. See
docs/operator/mcpserver-workloads.md.

Special notes for reviewers

The operator still does not author the STS spec — the proxy-runner does via
SSA. Recreate is "bounce the runner so it applies again," which matches how
the STS is born. Cooldown avoids a restart loop while the runner is still
starting.

The runner-created workload StatefulSet had no owner watch, so deleting
it left Ready true on a proxy-only stack. Adopt the STS, recreate it by
bouncing the proxy when it is missing, and keep status Pending until it
returns.

Fixes stacklok#6343
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@RaviTharuma

Copy link
Copy Markdown
Contributor Author

@reyortiz3

Copy link
Copy Markdown
Collaborator

@RaviTharuma mind fixing the lint error?

@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 61.00000% with 39 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.67%. Comparing base (406fd8d) to head (a547117).
⚠️ Report is 21 commits behind head on main.

Files with missing lines Patch % Lines
.../thv-operator/controllers/mcpserver_statefulset.go 64.70% 24 Missing ⚠️
...d/thv-operator/controllers/mcpserver_controller.go 53.12% 15 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6379      +/-   ##
==========================================
+ Coverage   72.98%   77.67%   +4.69%     
==========================================
  Files         744      751       +7     
  Lines       78611    72694    -5917     
==========================================
- Hits        57374    56467     -907     
+ Misses      17236    16222    -1014     
+ Partials     4001        5    -3996     

☔ 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.

@reyortiz3
reyortiz3 merged commit b48013e into stacklok:main Aug 21, 2026
44 checks passed
@github-actions github-actions Bot mentioned this pull request Aug 26, 2026
2 tasks
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.

bug(operator): deleted MCPServer StatefulSet is not recreated

2 participants