You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Tomasz discovered this during the review of #621 and would like to get clarity before we decide on any code change.
The connection string the Kubernetes discovery feature builds for discovered DocumentDB targets sets bothdirectConnection=trueandreplicaSet=rs0, where rs0 is a hardcoded magic string. This raises a few open questions we want answered before touching code.
⚠️ Everything in the "Initial AI assessment" section below is an initial AI assessment generated during the review — it is context to investigate and confirm, not established fact. Please validate it (especially with the DocumentDB engine team) rather than treating it as ground truth.
Desired outcome of this issue
Clarity on the connection path — direct connection vs. replica set. Which is correct for Kubernetes-discovered targets, why, and should the user be allowed to choose between them (e.g. a toggle / setting / per-connection option) rather than us picking one unconditionally?
How to handle rs0 as a magic string. What should happen when it is incorrect (a deployment whose replica-set name is not rs0)? Options to weigh: drop it entirely, make it configurable, detect it, or rely on directConnection making it inert.
What does the DocumentDB engine team tell us about the behavior in general and about typical deployments — default replica-set naming, whether single-node deployments are advertised as a replica set, and how the driver treats directConnection=true combined with replicaSet.
➡️ Only once these questions are clarified will we decide how (or whether) to address this in code. This issue is investigation-only; no implementation should land until the above is answered.
Initial AI assessment (to be validated — not authoritative)
Where it comes from
buildDocumentDbConnectionParams() in src/plugins/service-kubernetes/kubernetesClient.ts unconditionally sets:
These params are attached to every discovered target (DKO and generic) and to the auto-credential path.
Likely reasons rs0 is hardcoded (hypotheses)
It may be the DocumentDB Kubernetes Operator (DKO) default. DKO likely provisions the database as a single-node replica set named rs0 (the same rs0 convention MongoDB uses for a default RS), so hardcoding it would match the common case. Needs confirmation from the engine/operator team.
Discovery never connects to the database, so it cannot learn the real RS name. The feature only reads Kubernetes objects (Services, the DKO dbs CRD, Secrets); it deliberately avoids a DB round-trip (hello/rs.status()). So the actual replica-set name isn't available at discovery time, and the operator default is assumed.
It mirrors the canonical/ documented DocumentDB connection string used elsewhere (getting-started lab, DocumentDB Local): mongodb://…@127.0.0.1:10260/?directConnection=true&authMechanism=SCRAM-SHA-256&tls=true&tlsAllowInvalidCertificates=true&replicaSet=rs0
The tension worth confirming
directConnection=true and replicaSet=rs0 are semantically at odds:
directConnection=true is there for a real reason here: it pins the driver to the single reachable endpoint (the LoadBalancer/NodePort address, or 127.0.0.1:<localPort> for a port-forward). Without it, the driver would attempt replica-set discovery and try to reach members by their internal pod DNS names (…svc.cluster.local), which are unreachable from the user's machine.
replicaSet=rs0 asks for replica-set topology.
In the MongoDB driver these can conflict — some driver versions rejectdirectConnection=true combined with replicaSet, others ignorereplicaSet when directConnection wins. In practice, with directConnection=true the replicaSet value is probably inert, which may be why this has not surfaced as a bug despite looking contradictory. This driver behavior should be confirmed against the actual DocumentDB driver/version we ship.
Caveats of hardcoding (if confirmed)
A deployment with a non-default RS name makes rs0 wrong — though directConnection=true likely neutralizes it, so it may still connect.
It is a magic string with no named constant or comment explaining the rs0 convention, so it reads as arbitrary to a future maintainer.
Possible directions (do NOT implement yet — pending answers above)
Confirm whether the DocumentDB driver tolerates directConnection=true + replicaSet; if it's inert, consider dropping replicaSet for the discovery path.
If a replica-set path is genuinely needed for some deployments, consider letting the user choose direct vs. replica-set, and/or making the RS name configurable instead of hardcoded.
At minimum, extract rs0 / the param set into a documented constant explaining the convention.
Tomasz discovered this during the review of #621 and would like to get clarity before we decide on any code change.
The connection string the Kubernetes discovery feature builds for discovered DocumentDB targets sets both
directConnection=trueandreplicaSet=rs0, wherers0is a hardcoded magic string. This raises a few open questions we want answered before touching code.Desired outcome of this issue
rs0as a magic string. What should happen when it is incorrect (a deployment whose replica-set name is notrs0)? Options to weigh: drop it entirely, make it configurable, detect it, or rely ondirectConnectionmaking it inert.directConnection=truecombined withreplicaSet.➡️ Only once these questions are clarified will we decide how (or whether) to address this in code. This issue is investigation-only; no implementation should land until the above is answered.
Initial AI assessment (to be validated — not authoritative)
Where it comes from
buildDocumentDbConnectionParams()insrc/plugins/service-kubernetes/kubernetesClient.tsunconditionally sets:These params are attached to every discovered target (DKO and generic) and to the auto-credential path.
Likely reasons
rs0is hardcoded (hypotheses)rs0(the samers0convention MongoDB uses for a default RS), so hardcoding it would match the common case. Needs confirmation from the engine/operator team.dbsCRD, Secrets); it deliberately avoids a DB round-trip (hello/rs.status()). So the actual replica-set name isn't available at discovery time, and the operator default is assumed.mongodb://…@127.0.0.1:10260/?directConnection=true&authMechanism=SCRAM-SHA-256&tls=true&tlsAllowInvalidCertificates=true&replicaSet=rs0The tension worth confirming
directConnection=trueandreplicaSet=rs0are semantically at odds:directConnection=trueis there for a real reason here: it pins the driver to the single reachable endpoint (the LoadBalancer/NodePort address, or127.0.0.1:<localPort>for a port-forward). Without it, the driver would attempt replica-set discovery and try to reach members by their internal pod DNS names (…svc.cluster.local), which are unreachable from the user's machine.replicaSet=rs0asks for replica-set topology.In the MongoDB driver these can conflict — some driver versions reject
directConnection=truecombined withreplicaSet, others ignorereplicaSetwhendirectConnectionwins. In practice, withdirectConnection=truethereplicaSetvalue is probably inert, which may be why this has not surfaced as a bug despite looking contradictory. This driver behavior should be confirmed against the actual DocumentDB driver/version we ship.Caveats of hardcoding (if confirmed)
rs0wrong — thoughdirectConnection=truelikely neutralizes it, so it may still connect.rs0convention, so it reads as arbitrary to a future maintainer.Possible directions (do NOT implement yet — pending answers above)
directConnection=true+replicaSet; if it's inert, consider droppingreplicaSetfor the discovery path.rs0/ the param set into a documented constant explaining the convention.References
src/plugins/service-kubernetes/kubernetesClient.ts—buildDocumentDbConnectionParams()docs/ai-and-plans/PRs/621-kubernetes-discovery/pre-merge-code-review.md