Skip to content

wire spec-driven replicas and Redis password for VirtualMCPServer#4367

Merged
yrobla merged 2 commits intomainfrom
issue-4215
Mar 26, 2026
Merged

wire spec-driven replicas and Redis password for VirtualMCPServer#4367
yrobla merged 2 commits intomainfrom
issue-4215

Conversation

@yrobla
Copy link
Copy Markdown
Contributor

@yrobla yrobla commented Mar 25, 2026

Summary

  • Nil-passthrough for Deployment.Spec.Replicas (hands-off when spec.replicas is nil, spec-driven when set) for HPA compatibility
  • Add terminationGracePeriodSeconds (30s) to vMCP pod spec
  • Add buildRedisPasswordEnvVar: injects THV_SESSION_REDIS_PASSWORD from SessionStorageConfig.PasswordRef when provider is redis
  • Sync Spec.Replicas on update when spec.replicas is non-nil
  • deploymentNeedsUpdate detects replica drift for spec-driven scaling

Fixes #4215

Type of change

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

Test plan

  • Unit tests (task test)
  • E2E tests (task test-e2e)
  • Linting (task lint-fix)
  • Manual testing (describe below)

Changes

File Change

Does this introduce a user-facing change?

Special notes for reviewers

@yrobla yrobla requested a review from Copilot March 25, 2026 15:12
@github-actions github-actions bot added the size/XS Extra small PR: < 100 lines changed label Mar 25, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the ToolHive operator’s VirtualMCPServer Deployment wiring to support HPA-compatible scaling (nil-passthrough replicas), adds a default graceful shutdown period for vMCP pods, and injects a Redis password env var when session storage is configured for Redis.

Changes:

  • Make Deployment.Spec.Replicas spec-driven with nil-passthrough to avoid fighting HPAs when spec.replicas is unset.
  • Set TerminationGracePeriodSeconds (30s) on the vMCP pod spec.
  • Inject THV_SESSION_REDIS_PASSWORD from spec.sessionStorage.passwordRef when provider == "redis", and sync replica drift on update when spec.replicas is set.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
cmd/thv-operator/controllers/virtualmcpserver_deployment.go Implements nil-passthrough replicas, adds termination grace period, and injects Redis password env var.
cmd/thv-operator/controllers/virtualmcpserver_controller.go Updates reconciliation logic to sync replicas only when spec.replicas is set; adds replica drift detection.
cmd/thv-operator/controllers/virtualmcpserver_deployment_test.go Updates expectations for nil replicas in the deployment builder test.
cmd/thv-operator/controllers/virtualmcpserver_controller_test.go Updates expectations for nil replicas in ensureDeployment test.
cmd/thv-operator/controllers/mcpserver_pod_template_test.go Removes local int64Ptr helper (now provided by package-level helper).
cmd/thv-operator/controllers/mcpserver_controller.go Adds shared int64Ptr helper used by vMCP deployment builder (and tests).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 25, 2026

Codecov Report

❌ Patch coverage is 64.00000% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.47%. Comparing base (6b8f044) to head (1a0dc42).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...perator/controllers/virtualmcpserver_controller.go 37.93% 16 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4367      +/-   ##
==========================================
+ Coverage   69.43%   69.47%   +0.03%     
==========================================
  Files         485      485              
  Lines       49493    49539      +46     
==========================================
+ Hits        34367    34415      +48     
+ Misses      12466    12458       -8     
- Partials     2660     2666       +6     

☔ View full report in Codecov by Sentry.
📢 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.

@yrobla yrobla requested a review from Copilot March 25, 2026 15:31
@github-actions github-actions bot added size/S Small PR: 100-299 lines changed and removed size/XS Extra small PR: < 100 lines changed labels Mar 25, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

jerm-dro
jerm-dro previously approved these changes Mar 25, 2026
@yrobla yrobla force-pushed the feat/thv-0047-crd-type-changes branch 3 times, most recently from 31e22a5 to 6788d84 Compare March 26, 2026 10:12
taskbot added 2 commits March 26, 2026 12:05
Add SessionStorageConfig struct and scaling fields to MCPServer and
VirtualMCPServer CRDs as the foundation for horizontal scaling support.

- Add SessionStorageConfig struct with Provider, Address, DB, KeyPrefix,
  and PasswordRef fields; CEL rule enforces address is required for redis
- Add Replicas *int32, BackendReplicas *int32, SessionStorage to MCPServerSpec
- Add Replicas *int32, SessionStorage to VirtualMCPServerSpec
- Nil pointer fields allow HPA to manage replicas without operator interference
- Regenerate zz_generated.deepcopy.go and CRD manifests

Closes: #4206
- Nil-passthrough for Deployment.Spec.Replicas (hands-off when spec.replicas
  is nil, spec-driven when set) for HPA compatibility
- Add terminationGracePeriodSeconds (30s) to vMCP pod spec
- Add buildRedisPasswordEnvVar: injects THV_SESSION_REDIS_PASSWORD from
  SessionStorageConfig.PasswordRef when provider is redis
- Sync Spec.Replicas on update when spec.replicas is non-nil
- deploymentNeedsUpdate detects replica drift for spec-driven scaling

Closes: #4215
@yrobla yrobla requested a review from Copilot March 26, 2026 11:26
@github-actions github-actions bot added size/XL Extra large PR: 1000+ lines changed and removed size/S Small PR: 100-299 lines changed labels Mar 26, 2026
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Large PR Detected

This PR exceeds 1000 lines of changes and requires justification before it can be reviewed.

How to unblock this PR:

Add a section to your PR description with the following format:

## Large PR Justification

[Explain why this PR must be large, such as:]
- Generated code that cannot be split
- Large refactoring that must be atomic
- Multiple related changes that would break if separated
- Migration or data transformation

Alternative:

Consider splitting this PR into smaller, focused changes (< 1000 lines each) for easier review and reduced risk.

See our Contributing Guidelines for more details.


This review will be automatically dismissed once you add the justification section.

@yrobla yrobla changed the base branch from feat/thv-0047-crd-type-changes to main March 26, 2026 11:27
@yrobla yrobla dismissed jerm-dro’s stale review March 26, 2026 11:27

The base branch was changed.

@yrobla yrobla requested a review from jerm-dro March 26, 2026 11:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

cmd/thv-operator/controllers/mcpserver_controller.go:472

  • Same pattern here: the controller only updates Deployment.Spec.Replicas when spec.replicas is non-nil. If spec.replicas is later unset (nil) to hand scaling back to an HPA/external controller, the existing Deployment.Spec.Replicas will not be cleared and may stay pinned to the previous value. Consider explicitly clearing deployment.Spec.Replicas when the desired replicas resolves to nil.
		deployment.Annotations = ctrlutil.MergeAnnotations(newDeployment.Annotations, deployment.Annotations)
		if newDeployment.Spec.Replicas != nil {
			deployment.Spec.Replicas = newDeployment.Spec.Replicas
		}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@yrobla yrobla merged commit aa18184 into main Mar 26, 2026
70 of 73 checks passed
@yrobla yrobla deleted the issue-4215 branch March 26, 2026 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XL Extra large PR: 1000+ lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extend deploymentForVirtualMCPServer with spec-driven replicas, terminationGracePeriodSeconds, and Redis password env var

5 participants