-
Notifications
You must be signed in to change notification settings - Fork 146
Extract common controller helpers from MCPRemoteProxy PR #2230
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
b05fdbb to
cd639a3
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2230 +/- ##
==========================================
- Coverage 53.54% 53.45% -0.09%
==========================================
Files 228 229 +1
Lines 29313 29375 +62
==========================================
+ Hits 15696 15703 +7
- Misses 12489 12542 +53
- Partials 1128 1130 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
cd639a3 to
c4262e1
Compare
…dPlatformDetector This extracts common helper functions from the large MCPRemoteProxy PR (#2226) into a shared common_helpers.go file that can be used by multiple controllers. Changes: - Add common_helpers.go with shared helper functions: - SharedPlatformDetector for platform detection across controllers - RBAC resource creation helpers (EnsureRBACResource, createRBACResource) - OpenTelemetry environment variable generation - Token exchange environment variable generation - Authorization volume configuration (GenerateAuthzVolumeConfig) - Authorization ConfigMap management (EnsureAuthzConfigMap) - Authorization config options for RunConfig (AddAuthzConfigOptions) - GetExternalAuthConfigByName for fetching external auth configs - Refactor MCPServerReconciler to use SharedPlatformDetector: - Replace individual platformDetector, detectedPlatform, and platformOnce fields with single PlatformDetector field - Update detectPlatform() to use shared detector - Initialize SharedPlatformDetector in main.go - Update deploymentForMCPServer to use local detectedPlatform variable - Add test helpers and fixtures: - newTestMCPServerReconciler() for test setup - newTestMCPServerReconcilerWithDetector() for custom detector injection - NewSharedPlatformDetectorWithDetector() for testing with mock detectors - Update all test files to use new helper functions - Fix imports in all test files to include kubernetes package This is the first step in adopting the common helpers from PR #2226. Additional refactoring will follow to adopt the remaining helper functions. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
This completes the adoption of common helper functions from PR #2226, removing duplication between the MCPServer controller and the upcoming MCPRemoteProxy controller. Changes: - Replace private generateOpenTelemetryEnvVars with common GenerateOpenTelemetryEnvVars - Replace private generateTokenExchangeEnvVars with common GenerateTokenExchangeEnvVars - Replace private generateAuthzVolumeConfig with common GenerateAuthzVolumeConfig - Replace private ensureAuthzConfigMap with common EnsureAuthzConfigMap - Replace private addAuthzConfigOptions with common AddAuthzConfigOptions - Update all test files to use common helpers directly - Remove unused imports (yaml, authz) from mcpserver_runconfig.go All functions are now shared and reusable across multiple controllers, reducing code duplication and improving maintainability. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
- Break long lines for GenerateTokenExchangeEnvVars calls - Break long line for EnsureAuthzConfigMap call - Rename mcpserver_test_helpers.go to mcpserver_test_helpers_test.go - Remove duplicate mockPlatformDetector from mcpserver_platform_test.go - Fix import shadowing by renaming client parameter to k8sClient - Add nolint:unparam for platform parameter - Remove unused newTestMCPServerReconcilerWithDetector function 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
c4262e1 to
51689ff
Compare
|
@claude pleaes thoroughly review this with a backwards compatibility and security focus in mind |
|
Claude finished @JAORMX's task —— View job Thorough Code Review - Backwards Compatibility & Security Focus
|
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
Extracts reusable controller helper functions from the MCPRemoteProxy PR into a common helpers file to reduce code duplication and prepare for future controller implementations. This refactoring moves shared functionality to common_helpers.go and updates the MCPServer controller to use these common patterns.
- Creates common helper functions for platform detection, RBAC resource management, OpenTelemetry configuration, token exchange, and authorization
- Refactors MCPServer controller to use SharedPlatformDetector instead of individual platform detection logic
- Updates all test files to use standardized test helper patterns
Reviewed Changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| cmd/thv-operator/controllers/common_helpers.go | New file containing extracted common helper functions for controllers |
| cmd/thv-operator/controllers/mcpserver_controller.go | Refactored to use SharedPlatformDetector and common helper functions |
| cmd/thv-operator/controllers/mcpserver_runconfig.go | Updated to use common AddAuthzConfigOptions function |
| cmd/thv-operator/controllers/mcpserver_test_helpers_test.go | New test helper utilities for standardized test setup |
| cmd/thv-operator/main.go | Updated to create and inject SharedPlatformDetector |
| cmd/thv-operator/test-integration/mcp-server/suite_test.go | Updated to use SharedPlatformDetector |
| Multiple test files | Updated to use newTestMCPServerReconciler helper for consistent test setup |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
During the refactoring to extract common helpers, the ConfigMap update logic was accidentally omitted from EnsureAuthzConfigMap. This caused authorization policy updates to be ignored after initial ConfigMap creation, breaking a core feature. This commit restores the update logic that checks for data changes using reflect.DeepEqual and updates the ConfigMap when needed. Also replaces hardcoded "authz.json" string with the defaultAuthzKey constant for consistency. Changes: - Add reflect import to common_helpers.go - Restore ConfigMap update logic in EnsureAuthzConfigMap (lines 351-362) - Replace hardcoded string with defaultAuthzKey constant (line 430) Addresses critical issues identified in PR review. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
@claude please review this again. |
|
Claude finished @JAORMX's task —— View job Comprehensive Code Review - Backwards Compatibility & Security FocusReviewing this refactoring PR with a focus on backwards compatibility and security implications after the fixes have been applied. Review SummaryThis refactoring successfully extracts common controller helpers and reduces code duplication by ~498 lines. The 2 critical issues identified in the previous review have been fixed. The changes are well-structured and maintain backwards compatibility. Critical Issues from Previous Review1. ✅ FIXED - Missing ConfigMap Update LogicLocation: Previous Issue: The Fix Applied: } else {
// ConfigMap exists, check if it needs to be updated
if !reflect.DeepEqual(existingConfigMap.Data, configMap.Data) {
ctxLogger.Info("Updating authorization ConfigMap",
"ConfigMap.Namespace", configMap.Namespace,
"ConfigMap.Name", configMap.Name)
existingConfigMap.Data = configMap.Data
if err := c.Update(ctx, existingConfigMap); err != nil {
return fmt.Errorf("failed to update authorization ConfigMap: %w", err)
}
}
}Verdict: ✅ Properly fixed - Users can now update inline authorization policies and the ConfigMap will be updated accordingly. 2. ✅ FIXED - Hardcoded String Instead of ConstantLocation: Multiple locations in Previous Issue: Code used hardcoded string Fix Applied: All occurrences now consistently use the Verdict: ✅ Properly fixed - Maintains DRY principle and makes future changes easier. Security Analysis✅ RBAC Changes - Safe
✅ Authorization Config - Safe
✅ Token Exchange - Safe
✅ Platform Detection - Safe
✅ OpenTelemetry - Safe
Backwards Compatibility Analysis✅ API Compatibility
✅ Behavior Preservation
✅ State Migration
Code Quality AnalysisStrengths
Areas for Improvement (Non-Blocking)
Test Coverage Analysis✅ Test Changes Look Good
Test Coverage Notes
Code Organization✅ Well-Organized RefactoringNew File:
Updated:
Updated:
Updated:
Specific Code Review NotesPlatform Detection (common_helpers.go:28-83)type SharedPlatformDetector struct {
detector kubernetes.PlatformDetector
detectedPlatform kubernetes.Platform
once sync.Once
config *rest.Config // Optional config for testing
}
RBAC Helper (common_helpers.go:86-133)func EnsureRBACResource(
ctx context.Context,
c client.Client,
scheme *runtime.Scheme,
owner client.Object,
resourceType string,
createResource func() client.Object,
) error
Authorization ConfigMap (common_helpers.go:289-365)func EnsureAuthzConfigMap(...)
Authorization Volume Config (common_helpers.go:209-287)func GenerateAuthzVolumeConfig(...)
Recommended Follow-Up (Optional, Not Blocking)
Final Verdict✅ APPROVED - Ready to MergeThis refactoring is well-executed and achieves its goals: Strengths:
Impact:
Net Result: This PR successfully achieves its goal of preparing the codebase for future controller implementations (MCPRemoteProxy) while maintaining stability and security. Reviewed: 16 files, 623 additions, 516 deletions Job Run | Branch: |
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 16 out of 16 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Adds integration test that verifies ConfigMap updates when inline authorization policies change. This test ensures the fix for the missing update logic works correctly. Test scenario: 1. Create MCPServer with initial inline authz config 2. Verify ConfigMap is created with initial policies 3. Update MCPServer with different policies and entities 4. Verify ConfigMap is updated with new data This addresses the "Recommended Change" from the PR review to add integration test coverage for the ConfigMap update logic. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>

Summary
Extracts reusable controller helper functions from PR #2226 into
common_helpers.goand refactors MCPServer controller to use them. This reduces code duplication and prepares for future controller implementations.Net impact: -498 lines of duplicated code
Key Changes
New common helpers (
common_helpers.go):SharedPlatformDetector- Shared platform detection across controllersEnsureRBACResource- Generic RBAC resource managementGenerateOpenTelemetryEnvVars- OTEL environment variable generationGenerateTokenExchangeEnvVars- Token exchange env var generationGenerateAuthzVolumeConfig- Authorization volume configurationEnsureAuthzConfigMap- Authorization ConfigMap managementAddAuthzConfigOptions- Authorization options for RunConfigGetExternalAuthConfigByName- External auth config fetchingMCPServer refactoring:
SharedPlatformDetectorTest infrastructure:
mcpserver_test_helpers_test.gowith test setup utilitiesTest Plan
task test)task lint-fix)Related
Split from #2226 to enable focused review of infrastructure improvements.
🤖 Generated with Claude Code