ERA-66338: Add MongoDB HA (ReplicaSet) instance support - #246
Draft
sasikanthmasini wants to merge 1 commit into
Draft
ERA-66338: Add MongoDB HA (ReplicaSet) instance support#246sasikanthmasini wants to merge 1 commit into
sasikanthmasini wants to merge 1 commit into
Conversation
- Add MongoHAConfig type with ReplicaSetName, DeployArbiter, ArbiterComputeProfileId, ListenerPort fields - Add MongoDB field to InstanceHAConfig - Add arbiter to HA node type enum in CRD - Add MongoHAParamsValidator for webhook validation - Add IsMongoHA() method to Database adapter and interface - Add MongoHAConnectivityManager and MongoHAIPResolver - Add setupMongoHAConnectivity: creates headless Services/Endpoints per data node and a <db>-db-uri Secret with the full MongoDB connection URI - Update MongoDB provisioning request appender with HA-specific action arguments (cluster_name, cluster_description, listener_port) - Change db_user default from 'admin' to 'mongod' - Allow cluster_name and cluster_description in MongoDB additional arguments - Update RBAC to allow create/patch/update on secrets - Update go.mod/go.sum dependencies - Add tests for all new functionality Co-authored-by: sasikanthmasini <sasikanth.masini@nutanix.com>
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.
What this PR does / why we need it
This PR implements PR #244 — adds support for MongoDB HA (ReplicaSet) via the NDB Operator.
Changes
API (
api/v1alpha1)database_types.go: AddedMongoHAConfigstruct withReplicaSetName,ReplicaSetDescription,DeployArbiter,ArbiterComputeProfileId, andListenerPortfields. AddedMongoDB *MongoHAConfigtoInstanceHAConfig. ExtendednodeTypeenum with"arbiter".ha_validators.go: AddedMongoHAParamsValidatorfor webhook validation of MongoDB HA constraints (required mongodb config block, exactly one primary, arbiter consistency withdeployArbiter, node type restrictions).zz_generated.deepcopy.go: Added generatedDeepCopy/DeepCopyIntoforMongoHAConfig.Common
constants.go: AddedHA_MONGO_DEFAULT_LISTENER_PORT,HA_NODE_TYPE_ARBITER,HA_NODE_ROLE_MONGO_PRIMARY/SECONDARY/ARBITERconstants.common/util/additionalArguments.go: Allowedcluster_nameandcluster_descriptionas overridable MongoDB HA action arguments.NDB API (
ndb_api)interfaces.go: AddedIsMongoHA()toDatabaseInterfaceand MongoDB-specific fields (ReplicaSetName,DeployArbiter,ArbiterComputeProfileId,MongoListenerPort) toHAConfig.db_helpers.go: Added MongoDB HA provisioning request block (clustered=true, per-node properties with role/votes/priority, SLA cluster IDs). UpdatedMongoDbRequestAppenderwith HA-specific action arguments and changed defaultdb_userfromadmintomongod.Controller Adapters
controller_adapters/database.go: AddedIsMongoHA()method and wired MongoDB fields inGetInstanceHAConfig().Controllers
controllers/ha_connectivity.go: AddedMongoHAIPResolver(returns IPs of all data nodes, excludes arbiters) andMongoHAConnectivityManager(returnsniladditional services — MongoDB HA uses a URI secret instead of K8s Services).controllers/database_reconciler_helpers.go: AddedsetupMongoHAConnectivity(creates a headless Service + Endpoints per data node for CoreDNS resolution, then creates/updates a<db>-db-uriSecret with the MongoDB connection URI) andsetupMongoHeadlessService.controllers/database_controller.go: Updated RBAC annotation for secrets to includecreate;update;patch.Config
config/crd/bases/ndb.nutanix.com_databases.yaml: Addedmongodbblock andarbitertonodeTypeenum.config/rbac/role.yaml: Addedcreate,patch,updateverbs for secrets.Dependencies
go.mod/go.sumwith minor dependency bumps.How it works
MongoDB HA uses a Replica Set topology where:
The operator creates:
<database-name>-db-uriSecret containing the full MongoDB connection URI:mongodb://user:pass@vm1:27017,vm2:27017/dbname?replicaSet=rs0&authSource=adminApplications use this URI with a MongoDB driver that handles routing and automatic failover via SDAM.
Tests
TestMongoHAParamsValidator_Validate— 11 subtests covering all validation scenariosTestMongoHAConnectivityManager_*— registry, PrimaryPort, AdditionalServicesTestMongoHAIPResolver_*— registry, ResolveIPs (excludes arbiters, handles empty nodes)IsMongoHAmock and correcteddb_uservalue