Skip to content

feat: add MongoDB Atlas support via system TLS and URI passthrough#1069

Open
drubinstein wants to merge 2 commits intoNVIDIA:mainfrom
reflectionai:david/external-mongo
Open

feat: add MongoDB Atlas support via system TLS and URI passthrough#1069
drubinstein wants to merge 2 commits intoNVIDIA:mainfrom
reflectionai:david/external-mongo

Conversation

@drubinstein
Copy link
Copy Markdown

@drubinstein drubinstein commented Mar 23, 2026

Adds MONGODB_USE_SYSTEM_TLS support so NVSentinel can connect to MongoDB Atlas (and any deployment using publicly trusted certificates) without requiring custom CA cert files mounted in pods.

Go changes:

  • New MONGODB_USE_SYSTEM_TLS env var: when true, uses x509.SystemCertPool() instead of loading CA certs from disk, skipping X.509 client auth
  • Added GetUseSystemTLS() to DatabaseConfig interface and all implementations
  • Wired UseSystemTLS through MongoDBConfig, NewMongoDBClient, and ConvertToMongoDBConfig

Helm changes:

  • configmap-datastore.yaml: supports global.datastore.connection.uri for direct URI passthrough (e.g. mongodb+srv://), emits MONGODB_USE_SYSTEM_TLS
  • values.yaml: documents uri, useSystemTLS, and uriSecretName options
  • All 6 datastore-consuming deployment templates: inject optional Secret via envFrom when global.datastore.uriSecretName is set, keeping passwords out of ConfigMaps

Usage with Atlas:
kubectl create secret generic nvsentinel-atlas-uri \ --from-literal=MONGODB_URI='mongodb+srv://user:pass@cluster.mongodb.net/' helm upgrade nvsentinel ... \ --set global.datastore.provider=mongodb \ --set global.datastore.connection.database=nvsentinel \ --set global.datastore.useSystemTLS=true \ --set global.datastore.uriSecretName=nvsentinel-atlas-uri

Summary

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 💥 Breaking change
  • 📚 Documentation
  • 🔧 Refactoring
  • 🔨 Build/CI

Component(s) Affected

  • Core Services
  • Documentation/CI
  • Fault Management
  • Health Monitors
  • Janitor
  • Other: ____________

Testing

  • Tests pass locally
  • Manual testing completed
  • No breaking changes (or documented)

Checklist

  • Self-review completed
  • Documentation updated (if needed)
  • Ready for review

Summary by CodeRabbit

  • New Features

    • Support for a full MongoDB connection URI and optional injection via Kubernetes Secret.
    • Option to use system-trusted TLS for MongoDB connections.
    • Deployments will conditionally require the configured datastore secret when a secret name is provided.
  • Documentation

    • Added commented Helm guidance for MongoDB URI, system TLS, and secret name.
  • Tests

    • Updated test mocks to include the system-TLS flag.

@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot bot commented Mar 23, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 23, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: bf101980-0343-424c-bee0-443e701d718b

📥 Commits

Reviewing files that changed from the base of the PR and between 1009494 and 46b3f45.

📒 Files selected for processing (1)
  • store-client/pkg/datastore/providers/mongodb/watcher/watch_store.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • store-client/pkg/datastore/providers/mongodb/watcher/watch_store.go

📝 Walkthrough

Walkthrough

Add conditional injection of a datastore URI Secret into multiple Helm Deployment envFrom entries, document MongoDB connection options in values, and propagate a new UseSystemTLS flag from env config through adapters into the MongoDB client/watcher to enable system-CA TLS selection.

Changes

Cohort / File(s) Summary
Helm Deployment Templates
distros/kubernetes/nvsentinel/charts/csp-health-monitor/templates/deployment.yaml, distros/kubernetes/nvsentinel/charts/event-exporter/templates/deployment.yaml, distros/kubernetes/nvsentinel/charts/fault-quarantine/templates/deployment.yaml, distros/kubernetes/nvsentinel/charts/fault-remediation/templates/deployment.yaml, distros/kubernetes/nvsentinel/charts/health-events-analyzer/templates/deployment.yaml, distros/kubernetes/nvsentinel/charts/node-drainer/templates/deployment.yaml
Conditionally add a required secretRef to container envFrom when global.datastore and global.datastore.uriSecretName are set.
Helm ConfigMap & Values
distros/kubernetes/nvsentinel/templates/configmap-datastore.yaml, distros/kubernetes/nvsentinel/values.yaml
For MongoDB provider, support direct connection.uri, add MONGODB_USE_SYSTEM_TLS key in ConfigMap and document connection.uri, useSystemTLS, and uriSecretName in values comments.
Database Config & Env Loader
store-client/pkg/config/env_loader.go
Add GetUseSystemTLS() bool to DatabaseConfig, add EnvMongoDBUseSystemTLS constant, store useSystemTLS in StandardDatabaseConfig, and initialize it from env.
Legacy Adapter
store-client/pkg/adapter/legacy_adapter.go
Implement GetUseSystemTLS() to read MONGODB_USE_SYSTEM_TLS using truthy parsing.
Config Propagation
store-client/pkg/client/convenience.go, store-client/pkg/client/mongodb_client.go
Propagate UseSystemTLS from DatabaseConfig into MongoDBConfig used by the MongoDB client.
MongoDB TLS Logic
store-client/pkg/datastore/providers/mongodb/watcher/watch_store.go
Add UseSystemTLS bool to MongoDBConfig; introduce constructSystemTLSConfig() and branch TLS construction to use system CA pool when UseSystemTLS is true; extract TLS/apply logic and preserve existing dynamic/static cert behavior otherwise.
Tests / Mocks
node-drainer/pkg/reconciler/reconciler_integration_test.go
Add GetUseSystemTLS() bool to mockDatabaseConfig returning false to satisfy the updated interface.

Sequence Diagram(s)

sequenceDiagram
  participant Helm as "Helm (templates)"
  participant K8s as "Kubernetes (Deployment/Pod)"
  participant App as "Application Container"
  participant StoreClient as "store-client (DatabaseConfig)"
  participant MongoWatcher as "MongoDB Watcher / Client"
  participant MongoDB as "MongoDB"

  Helm->>K8s: Render Deployment with envFrom (configMap + conditional secretRef)
  K8s->>App: Pod starts with env (MONGODB_URI, MONGODB_USE_SYSTEM_TLS)
  App->>StoreClient: Initialize DatabaseConfig (reads env vars)
  StoreClient->>MongoWatcher: NewMongoDBClient(..., UseSystemTLS)
  MongoWatcher->>MongoWatcher: constructMongoClientOptions -> branch on UseSystemTLS
  alt UseSystemTLS == true
    MongoWatcher->>MongoDB: Connect using system CA pool TLS (no client cert)
  else UseSystemTLS == false
    MongoWatcher->>MongoWatcher: build cert-based TLS (dynamic or static)
    MongoWatcher->>MongoDB: Connect using client-certificate TLS (MONGODB-X509 possible)
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • KaivalyaMDabhadkar

Poem

🐰 I nibble secrets, hop through configs bright,
I stitch TLS roots by the soft moonlight,
From helm to client the tiny pathways hum,
System trust wakes, connections come,
Hoppity-hop — secure and light!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main feature: adding MongoDB Atlas support via system TLS and URI passthrough, which directly corresponds to the PR's core objectives.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.11.3)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@distros/kubernetes/nvsentinel/templates/configmap-datastore.yaml`:
- Around line 84-88: The inline comment next to the MONGODB_URI block references
global.datastore.uriSecret but the templates actually use
.Values.global.datastore.uriSecretName; update the comment to reference
global.datastore.uriSecretName (or vice‑versa if you prefer renaming the Helm
value) so the comment matches the actual Helm value name used by the template
(.Values.global.datastore.connection.uri and
.Values.global.datastore.uriSecretName) and avoid confusion.

In `@distros/kubernetes/nvsentinel/values.yaml`:
- Line 37: The docs comment mistakenly references uriSecret while the actual
configuration key is uriSecretName; update the comment(s) in values.yaml to use
uriSecretName (and any example snippets) so they match the real key, and scan
the file for any other occurrences (e.g., the other instance noted) to ensure
all comments and examples consistently reference uriSecretName.

In `@store-client/pkg/client/mongodb_client.go`:
- Line 347: NewChangeStreamWatcher builds a separate mongoConfig that omits
dbConfig.GetUseSystemTLS(), causing mixed TLS behavior; update
NewChangeStreamWatcher to propagate UseSystemTLS from the provided dbConfig (or
NewMongoDBClient) into its local mongoConfig and ensure any logic that performs
certificate rotation/management is disabled when UseSystemTLS is true so system
CA paths are used consistently; look for NewMongoDBClient,
NewChangeStreamWatcher, and the local mongoConfig variable and add UseSystemTLS:
dbConfig.GetUseSystemTLS() (or equivalent) and guard cert-rotation calls behind
a !UseSystemTLS condition.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b5486c71-6048-4bae-9350-9d8c1161a7a7

📥 Commits

Reviewing files that changed from the base of the PR and between 943880f and ab8e294.

📒 Files selected for processing (14)
  • distros/kubernetes/nvsentinel/charts/csp-health-monitor/templates/deployment.yaml
  • distros/kubernetes/nvsentinel/charts/event-exporter/templates/deployment.yaml
  • distros/kubernetes/nvsentinel/charts/fault-quarantine/templates/deployment.yaml
  • distros/kubernetes/nvsentinel/charts/fault-remediation/templates/deployment.yaml
  • distros/kubernetes/nvsentinel/charts/health-events-analyzer/templates/deployment.yaml
  • distros/kubernetes/nvsentinel/charts/node-drainer/templates/deployment.yaml
  • distros/kubernetes/nvsentinel/templates/configmap-datastore.yaml
  • distros/kubernetes/nvsentinel/values.yaml
  • node-drainer/pkg/reconciler/reconciler_integration_test.go
  • store-client/pkg/adapter/legacy_adapter.go
  • store-client/pkg/client/convenience.go
  • store-client/pkg/client/mongodb_client.go
  • store-client/pkg/config/env_loader.go
  • store-client/pkg/datastore/providers/mongodb/watcher/watch_store.go

Comment on lines +84 to +88
{{- if .Values.global.datastore.connection.uri }}
# Direct URI provided (e.g. MongoDB Atlas mongodb+srv://...). Password should be
# supplied via global.datastore.uriSecret to avoid storing credentials in a ConfigMap.
MONGODB_URI: {{ .Values.global.datastore.connection.uri | quote }}
{{- else }}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Minor comment inconsistency: uriSecret vs uriSecretName.

The comment references global.datastore.uriSecret but the actual Helm value used in the deployment templates is global.datastore.uriSecretName. Consider updating for consistency.

-  # supplied via global.datastore.uriSecret to avoid storing credentials in a ConfigMap.
+  # supplied via global.datastore.uriSecretName to avoid storing credentials in a ConfigMap.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{{- if .Values.global.datastore.connection.uri }}
# Direct URI provided (e.g. MongoDB Atlas mongodb+srv://...). Password should be
# supplied via global.datastore.uriSecret to avoid storing credentials in a ConfigMap.
MONGODB_URI: {{ .Values.global.datastore.connection.uri | quote }}
{{- else }}
{{- if .Values.global.datastore.connection.uri }}
# Direct URI provided (e.g. MongoDB Atlas mongodb+srv://...). Password should be
# supplied via global.datastore.uriSecretName to avoid storing credentials in a ConfigMap.
MONGODB_URI: {{ .Values.global.datastore.connection.uri | quote }}
{{- else }}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@distros/kubernetes/nvsentinel/templates/configmap-datastore.yaml` around
lines 84 - 88, The inline comment next to the MONGODB_URI block references
global.datastore.uriSecret but the templates actually use
.Values.global.datastore.uriSecretName; update the comment to reference
global.datastore.uriSecretName (or vice‑versa if you prefer renaming the Helm
value) so the comment matches the actual Helm value name used by the template
(.Values.global.datastore.connection.uri and
.Values.global.datastore.uriSecretName) and avoid confusion.

#
# # MongoDB Atlas / external MongoDB: set uri directly instead of host/port.
# # The URI must include credentials. To avoid storing the password in a
# # ConfigMap, create a Secret and reference it via uriSecret below instead.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix the option name typo in the docs (uriSecret vs uriSecretName).

The comment references uriSecret, but the documented key is uriSecretName. This can cause user misconfiguration.

📝 Suggested doc fix
-  #   # ConfigMap, create a Secret and reference it via uriSecret below instead.
+  #   # ConfigMap, create a Secret and reference it via uriSecretName below instead.

Also applies to: 54-54

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@distros/kubernetes/nvsentinel/values.yaml` at line 37, The docs comment
mistakenly references uriSecret while the actual configuration key is
uriSecretName; update the comment(s) in values.yaml to use uriSecretName (and
any example snippets) so they match the real key, and scan the file for any
other occurrences (e.g., the other instance noted) to ensure all comments and
examples consistently reference uriSecretName.

ChangeStreamRetryDeadlineSeconds: dbConfig.GetTimeoutConfig().GetChangeStreamRetryDeadlineSeconds(),
ChangeStreamRetryIntervalSeconds: dbConfig.GetTimeoutConfig().GetChangeStreamRetryIntervalSeconds(),
AppName: dbConfig.GetAppName(),
UseSystemTLS: dbConfig.GetUseSystemTLS(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

UseSystemTLS is only wired for one MongoDB path, causing split TLS behavior.

NewMongoDBClient now forwards UseSystemTLS, but NewChangeStreamWatcher builds a separate mongoConfig without it. This can break Atlas/public-CA setups when change streams start. Also, cert rotation should be skipped when system TLS is enabled.

🔧 Suggested fix
 func NewMongoDBClient(ctx context.Context, dbConfig config.DatabaseConfig) (*MongoDBClient, error) {
+	useSystemTLS := dbConfig.GetUseSystemTLS()
+
 	// Convert to the existing MongoDBConfig format for backward compatibility
 	mongoConfig := mongoWatcher.MongoDBConfig{
@@
-		UseSystemTLS:                     dbConfig.GetUseSystemTLS(),
+		UseSystemTLS:                     useSystemTLS,
 	}
@@
-	if config.IsCertRotationEnabled() {
+	if config.IsCertRotationEnabled() && !useSystemTLS {
 		slog.Info("Certificate rotation enabled, initializing certificate watcher")
@@
 func (c *MongoDBClient) NewChangeStreamWatcher(ctx context.Context, tokenConfig TokenConfig,
 	pipeline interface{}) (ChangeStreamWatcher, error) {
@@
 	mongoConfig := mongoWatcher.MongoDBConfig{
@@
 		ChangeStreamRetryDeadlineSeconds: c.config.GetTimeoutConfig().GetChangeStreamRetryDeadlineSeconds(),
 		ChangeStreamRetryIntervalSeconds: c.config.GetTimeoutConfig().GetChangeStreamRetryIntervalSeconds(),
 		CertWatcher:                      c.certWatcher,
+		UseSystemTLS:                     c.config.GetUseSystemTLS(),
 	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@store-client/pkg/client/mongodb_client.go` at line 347,
NewChangeStreamWatcher builds a separate mongoConfig that omits
dbConfig.GetUseSystemTLS(), causing mixed TLS behavior; update
NewChangeStreamWatcher to propagate UseSystemTLS from the provided dbConfig (or
NewMongoDBClient) into its local mongoConfig and ensure any logic that performs
certificate rotation/management is disabled when UseSystemTLS is true so system
CA paths are used consistently; look for NewMongoDBClient,
NewChangeStreamWatcher, and the local mongoConfig variable and add UseSystemTLS:
dbConfig.GetUseSystemTLS() (or equivalent) and guard cert-rotation calls behind
a !UseSystemTLS condition.

Adds MONGODB_USE_SYSTEM_TLS support so NVSentinel can connect to MongoDB
Atlas (and any deployment using publicly trusted certificates) without
requiring custom CA cert files mounted in pods.

Go changes:
- New MONGODB_USE_SYSTEM_TLS env var: when true, uses x509.SystemCertPool()
  instead of loading CA certs from disk, skipping X.509 client auth
- Added GetUseSystemTLS() to DatabaseConfig interface and all implementations
- Wired UseSystemTLS through MongoDBConfig, NewMongoDBClient, and
  ConvertToMongoDBConfig

Helm changes:
- configmap-datastore.yaml: supports global.datastore.connection.uri for
  direct URI passthrough (e.g. mongodb+srv://), emits MONGODB_USE_SYSTEM_TLS
- values.yaml: documents uri, useSystemTLS, and uriSecretName options
- All 6 datastore-consuming deployment templates: inject optional Secret via
  envFrom when global.datastore.uriSecretName is set, keeping passwords out
  of ConfigMaps

Usage with Atlas:
  kubectl create secret generic nvsentinel-atlas-uri \
    --from-literal=MONGODB_URI='mongodb+srv://user:pass@cluster.mongodb.net/'
  helm upgrade nvsentinel ... \
    --set global.datastore.provider=mongodb \
    --set global.datastore.connection.database=nvsentinel \
    --set global.datastore.useSystemTLS=true \
    --set global.datastore.uriSecretName=nvsentinel-atlas-uri

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: David Rubinstein <david@reflection.ai>
@drubinstein drubinstein force-pushed the david/external-mongo branch from ab8e294 to 3439a4b Compare March 23, 2026 19:58
@lalitadithya
Copy link
Copy Markdown
Collaborator

/ok to test 3439a4b

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

♻️ Duplicate comments (1)
store-client/pkg/client/mongodb_client.go (1)

347-347: ⚠️ Potential issue | 🔴 Critical

Propagate UseSystemTLS consistently to change streams and skip cert rotation in system-TLS mode.

Line 347 wires UseSystemTLS only for one config path. NewChangeStreamWatcher still rebuilds a config without this flag, and cert rotation is still initialized when system TLS is enabled. That can cause split behavior/failures for Atlas-style setups without mounted cert/key files.

🔧 Proposed fix
 func NewMongoDBClient(ctx context.Context, dbConfig config.DatabaseConfig) (*MongoDBClient, error) {
+	useSystemTLS := dbConfig.GetUseSystemTLS()
+
 	// Convert to the existing MongoDBConfig format for backward compatibility
 	mongoConfig := mongoWatcher.MongoDBConfig{
@@
-		UseSystemTLS:                     dbConfig.GetUseSystemTLS(),
+		UseSystemTLS:                     useSystemTLS,
 	}
@@
-	if config.IsCertRotationEnabled() {
+	if config.IsCertRotationEnabled() && !useSystemTLS {
 		slog.Info("Certificate rotation enabled, initializing certificate watcher")
@@
 func (c *MongoDBClient) NewChangeStreamWatcher(ctx context.Context, tokenConfig TokenConfig,
 	pipeline interface{}) (ChangeStreamWatcher, error) {
@@
 	mongoConfig := mongoWatcher.MongoDBConfig{
@@
 		ChangeStreamRetryDeadlineSeconds: c.config.GetTimeoutConfig().GetChangeStreamRetryDeadlineSeconds(),
 		ChangeStreamRetryIntervalSeconds: c.config.GetTimeoutConfig().GetChangeStreamRetryIntervalSeconds(),
 		CertWatcher:                      c.certWatcher,
+		UseSystemTLS:                     c.config.GetUseSystemTLS(),
 	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@store-client/pkg/client/mongodb_client.go` at line 347, The UseSystemTLS flag
is only set on one config path causing NewChangeStreamWatcher to rebuild a
config without it and the certificate-rotation path to run even when system TLS
is enabled; update NewChangeStreamWatcher and any code that constructs a new db
config for change streams to copy dbConfig.GetUseSystemTLS() into the rebuilt
config (the same config key used on line where UseSystemTLS is currently set)
and modify the cert-rotation initialization (the function that
starts/initializes rotation) to no-op when UseSystemTLS is true so cert/key
rotation is skipped for system-TLS setups.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@store-client/pkg/adapter/legacy_adapter.go`:
- Around line 147-149: Add a Go doc comment for the exported method
GetUseSystemTLS on LegacyDatabaseConfigAdapter: a one-line comment that starts
with "GetUseSystemTLS" and briefly explains that the method returns whether
system TLS should be used (reads the environment variable
config.EnvMongoDBUseSystemTLS and interprets it via stringutil.IsTruthyValue),
and mention the bool return for clarity; place the comment immediately above the
GetUseSystemTLS method declaration.

In `@store-client/pkg/config/env_loader.go`:
- Around line 515-517: Add a concise Go doc comment for the exported method
GetUseSystemTLS on type StandardDatabaseConfig: place a comment immediately
above the method that begins with "GetUseSystemTLS" and briefly describes what
it returns (e.g., whether the database connection should use system TLS
certificates), mentioning the receiver type StandardDatabaseConfig if helpful;
update the comment to follow Go doc conventions (full sentence, starts with the
method name).

---

Duplicate comments:
In `@store-client/pkg/client/mongodb_client.go`:
- Line 347: The UseSystemTLS flag is only set on one config path causing
NewChangeStreamWatcher to rebuild a config without it and the
certificate-rotation path to run even when system TLS is enabled; update
NewChangeStreamWatcher and any code that constructs a new db config for change
streams to copy dbConfig.GetUseSystemTLS() into the rebuilt config (the same
config key used on line where UseSystemTLS is currently set) and modify the
cert-rotation initialization (the function that starts/initializes rotation) to
no-op when UseSystemTLS is true so cert/key rotation is skipped for system-TLS
setups.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9803dec3-4740-4e63-9eae-ea22eee710f0

📥 Commits

Reviewing files that changed from the base of the PR and between ab8e294 and 3439a4b.

📒 Files selected for processing (14)
  • distros/kubernetes/nvsentinel/charts/csp-health-monitor/templates/deployment.yaml
  • distros/kubernetes/nvsentinel/charts/event-exporter/templates/deployment.yaml
  • distros/kubernetes/nvsentinel/charts/fault-quarantine/templates/deployment.yaml
  • distros/kubernetes/nvsentinel/charts/fault-remediation/templates/deployment.yaml
  • distros/kubernetes/nvsentinel/charts/health-events-analyzer/templates/deployment.yaml
  • distros/kubernetes/nvsentinel/charts/node-drainer/templates/deployment.yaml
  • distros/kubernetes/nvsentinel/templates/configmap-datastore.yaml
  • distros/kubernetes/nvsentinel/values.yaml
  • node-drainer/pkg/reconciler/reconciler_integration_test.go
  • store-client/pkg/adapter/legacy_adapter.go
  • store-client/pkg/client/convenience.go
  • store-client/pkg/client/mongodb_client.go
  • store-client/pkg/config/env_loader.go
  • store-client/pkg/datastore/providers/mongodb/watcher/watch_store.go
✅ Files skipped from review due to trivial changes (4)
  • distros/kubernetes/nvsentinel/values.yaml
  • distros/kubernetes/nvsentinel/charts/event-exporter/templates/deployment.yaml
  • distros/kubernetes/nvsentinel/charts/csp-health-monitor/templates/deployment.yaml
  • distros/kubernetes/nvsentinel/templates/configmap-datastore.yaml
🚧 Files skipped from review as they are similar to previous changes (4)
  • store-client/pkg/client/convenience.go
  • distros/kubernetes/nvsentinel/charts/health-events-analyzer/templates/deployment.yaml
  • node-drainer/pkg/reconciler/reconciler_integration_test.go
  • distros/kubernetes/nvsentinel/charts/node-drainer/templates/deployment.yaml

Comment on lines +147 to +149
func (l *LegacyDatabaseConfigAdapter) GetUseSystemTLS() bool {
return stringutil.IsTruthyValue(os.Getenv(config.EnvMongoDBUseSystemTLS))
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Add a doc comment for exported method GetUseSystemTLS.

Line 147 introduces an exported method without a Go doc comment.

✏️ Suggested doc comment
+// GetUseSystemTLS returns true when MongoDB should use the system CA trust store.
 func (l *LegacyDatabaseConfigAdapter) GetUseSystemTLS() bool {
 	return stringutil.IsTruthyValue(os.Getenv(config.EnvMongoDBUseSystemTLS))
 }

As per coding guidelines: "Function comments required for all exported Go functions".

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func (l *LegacyDatabaseConfigAdapter) GetUseSystemTLS() bool {
return stringutil.IsTruthyValue(os.Getenv(config.EnvMongoDBUseSystemTLS))
}
// GetUseSystemTLS returns true when MongoDB should use the system CA trust store.
func (l *LegacyDatabaseConfigAdapter) GetUseSystemTLS() bool {
return stringutil.IsTruthyValue(os.Getenv(config.EnvMongoDBUseSystemTLS))
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@store-client/pkg/adapter/legacy_adapter.go` around lines 147 - 149, Add a Go
doc comment for the exported method GetUseSystemTLS on
LegacyDatabaseConfigAdapter: a one-line comment that starts with
"GetUseSystemTLS" and briefly explains that the method returns whether system
TLS should be used (reads the environment variable config.EnvMongoDBUseSystemTLS
and interprets it via stringutil.IsTruthyValue), and mention the bool return for
clarity; place the comment immediately above the GetUseSystemTLS method
declaration.

Comment on lines +515 to +517
func (c *StandardDatabaseConfig) GetUseSystemTLS() bool {
return c.useSystemTLS
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Add a doc comment for exported method GetUseSystemTLS.

Line 515 adds an exported getter without a Go doc comment.

✏️ Suggested doc comment
+// GetUseSystemTLS returns whether system CA trust should be used for MongoDB TLS.
 func (c *StandardDatabaseConfig) GetUseSystemTLS() bool {
 	return c.useSystemTLS
 }

As per coding guidelines: "Function comments required for all exported Go functions".

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func (c *StandardDatabaseConfig) GetUseSystemTLS() bool {
return c.useSystemTLS
}
// GetUseSystemTLS returns whether system CA trust should be used for MongoDB TLS.
func (c *StandardDatabaseConfig) GetUseSystemTLS() bool {
return c.useSystemTLS
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@store-client/pkg/config/env_loader.go` around lines 515 - 517, Add a concise
Go doc comment for the exported method GetUseSystemTLS on type
StandardDatabaseConfig: place a comment immediately above the method that begins
with "GetUseSystemTLS" and briefly describes what it returns (e.g., whether the
database connection should use system TLS certificates), mentioning the receiver
type StandardDatabaseConfig if helpful; update the comment to follow Go doc
conventions (full sentence, starts with the method name).

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
store-client/pkg/datastore/providers/mongodb/watcher/watch_store.go (1)

613-631: Wrap TLS branch errors with explicit context.

These branches return raw errors, which makes failure origin harder to identify in logs and call chains.

🔧 Suggested change
 	switch {
 	case mongoConfig.UseSystemTLS:
 		// Use the system CA trust store — no cert files required.
 		// Credentials (e.g. SCRAM username/password) are encoded in the URI.
 		tlsConfig, err = constructSystemTLSConfig()
 		if err != nil {
-			return nil, err
+			return nil, fmt.Errorf("construct system TLS config: %w", err)
 		}
 	case mongoConfig.CertWatcher != nil:
 		// Dynamic TLS with automatic client certificate rotation.
 		tlsConfig, err = constructDynamicTLSConfig(mongoConfig)
 		if err != nil {
-			return nil, err
+			return nil, fmt.Errorf("construct dynamic TLS config: %w", err)
 		}
 	default:
 		// Static TLS loaded from cert files on disk.
 		tlsConfig, err = constructStaticTLSConfig(mongoConfig)
 		if err != nil {
-			return nil, err
+			return nil, fmt.Errorf("construct static TLS config: %w", err)
 		}
 	}

As per coding guidelines, "Wrap errors with context using fmt.Errorf("context: %w", err) in Go code".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@store-client/pkg/datastore/providers/mongodb/watcher/watch_store.go` around
lines 613 - 631, The error returns from the TLS selection branches should be
wrapped with contextual messages; update the cases that call
constructSystemTLSConfig, constructDynamicTLSConfig, and
constructStaticTLSConfig inside the switch on mongoConfig (including the
mongoConfig.UseSystemTLS and mongoConfig.CertWatcher branches) to return
fmt.Errorf with context (e.g., "constructSystemTLSConfig failed: %w") instead of
returning the raw err so callers can identify which TLS path failed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@store-client/pkg/datastore/providers/mongodb/watcher/watch_store.go`:
- Around line 613-631: The error returns from the TLS selection branches should
be wrapped with contextual messages; update the cases that call
constructSystemTLSConfig, constructDynamicTLSConfig, and
constructStaticTLSConfig inside the switch on mongoConfig (including the
mongoConfig.UseSystemTLS and mongoConfig.CertWatcher branches) to return
fmt.Errorf with context (e.g., "constructSystemTLSConfig failed: %w") instead of
returning the raw err so callers can identify which TLS path failed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 30440fdc-9791-473a-8556-5ad7902f5ec6

📥 Commits

Reviewing files that changed from the base of the PR and between 3439a4b and 1009494.

📒 Files selected for processing (1)
  • store-client/pkg/datastore/providers/mongodb/watcher/watch_store.go

Signed-off-by: David Rubinstein <david@reflection.ai>
@drubinstein drubinstein force-pushed the david/external-mongo branch from 1009494 to 46b3f45 Compare March 23, 2026 20:20
@lalitadithya
Copy link
Copy Markdown
Collaborator

/ok to test 46b3f45

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.

2 participants