Skip to content

Remove deprecated legacy typed fields from MCPRegistry CRD #4704

Closed

Description

@ChrisJBurns

Parent

Part of #4701 (Phase 2)

Preconditions

Summary

Remove the legacy typed config fields and all associated operator code after users have migrated to the configYAML path. This eliminates ~6,100 net lines of code.

Implementation Plan

Step 0: Prerequisite Research (before coding)

Investigate before starting:

  • GetStorageName() — used by pkg/validation/image_validation.go:206 for a ConfigMap name pattern. Determine if this is still relevant in the new path or needs adaptation.
  • Verify no Helm chart templates reference legacy CRD fields.

Step 1: CRD Types — Remove Legacy Types and Fields

File: `cmd/thv-operator/api/v1alpha1/mcpregistry_types.go`
Blocking: Everything downstream depends on this.

Delete all legacy type definitions (~600 lines):

  • `MCPRegistrySourceConfig`, `MCPRegistryViewConfig`, `ManagedSource`, `KubernetesSource`, `URLSource`
  • `GitSource`, `GitAuthConfig`, `APISource`, `SyncPolicy`
  • `RegistryFilter`, `NameFilter`, `TagFilter`
  • `MCPRegistryDatabaseConfig`, `MCPRegistryDynamicAuthConfig`, `MCPRegistryAWSRDSIAMConfig`
  • `MCPRegistryAuthConfig`, `MCPRegistryAuthMode` (type + constants), `MCPRegistryOAuthConfig`, `MCPRegistryOAuthProviderConfig`
  • `MCPRegistryAuthzConfig`, `MCPRegistryRolesConfig`
  • `MCPRegistryTelemetryConfig`, `MCPRegistryTracingConfig`, `MCPRegistryMetricsConfig`

Delete deprecated fields from `MCPRegistrySpec`:

  • `Sources`, `Registries`, `DatabaseConfig`, `AuthConfig`, `TelemetryConfig`

Delete format constants:

  • `RegistryFormatToolHive`, `RegistryFormatUpstream`

Delete legacy helper methods:

  • `BuildPGPassSecretName()`, `HasDatabaseConfig()`, `GetDatabaseConfig()`, `GetDatabasePort()`
  • `GetStorageName()` — only if Step 0 confirms it's safe

Make `ConfigYAML` required (`+kubebuilder:validation:Required`, `+kubebuilder:validation:MinLength=1`).

Delete/simplify CEL validation rules:

  • Remove `size(self.spec.configYAML) > 0 || ...` (configYAML is now required)
  • Remove `self.spec.sources.filter(...)` (sources no longer exist)

Step 2: Regenerate Deepcopy and CRD Manifests

Run immediately after Step 1:

task operator-generate
task operator-manifests
task crdref-gen   # from repo root

Steps 3-8: Parallel Code Removal

These steps are independent and can be done in parallel after Step 1 compiles.

Step 3: Delete Legacy Config Package Code (~3,300 lines)

Delete: `pkg/registryapi/config/config.go` — all `build*` functions, `ConfigManager` interface, all config struct types. Keep only `RegistryServerConfigFilePath` and `RegistryServerConfigFileName` constants (move to `raw_config.go` if the file becomes too sparse).

Delete entirely: `pkg/registryapi/config/config_test.go` (2,172 lines)

Step 4: Delete Legacy PGPass Code (~416 lines)

Delete entirely: `pkg/registryapi/pgpass.go` (77 lines)
Delete entirely: `pkg/registryapi/pgpass_test.go` (339 lines)

Step 5: Simplify Manager (~110 lines deleted)

File: `pkg/registryapi/manager.go`

  • Delete `reconcileLegacyPath()`
  • Delete `ensureRegistryServerConfigConfigMap()`
  • Delete `getConfigMapName()`
  • Simplify `ReconcileAPIService()` — remove if/else branch, inline `reconcileNewPath` or rename to `reconcile()`
  • Remove `config` package import

File: `pkg/registryapi/manager_test.go` — delete legacy `TestReconcileAPIService` subtests, add new-path test

Step 6: Simplify Deployment (~760 lines deleted)

File: `pkg/registryapi/deployment.go`

  • Delete `ensureDeployment(ctx, mcpRegistry, configManager)` (legacy wrapper)
  • Delete `buildRegistryAPIDeployment()` (legacy builder)
  • Rename `ensureDeploymentNewPath` → `ensureDeployment`
  • Rename `buildRegistryAPIDeploymentNewPath` → `buildRegistryAPIDeployment`
  • Remove `config` package import

File: `pkg/registryapi/deployment_test.go` — delete `TestManagerBuildRegistryAPIDeployment` and `TestEnsureDeployment` legacy tests (~660 lines). Add renamed tests for new path builder.

Step 7: Remove Legacy PodTemplateSpec Options (~555 lines deleted)

File: `pkg/registryapi/podtemplatespec.go`

  • Delete `WithRegistrySourceMounts()`
  • Delete `WithGitAuthMount()`
  • Delete `WithPGPassMount()`
  • Delete `WithRegistryStorageMount()`

File: `pkg/registryapi/podtemplatespec_test.go` — delete `TestWithPGPassMount`, `TestWithGitAuthMount`, and `WithRegistrySourceMounts`/`WithRegistryStorageMount` subtests (~450 lines)

Step 8: Clean Up Legacy Constants (~48 lines)

File: `pkg/registryapi/types.go`

  • Delete `RegistryDataVolumeName`, `RegistryDataMountPath`, `gitAuthSecretsBasePath`

File: `pkg/registryapi/types_test.go` — delete `TestGetConfigMapName`, update `TestMCPRegistryHelperMethods` if `GetStorageName` is removed

Step 9: Simplify Controller Validation (~120 lines deleted)

File: `controllers/mcpregistry_controller.go`

  • Delete `validatePathExclusivity()` entirely (no mutual exclusivity to validate)
  • Simplify `validateNewPathSpec()` → rename to `validateSpec()`, remove ConfigYAML empty check (now required)
  • Move `validatePGPassSecretRef()` call into `validateSpec()` directly
  • Remove `nolint:staticcheck` directives

File: `controllers/mcpregistry_controller_test.go`

  • Delete mutual exclusivity test cases (8 cases)
  • Update `newMCPRegistryWithFinalizer` and all test fixtures to use `ConfigYAML` instead of `Sources`

Step 10: Rewrite Integration Tests (~1,200 deleted, ~800 rewritten)

Files: All files in `test-integration/mcp-registry/`

  • Rewrite `RegistryBuilder` in `registry_helpers.go` to build `ConfigYAML` YAML strings with optional `Volumes`/`VolumeMounts`
  • Rewrite `registryserver_config_test.go` to verify new-path config generation
  • Update fixtures in `registry_lifecycle_test.go`, `deployment_update_test.go`, `registry_server_rbac_test.go`
  • Keep path-agnostic helpers (`status_helpers.go`, `timing_helpers.go`, `configmap_helpers.go`)

Step 11: Delete Legacy Examples (14 files)

Delete from `examples/operator/mcp-registries/`:

  • `mcpregistry-advanced-filtering.yaml`
  • `mcpregistry-api-advanced.yaml`
  • `mcpregistry-api-basic.yaml`
  • `mcpregistry-api-external.yaml`
  • `mcpregistry-automatic-sync.yaml`
  • `mcpregistry-configmap.yaml`
  • `mcpregistry-enforcing.yaml`
  • `mcpregistry-git-commit.yaml`
  • `mcpregistry-git-private.yaml`
  • `mcpregistry-git-simple.yaml`
  • `mcpregistry-git-toolhive.yaml`
  • `mcpregistry-minimal.yaml`
  • `mcpregistry-multiple-configmap.yaml`
  • `mcpregistry-tag-filtering.yaml`

Keep new-path examples (`mcpregistry-configyaml-*.yaml`).

Step 12: Final Verification

task operator-generate        # Regenerate deepcopy
task operator-manifests       # Regenerate CRD YAML
task crdref-gen               # Regenerate API docs (from repo root)
go build ./cmd/thv-operator/...
task lint
task operator-test            # Unit tests
task operator-test-integration # Integration tests (envtest)
task license-check            # SPDX headers

Verify no `nolint:staticcheck` directives remain for deprecated fields.

Risk Areas

  1. `GetStorageName()` in `image_validation.go` — used outside registryapi package at `pkg/validation/image_validation.go:206`. Must investigate if the storage ConfigMap pattern is still relevant in the new path. If not, remove; if yes, keep or adapt.

  2. Breaking CRD change — existing MCPRegistry resources with legacy fields become invalid after the schema change. Document migration path in release notes.

  3. Orphaned pgpass secrets — legacy deployments created pgpass secrets owned by MCPRegistry. After removal, the operator won't manage them. Document manual cleanup: `kubectl delete secret -l app.kubernetes.io/managed-by=toolhive-operator -l app.kubernetes.io/component=registry-api --field-selector type=Opaque`

  4. Integration test rewrite — largest effort (~1,200 lines). The `RegistryBuilder` needs a complete rewrite to construct `configYAML` YAML strings instead of typed Go structs.

  5. Config package near-empty — after removal, `config/config.go` has only two constants. Consider merging into `raw_config.go`.

  6. Deepcopy build ordering — code won't compile until BOTH types are deleted AND deepcopy is regenerated. Steps 1 and 2 must happen atomically.

Estimated Impact

Category Lines Deleted Lines Added
CRD types ~600 ~15
Config package ~3,300 ~5
Legacy pgpass ~416 0
Deployment + manager ~210 ~80
PodTemplateSpec ~555 0
Types/constants ~48 0
Controller + tests ~120 ~50
Unit tests ~1,265 ~110
Integration tests ~1,200 ~800
Legacy examples ~14 files 0
Total ~7,200 ~1,060

Net reduction: ~6,100 lines

Activity

  1. added
    enhancement
    on Apr 9, 2026
  2. added
    go
    kubernetes
    api
    on Apr 9, 2026
  3. added 2 commits that reference this issue on Apr 9, 2026
    e8ecf6a
    f430124
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

    apienhancementgokubernetesoperator

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions