-
Notifications
You must be signed in to change notification settings - Fork 133
Reduce MCPServer CRD size by using runtime.RawExtension for PodTemplateSpec #2015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2015 +/- ##
==========================================
+ Coverage 53.43% 53.57% +0.13%
==========================================
Files 238 238
Lines 30572 30658 +86
==========================================
+ Hits 16336 16424 +88
+ Misses 13068 13064 -4
- Partials 1168 1170 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
bf4a82f
to
c22bf13
Compare
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. |
4d28669
to
cd7f211
Compare
0401195
to
ac354b1
Compare
160cd36
to
58d7698
Compare
cmd/thv-operator/controllers/mcpserver_podtemplatespec_invalid_test.go
Outdated
Show resolved
Hide resolved
...ingle-tenancy/test-scenarios/invalid-podtemplatespec/assert-mcpserver-invalid-condition.yaml
Outdated
Show resolved
Hide resolved
0831563
to
8a1d9d2
Compare
…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
53cc1aa
to
33b8094
Compare
The CRD has been modified (MCPServer.spec.podTemplateSpec changed to runtime.RawExtension), so the chart version needs to be bumped per CI requirements. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
@claude please do a thorough review of this PR. |
Claude finished @JAORMX's task —— View job Thorough PR ReviewI've completed a comprehensive review of this PR. Here are my findings: Review SummaryThis PR successfully reduces the MCPServer CRD size from ~9,500 lines to 678 lines (93% reduction) by changing the Major Strengths ✅1. Excellent Problem-Solution Fit
2. Robust Error HandlingThe validation logic in
3. Strong Test CoverageThree levels of testing:
4. Backward Compatibility MaintainedUsers can continue using the same YAML structure - the change is transparent to them. Issues and Concerns 🔴1. Security Concern: Validation Gap
|
There was a problem hiding this 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 reduces the MCPServer CRD size by 93% (from ~9,500 to 651 lines) by changing the PodTemplateSpec
field from a strongly-typed corev1.PodTemplateSpec
to runtime.RawExtension
. This resolves deployment issues while maintaining full backwards compatibility through runtime validation.
Key Changes:
- Modified
PodTemplateSpec
field type toruntime.RawExtension
for schema flexibility - Added runtime validation with proper error handling via events and status conditions
- Updated builder pattern to handle unmarshalling and validation of raw JSON/YAML
Reviewed Changes
Copilot reviewed 20 out of 21 changed files in this pull request and generated 4 comments.
Show a summary per file
File | Description |
---|---|
cmd/thv-operator/api/v1alpha1/mcpserver_types.go |
Changed PodTemplateSpec field from corev1.PodTemplateSpec to runtime.RawExtension |
cmd/thv-operator/api/v1alpha1/zz_generated.deepcopy.go |
Updated generated deep copy code for the new type |
cmd/thv-operator/controllers/mcpserver_controller.go |
Added validation logic, event recorder, and error handling for invalid PodTemplateSpec |
cmd/thv-operator/controllers/mcpserver_podtemplatespec_builder.go |
Updated builder to unmarshal RawExtension and return errors on invalid specs |
cmd/thv-operator/controllers/mcpserver_podtemplatespec_builder_test.go |
Added comprehensive tests for invalid spec scenarios |
cmd/thv-operator/controllers/mcpserver_invalid_podtemplate_reconcile_test.go |
New test file for reconciler behavior with invalid specs |
cmd/thv-operator/controllers/mcpserver_runconfig.go |
Updated Vault detection to unmarshal RawExtension |
cmd/thv-operator/controllers/mcpserver_pod_template_test.go |
Refactored to use helper function for RawExtension conversion |
cmd/thv-operator/controllers/helpers_test.go |
New helper function for test PodTemplateSpec conversion |
cmd/thv-operator/main.go |
Added event recorder initialization |
test/e2e/chainsaw/operator/single-tenancy/test-scenarios/valid-podtemplatespec/* |
New e2e test suite for valid PodTemplateSpec scenarios |
docs/operator/crd-api.md |
Updated documentation to reflect new field type |
deploy/charts/operator-crds/Chart.yaml |
Bumped chart version to 0.0.40 |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
cmd/thv-operator/controllers/mcpserver_podtemplatespec_builder.go
Outdated
Show resolved
Hide resolved
Fixes based on Copilot and reviewer feedback: - Fix DeepCopy call to use pointer: (&userTemplate).DeepCopy() - Remove duplicate test assertions in pod template tests - Remove redundant PodTemplateSpec check in deploymentNeedsUpdate - Remove ~200 lines of dead code (non-ConfigMap mode paths) - Remove 5 unused functions (getProxyHost, generateOIDCArgs, etc.) - Improve isEmpty() to check all meaningful PodTemplateSpec fields All tests passing and linter clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
There was a problem hiding this 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 20 out of 21 changed files in this pull request and generated 3 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
...w/operator/single-tenancy/test-scenarios/valid-podtemplatespec/assert-deployment-exists.yaml
Outdated
Show resolved
Hide resolved
Define constants for PodTemplateSpec validation condition types and reasons in the API types file, following the pattern established for ImageValidated and GroupRefValidated conditions. Changes: - Add ConditionPodTemplateValid constant - Add ConditionReasonPodTemplateValid and ConditionReasonPodTemplateInvalid - Update controller code to use constants instead of string literals - Update tests to use constants This improves maintainability and follows Kubernetes API conventions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
The Watches() handler for MCPExternalAuthConfig was accidentally removed during code cleanup. This handler is critical for triggering MCPServer reconciliation when the referenced external auth config changes. Without this handler, MCPServers would not be updated when their ExternalAuthConfigRef changes, breaking the token exchange integration. Changes: - Restore externalAuthConfigHandler in SetupWithManager - Add Watches() call for MCPExternalAuthConfig - Add missing imports: handler and reconcile packages 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Update the comment in deploymentForMCPServer to clarify that the PodTemplateSpec validation error handling is unreachable in normal flow because early validation in Reconcile() blocks invalid specs. The error handling at line 881-885 is defense-in-depth: it provides a safety net if validation is somehow bypassed or refactored in the future. This addresses confusion about whether invalid PodTemplateSpec can bypass security constraints (it cannot - early validation blocks it). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
@claude can you remove the e2e tests from this PR? We don't need those right now for this feature |
Claude finished @JAORMX's task —— View job Removing E2E TestsI've successfully removed the e2e tests from this PR as requested. Todo List:
Summary: Removed the entire
The integration tests in Changes have been committed and pushed to the Branch: |
Integration tests provide sufficient coverage for this feature, making the e2e tests redundant. Co-authored-by: Juan Antonio Osorio <[email protected]>
Signed-off-by: ChrisJBurns <[email protected]>
@jhrozek one more green tick and I think we should be good to go |
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
Changes Made
Testing
Added comprehensive test coverage including:
Breaking Changes
None - this change maintains full backwards compatibility.
Fixes #2013