Skip to content

Conversation

@jhrozek
Copy link
Contributor

@jhrozek jhrozek commented Dec 4, 2025

This PR fixes a bug where applying a PodTemplateSpec with only pod-level settings would accidentally wipe out the controller-generated vmcp container.

The root cause was Go's JSON marshaling behavior - when we parsed the user's JSON into Go structs and re-marshaled it, nil slices became empty arrays ([]), which strategic merge patch interpreted as "delete all containers".

The fix is: we now use the raw JSON bytes directly from the user's PodTemplateSpec for the strategic merge patch, preserving exactly what they specified without any round-trip through Go structs.

I also added a regression test that explicitly verifies the container is preserved when only a nodeSelector is provided, improved error handling in the integration tests, and fixed an edge case for empty raw bytes.

@github-actions github-actions bot added the size/M Medium PR: 300-599 lines changed label Dec 4, 2025
@codecov
Copy link

codecov bot commented Dec 4, 2025

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.40%. Comparing base (da719b8) to head (565f6b5).
⚠️ Report is 26 commits behind head on main.

Files with missing lines Patch % Lines
...perator/controllers/virtualmcpserver_deployment.go 50.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2897   +/-   ##
=======================================
  Coverage   56.40%   56.40%           
=======================================
  Files         322      322           
  Lines       31633    31637    +4     
=======================================
+ Hits        17842    17845    +3     
- Misses      12253    12254    +1     
  Partials     1538     1538           

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

When users provided a PodTemplateSpec with only pod-level settings
(like nodeSelector), the Deployment creation failed because containers
were being wiped out.

Root cause: The code parsed user JSON into a Go struct then re-marshaled
it. Go's json.Marshal converts nil slices to [], which strategic merge
patch interprets as "replace with empty array" - removing the vmcp
container.

Fix: Use the raw JSON bytes directly from Spec.PodTemplateSpec.Raw
instead of re-marshaling, preserving exactly what the user specified.
@github-actions github-actions bot added size/M Medium PR: 300-599 lines changed and removed size/M Medium PR: 300-599 lines changed labels Dec 4, 2025
@jhrozek jhrozek merged commit a08b8ba into main Dec 5, 2025
33 checks passed
@jhrozek jhrozek deleted the fix-vmcp-patch branch December 5, 2025 10:57
carlos-gn pushed a commit to carlos-gn/toolhive that referenced this pull request Dec 8, 2025
…cklok#2897)

* Fix PodTemplateSpec strategic merge wiping containers

When users provided a PodTemplateSpec with only pod-level settings
(like nodeSelector), the Deployment creation failed because containers
were being wiped out.

Root cause: The code parsed user JSON into a Go struct then re-marshaled
it. Go's json.Marshal converts nil slices to [], which strategic merge
patch interprets as "replace with empty array" - removing the vmcp
container.

Fix: Use the raw JSON bytes directly from Spec.PodTemplateSpec.Raw
instead of re-marshaling, preserving exactly what the user specified.

* Add integration test for the vMCP podTemplateSpec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Medium PR: 300-599 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants