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
Draft
Conversation
This was referenced Apr 30, 2026
Draft
Collaborator
Author
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
3 tasks
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.
d85b31c to
7598566
Compare
32ff0e7 to
1dfdcc0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Why this change is needed?
kubectl-mongodb migrateonly 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?
sharded_cluster_generator.goand 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.validateOneDeploymentPerProjectto allow exactly one sharded cluster, and addsvalidateEmbeddedConfigServerto 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).ClusterRoleConfigSrv/ClusterRoleShardSrvconstants and a Process.ClusterRole() accessor incontrollers/om/process.go, and treats sharding.clusterRole as an infrastructure-managed field so it is stripped from additionalMongodConfig.configServerNameOverrideand #shardNameOverridescomments 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.testdata/singlecluster/shardedcluster/for three scenarios (default config rs, split shard names, complex sharded with TLS+SCRAM+resource-name-override).vm_migration_generate_sharded_cluster.pyso the sharded path is exercised in CI.Proof of Work
Checklist
skip-changeloglabel if not needed