Skip to content

feat: sharded cluster support in kubectl-mongodb migrate#1043

Draft
filipcirtog wants to merge 3 commits into04-07-test_e2e_tests_and_evergreen_ci_for_vm_migrationfrom
04-29-feat_sharded_cluster_support_for_import_tool
Draft

feat: sharded cluster support in kubectl-mongodb migrate#1043
filipcirtog wants to merge 3 commits into04-07-test_e2e_tests_and_evergreen_ci_for_vm_migrationfrom
04-29-feat_sharded_cluster_support_for_import_tool

Conversation

@filipcirtog
Copy link
Copy Markdown
Collaborator

@filipcirtog filipcirtog commented Apr 30, 2026

Why this change is needed?

kubectl-mongodb migrate only supported replica sets. This PR closes that gap so a sharded VM deployment can be migrated end-to-end with the same workflow.

What this PR does?

  • Adds sharded_cluster_generator.go and dispatches to it from GenerateMongoDBCR when the Automation Config contains a sharded cluster. Output uses spec.type: ShardedCluster with shard, mongos, and config-server topology derived from the AC.
  • Loosens validateOneDeploymentPerProject to allow exactly one sharded cluster, and adds validateEmbeddedConfigServer to reject the unsupported case where a shard's replica set doubles as the config server (detected via either configServerReplica or sharding.clusterRole = configsvr on a process).
  • Adds ClusterRoleConfigSrv/ClusterRoleShardSrvconstants and a Process.ClusterRole() accessor in controllers/om/process.go, and treats sharding.clusterRole as an infrastructure-managed field so it is stripped from additionalMongodConfig.
  • Splices # configServerNameOverride and # shardNameOverrides comments into the produced YAML via a yamlCommentCarrier wrapper, so users can opt in once the CRD supports those fields. The TODO points at the cleanup.
  • Adds test fixtures under testdata/singlecluster/shardedcluster/ for three scenarios (default config rs, split shard names, complex sharded with TLS+SCRAM+resource-name-override).
  • Adds an e2e test vm_migration_generate_sharded_cluster.py so the sharded path is exercised in CI.

Proof of Work

Checklist

  • Have you linked a jira ticket and/or is the ticket in the title?
  • Have you checked whether your jira ticket required DOCSP changes?
  • Have you added changelog file?

Copy link
Copy Markdown
Collaborator Author

filipcirtog commented Apr 30, 2026

Lifts the previous "sharded cluster not yet supported" error from the
import tool. The generator now produces a MongoDB CR with type
ShardedCluster, populated externalMembers (config server, shards,
mongos), shard counts, and commented out configServerNameOverride and
shardNameOverrides blocks until the CRD adds those fields.

Adds two new validators: rejects multi-sharded-cluster projects (and
extra unrelated replica sets in a single-sharded project) and rejects
embedded config servers (detected via configServerReplica colliding
with a shard rs, or a process declaring sharding.clusterRole =
configsvr inside a shard rs).

In controllers/om: exports Shards/Id/Rs/ReplicaSetName, adds
ClusterRole and Port accessors and ClusterRoleConfigSrv/ShardSrv
constants, factors ExtractMemberInfo into ExtractExternalMembers so
the mongos path can reuse it, and strips args2_6.sharding.clusterRole
from AdditionalMongodConfig so the role does not leak into the CR.
Adds three sharded-cluster fixture cases (default config rs name,
split shard names, complex with TLS+SCRAM+resource-name-override) and
unit tests around the sharded-cluster generator: resource-name
override, topology counts, missing shard replica set, and the
configServerNameOverride helper. Refactors the existing fixture table
into a shared fixtureCase struct so replica-set and sharded-cluster
cases share one runner.

Adds validation tests covering: a single sharded cluster passes,
extra replica sets next to a sharded cluster are rejected, multiple
sharded clusters are rejected, and the embedded-config-server check
fires for both the configServerReplica-collision and
process-clusterRole-configsvr signals.

Also adapts existing om tests to the renamed (now-exported) Shards,
Id, Rs, ReplicaSetName accessors.
Mirrors the no-auth replica-set VM migration scenario but stands up a
sharded cluster on the VM StatefulSet (config server, shards, mongos)
and verifies kubectl-mongodb migrate produces a CR with the expected
type, topology counts, and externalMembers. The promote-and-prune
step is gated behind pytest.mark.skip until the operator supports VM
migrations for sharded clusters.

Extends deploy_vm_statefulset with an optional replicas override and
adds promote_and_prune_sharded as a placeholder helper that documents
the safe extension order (config server, shards, mongos) for the
forthcoming operator-side work.
@filipcirtog filipcirtog force-pushed the 04-07-test_e2e_tests_and_evergreen_ci_for_vm_migration branch from d85b31c to 7598566 Compare April 30, 2026 09:35
@filipcirtog filipcirtog force-pushed the 04-29-feat_sharded_cluster_support_for_import_tool branch from 32ff0e7 to 1dfdcc0 Compare April 30, 2026 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant