Skip to content

Fix MCPRegistry operator to update deployments on spec changes#4237

Merged
rdimitrov merged 4 commits intomainfrom
operator-registry-spec
Mar 19, 2026
Merged

Fix MCPRegistry operator to update deployments on spec changes#4237
rdimitrov merged 4 commits intomainfrom
operator-registry-spec

Conversation

@rdimitrov
Copy link
Copy Markdown
Member

@rdimitrov rdimitrov commented Mar 19, 2026

Summary

The MCPRegistry controller was ignoring changes to spec.podTemplateSpec (and all other spec fields) after the initial Deployment creation. The ensureDeployment method had a TODO that returned the stale existing Deployment without applying updates, so fields like imagePullSecrets and container env from podTemplateSpec were silently dropped.

This fix adds hash-based change detection (matching the VirtualMCPServer controller pattern) and selective Deployment updates when changes are detected.

Type of change

  • Bug fix

Changes

File Change
cmd/thv-operator/pkg/registryapi/deployment.go Replace dummy config-hash with real computed hash, add PodTemplateSpec hash annotation, add
deploymentNeedsUpdate function, implement selective Deployment update logic
cmd/thv-operator/pkg/registryapi/deployment_test.go Add tests for deploymentNeedsUpdate (8 cases) and PodTemplateSpec hash computation (3 cases),
update existing test for real config hash

Test plan

  • task lint passes with 0 issues
  • task test — all registryapi package tests pass
  • New TestDeploymentNeedsUpdate covers nil, identical, config hash change, PTS hash change/add/remove, and image change scenarios
  • New TestBuildRegistryAPIDeployment_PodTemplateSpecHash verifies hash presence/absence and uniqueness

Special notes for reviewers

  • Follows the same hash-based change detection pattern used by the VirtualMCPServer controller (podtemplatespec hash annotation + config checksum)
  • Spec.Replicas is preserved on the existing Deployment to avoid conflicts with HPA
  • Annotations are merged (not replaced) to preserve Kubernetes-managed annotations like deployment.kubernetes.io/revision`

Large PR Justification

  • Tests

Signed-off-by: Radoslav Dimitrov <radoslav@stacklok.com>
@rdimitrov rdimitrov self-assigned this Mar 19, 2026
@github-actions github-actions bot added the size/M Medium PR: 300-599 lines changed label Mar 19, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 19, 2026

Codecov Report

❌ Patch coverage is 72.09302% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.27%. Comparing base (5748d93) to head (78332fd).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
cmd/thv-operator/pkg/registryapi/deployment.go 72.09% 5 Missing and 7 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4237      +/-   ##
==========================================
- Coverage   69.32%   69.27%   -0.05%     
==========================================
  Files         470      470              
  Lines       47189    47240      +51     
==========================================
+ Hits        32712    32726      +14     
- Misses      11957    11965       +8     
- Partials     2520     2549      +29     

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

Signed-off-by: Radoslav Dimitrov <radoslav@stacklok.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 Mar 19, 2026
Signed-off-by: Radoslav Dimitrov <radoslav@stacklok.com>
@github-actions github-actions bot added size/XL Extra large PR: 1000+ lines changed and removed size/L Large PR: 600-999 lines changed labels Mar 19, 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.

@rdimitrov rdimitrov merged commit 95041a6 into main Mar 19, 2026
53 of 54 checks passed
@rdimitrov rdimitrov deleted the operator-registry-spec branch March 19, 2026 15:56
Sanskarzz pushed a commit to Sanskarzz/toolhive that referenced this pull request Mar 23, 2026
…lok#4237)

* Fix MCPRegistry operator to update deployments on spec changes

Signed-off-by: Radoslav Dimitrov <radoslav@stacklok.com>

* Add integration tests

Signed-off-by: Radoslav Dimitrov <radoslav@stacklok.com>

* Add more integration tests

Signed-off-by: Radoslav Dimitrov <radoslav@stacklok.com>

---------

Signed-off-by: Radoslav Dimitrov <radoslav@stacklok.com>
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.

2 participants