Extract mutation from Validate method into separate defaulting logic
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 2.2k
- Forks
- 300
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 184
Description
Summary
The validateEmbeddingServer method on VirtualMCPServer mutates r.Spec.Config.Optimizer during validation — a defaulting operation hidden inside a validation function. The mutation is never persisted to the API server, is re-applied every reconciliation from a fresh cache copy, and is invisible to users via kubectl get.
Severity: MUST FIX
Area: API Design
Breaking: No
Location
cmd/thv-operator/api/v1alpha1/virtualmcpserver_types.go:475-480
Problem
// EmbeddingServerRef is set but optimizer is not configured: auto-populate
// optimizer with default values so the embedding server is actually used.
if hasRef && !hasOptimizer {
r.Spec.Config.Optimizer = &config.OptimizerConfig{}
}
This mutation inside a Validate() method:
- Is never persisted to the API server (the controller doesn't write back to spec)
- Is re-applied every reconciliation from a fresh cache copy
- Is invisible to users via
kubectl get
Impact
- Violation of separation of concerns (validation should not mutate)
- Users see a different spec than what the controller uses
- If webhooks are implemented, this logic would need to be a Defaulter, not a Validator
Recommended Fix
- Extract to a separate
ApplyDefaults()method or a properDefault()webhook - Call
ApplyDefaults()beforeValidate()in the controller - Document that the defaulting is controller-side only
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in cmd/thv-operator/api/v1alpha1/virtualmcpserver_types.go:475-480 and inspect validateEmbeddingServer and the controller path that calls validation. Separate the defaulting step from validation, invoke it before Validate, and verify the relevant operator/API tests pass while the existing embedding-server behavior is preserved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, kubernetes
- Domain
- backend-api-design, devops
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100