Skip to content

Conversation

JAORMX
Copy link
Collaborator

@JAORMX JAORMX commented Sep 25, 2025

Summary

This PR addresses issue #2013 by significantly reducing the MCPServer CRD size from ~9500 lines to 651 lines (93% reduction).

Problem

The MCPServer CRD was too large (~9500 lines) to apply without server-side apply due to the embedded PodTemplateSpec taking up ~8500 lines. This was causing deployment issues as reported in #2013.

Solution

Changed the PodTemplateSpec field from a strongly-typed `corev1.PodTemplateSpec` to `runtime.RawExtension`, which stores the raw JSON without schema validation at the CRD level.

Key Benefits

  • 93% CRD size reduction (from ~9500 to 651 lines)
  • Full backwards compatibility - users can still use the same YAML structure
  • Runtime validation - validation now happens at runtime in the operator
  • Proper error handling - via Kubernetes events and status conditions

Changes Made

  • Modified MCPServer type to use `runtime.RawExtension` for PodTemplateSpec
  • Updated PodTemplateSpecBuilder to unmarshal and validate at runtime
  • Added event recording and status conditions for validation errors
  • Added comprehensive tests for invalid PodTemplateSpec scenarios
  • Fixed race conditions in parallel tests

Testing

Added comprehensive test coverage including:

  • Invalid PodTemplateSpec validation tests
  • Integration tests for error scenarios
  • Race condition fixes in parallel test execution

Breaking Changes

None - this change maintains full backwards compatibility.

Fixes #2013

Copy link

codecov bot commented Sep 25, 2025

Codecov Report

❌ Patch coverage is 60.43165% with 55 lines in your changes missing coverage. Please review.
✅ Project coverage is 53.07%. Comparing base (73707af) to head (0831563).

Files with missing lines Patch % Lines
...d/thv-operator/controllers/mcpserver_controller.go 55.37% 49 Missing and 5 partials ⚠️
cmd/thv-operator/main.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2015      +/-   ##
==========================================
+ Coverage   53.06%   53.07%   +0.01%     
==========================================
  Files         223      223              
  Lines       29057    29143      +86     
==========================================
+ Hits        15418    15467      +49     
- Misses      12512    12549      +37     
  Partials     1127     1127              

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

@JAORMX JAORMX force-pushed the fix/mcpserver-crd-size-reduction branch from bf4a82f to c22bf13 Compare September 29, 2025 13:41
jhrozek
jhrozek previously approved these changes Sep 29, 2025
@jhrozek
Copy link
Contributor

jhrozek commented Sep 29, 2025

aah, I approved based on reading the code :-)

But in general the approach of not reconciling again if the podTemplateSpec is bad seems good to me.

@JAORMX JAORMX force-pushed the fix/mcpserver-crd-size-reduction branch 4 times, most recently from 4d28669 to cd7f211 Compare September 30, 2025 11:43
@JAORMX JAORMX requested a review from jhrozek September 30, 2025 11:46
@JAORMX JAORMX force-pushed the fix/mcpserver-crd-size-reduction branch 3 times, most recently from 0401195 to ac354b1 Compare October 1, 2025 09:31
@JAORMX JAORMX force-pushed the fix/mcpserver-crd-size-reduction branch 3 times, most recently from 160cd36 to 58d7698 Compare October 14, 2025 13:45
@JAORMX JAORMX force-pushed the fix/mcpserver-crd-size-reduction branch from 4930ac2 to e2038fb Compare October 15, 2025 13:08
JAORMX and others added 5 commits October 16, 2025 11:17
…teSpec

The MCPServer CRD was too large (~9500 lines) to apply without server-side
apply due to the embedded PodTemplateSpec taking up ~8500 lines. This was
causing issues as reported in GitHub issue #2013.

Changed the PodTemplateSpec field from a strongly-typed corev1.PodTemplateSpec
to runtime.RawExtension, which stores the raw JSON without schema validation
at the CRD level. This reduces the CRD size from ~9500 lines to 651 lines
(93% reduction).

The solution maintains full backwards compatibility - users can still use
the same YAML structure. Validation now happens at runtime in the operator,
with proper error handling via Kubernetes events and status conditions to
notify users when invalid PodTemplateSpec data is provided.

Key changes:
- Modified MCPServer type to use runtime.RawExtension for PodTemplateSpec
- Updated PodTemplateSpecBuilder to unmarshal and validate at runtime
- Added event recording and status conditions for validation errors
- Added comprehensive tests for invalid PodTemplateSpec scenarios
- Fixed race conditions in parallel tests

Fixes #2013
Replace unreliable Chainsaw assertion with explicit kubectl check
for deployment non-existence. The test now uses a bash script to
verify that no deployment is created when an invalid PodTemplateSpec
is provided.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Signed-off-by: Juan Antonio Osorio <[email protected]>
- Remove redundant reconciliation skip log (already logged in validation)
- Remove verbose logging for successful PodTemplateSpec validation
- Merge invalid PodTemplateSpec unit tests into builder test file
- Add integration test for invalid PodTemplateSpec scenario
- Remove redundant e2e test (replaced by integration test)

The validation function already logs errors and generates events, so the
additional log in the reconcile loop was redundant. Integration tests
provide better coverage than e2e tests for this scenario.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
- Add nil check for Recorder before calling Eventf to prevent panic
- Update TestDeploymentArgsWithInvalidPodTemplateSpec to match configmap mode behavior

The Recorder can be nil in test environments, causing a panic when
trying to record events. The deployment args test was checking for
flags that only exist in non-configmap mode.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@JAORMX JAORMX force-pushed the fix/mcpserver-crd-size-reduction branch from 0831563 to 8a1d9d2 Compare October 16, 2025 08:21
This chart version bump is required due to the MCPServer CRD changes
that modify the PodTemplateSpec field from corev1.PodTemplateSpec to
runtime.RawExtension, reducing CRD size by 8000+ lines.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
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.

The MCPServers CRD is too big

3 participants