Skip to content

Extract mutation from Validate method into separate defaulting logic #4628

Done

Description

@ChrisJBurns

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:

  1. Is never persisted to the API server (the controller doesn't write back to spec)
  2. Is re-applied every reconciliation from a fresh cache copy
  3. 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

  1. Extract to a separate ApplyDefaults() method or a proper Default() webhook
  2. Call ApplyDefaults() before Validate() in the controller
  3. Document that the defaulting is controller-side only

Activity

  1. added
    bug
    go
    kubernetes
    api
    vmcp
    on Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    apibuggokubernetesoperatorvmcp

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions