Align operator validation/defaulting with MCP server webhook#69
Align operator validation/defaulting with MCP server webhook#69Agent-Hellboy merged 4 commits intomainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
✅ Files skipped from review due to trivial changes (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a mutating webhook Default() for MCPServer and moves extensive defaulting/validation into the CRD; the operator controller now delegates MCPServer spec validation/defaulting to the API layer and simplifies its reconciliation logic. Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant Client as API Client
participant APIServer as Kubernetes<br/>API Server
participant Webhook as MCPServer<br/>Mutating/Validating Webhook
participant CRD as MCPServer<br/>Stored Resource
participant Operator as MCPServer<br/>Controller
User->>Client: Create MCPServer resource
Client->>APIServer: POST /apis/.../mcpservers
APIServer->>Webhook: AdmissionRequest (mutate/validate)
Webhook->>Webhook: Default() sets missing fields
Webhook->>Webhook: ValidateCreate() enforces rules
alt Validation fails
Webhook-->>APIServer: AdmissionResponse (reject + errors)
APIServer-->>Client: Error response
else Validation succeeds
Webhook-->>APIServer: AdmissionResponse (allow, mutated object)
APIServer->>CRD: Persist mutated MCPServer
CRD->>Operator: Inform controller (watch event)
Operator->>Operator: Reconcile using validated/defaulted spec
Operator-->>CRD: Update status
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 0/1 reviews remaining, refill in 60 minutes.Comment |
|
@codex please review |
|
@coderabbitai please review |
|
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c492c66806
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if strings.TrimSpace(mcpServer.Spec.IngressHost) == "" && strings.TrimSpace(mcpServer.Spec.PublicPathPrefix) == "" { | ||
| mcpServer.Spec.IngressHost = strings.TrimSpace(r.DefaultIngressHost) |
There was a problem hiding this comment.
Preserve DefaultIngressHost fallback when deriving publicPathPrefix
setDefaults now calls mcpServer.Default() first, which populates spec.publicPathPrefix from metadata.name; as a result, this if condition is never true for normal named resources, so DefaultIngressHost is never applied. In clusters that rely on MCP_DEFAULT_INGRESS_HOST for host-based routing, servers created without an explicit spec.ingressHost will silently stay hostless and route via path-prefix mode instead of the configured default host.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
internal/operator/controller.go (1)
183-197:ValidateCreate()is duplicated and error labeling is misleading.Both
validateIngressConfig()andvalidateGatewayConfig()run fullValidateCreate()against the same object. This adds redundant work and can report gateway/rollout/auth validation failures as “Invalid ingress configuration”.♻️ Suggested simplification
func (r *MCPServerReconciler) validateIngressConfig(ctx context.Context, mcpServer *mcpv1alpha1.MCPServer, logger logr.Logger) error { if _, err := mcpServer.ValidateCreate(); err != nil { r.updateStatus(ctx, mcpServer, "Error", err.Error(), resourceReadiness{}) - logOperatorError(logger, err, "Invalid ingress configuration") + logOperatorError(logger, err, "Invalid MCPServer specification") return err } return nil } func (r *MCPServerReconciler) validateGatewayConfig(ctx context.Context, mcpServer *mcpv1alpha1.MCPServer, logger logr.Logger) error { - if _, err := mcpServer.ValidateCreate(); err != nil { - r.updateStatus(ctx, mcpServer, "Error", err.Error(), resourceReadiness{}) - logOperatorError(logger, err, "Invalid gateway configuration") - return err - } - if gatewayEnabled(mcpServer) { if _, err := r.resolveGatewayImage(mcpServer); err != nil {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/operator/controller.go` around lines 183 - 197, Both validateIngressConfig and validateGatewayConfig call mcpServer.ValidateCreate(), causing redundant validation and mislabelled errors; to fix, remove the direct ValidateCreate() call from these two functions and centralize the call once (either in the reconcile entrypoint or a new helper like validateCommonConfig that invokes mcpServer.ValidateCreate()), then have validateIngressConfig and validateGatewayConfig perform only their specific checks and call updateStatus/logOperatorError with the correct context-specific messages ("Invalid ingress configuration" in validateIngressConfig and "Invalid gateway configuration" in validateGatewayConfig) so errors are not misattributed; reference the functions validateIngressConfig, validateGatewayConfig, ValidateCreate, updateStatus, and logOperatorError when making the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@internal/operator/controller.go`:
- Around line 324-329: The fallback for IngressHost runs after calling
mcpServer.Default(), but Default() may populate Spec.PublicPathPrefix from
metadata.name which causes the conditional to be false and prevents applying
DefaultIngressHost; to fix, capture whether PublicPathPrefix was empty before
calling mcpServer.Default() (e.g. save origPrefix :=
strings.TrimSpace(mcpServer.Spec.PublicPathPrefix)), then call
mcpServer.Default(), and only set mcpServer.Spec.IngressHost =
strings.TrimSpace(r.DefaultIngressHost) when
strings.TrimSpace(mcpServer.Spec.IngressHost) == "" && origPrefix == "" so
DefaultIngressHost is applied when the user didn’t supply a publicPathPrefix.
---
Nitpick comments:
In `@internal/operator/controller.go`:
- Around line 183-197: Both validateIngressConfig and validateGatewayConfig call
mcpServer.ValidateCreate(), causing redundant validation and mislabelled errors;
to fix, remove the direct ValidateCreate() call from these two functions and
centralize the call once (either in the reconcile entrypoint or a new helper
like validateCommonConfig that invokes mcpServer.ValidateCreate()), then have
validateIngressConfig and validateGatewayConfig perform only their specific
checks and call updateStatus/logOperatorError with the correct context-specific
messages ("Invalid ingress configuration" in validateIngressConfig and "Invalid
gateway configuration" in validateGatewayConfig) so errors are not
misattributed; reference the functions validateIngressConfig,
validateGatewayConfig, ValidateCreate, updateStatus, and logOperatorError when
making the change.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 1bef83eb-d11d-46ee-a645-744457a09bb2
📒 Files selected for processing (4)
api/v1alpha1/validation.goapi/v1alpha1/validation_test.gointernal/operator/controller.gointernal/operator/controller_test.go
|
@code-review-assist please review |
17d5128 to
93cf12d
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #69 +/- ##
==========================================
+ Coverage 57.05% 57.14% +0.09%
==========================================
Files 59 59
Lines 10489 10436 -53
==========================================
- Hits 5984 5964 -20
+ Misses 3939 3903 -36
- Partials 566 569 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Summary by CodeRabbit
New Features
Improvements