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

…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
Copy link

codecov bot commented Sep 25, 2025

Codecov Report

❌ Patch coverage is 61.81818% with 42 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.05%. Comparing base (417c167) to head (bf4a82f).

Files with missing lines Patch % Lines
...d/thv-operator/controllers/mcpserver_controller.go 55.43% 36 Missing and 5 partials ⚠️
...thv-operator/api/v1alpha1/zz_generated.deepcopy.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2015      +/-   ##
==========================================
+ Coverage   47.91%   48.05%   +0.13%     
==========================================
  Files         233      233              
  Lines       29172    29236      +64     
==========================================
+ Hits        13979    14050      +71     
+ Misses      14165    14151      -14     
- Partials     1028     1035       +7     

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

if err != nil {
// Record event for invalid PodTemplateSpec
r.Recorder.Eventf(mcpServer, corev1.EventTypeWarning, "InvalidPodTemplateSpec",
"Failed to parse PodTemplateSpec: %v. Deployment will continue without pod customizations.", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think we should continue without the podTemplateSpec rather than fail? This is a change in behaviour and I wonder if it can allow users to spin up MCP servers with less security than intended,

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
2 participants