Skip to content

K8SPSMDB-1537: connection string secret fixes#2442

Draft
pooknull wants to merge 2 commits into
mainfrom
K8SPSMDB-1537-fix
Draft

K8SPSMDB-1537: connection string secret fixes#2442
pooknull wants to merge 2 commits into
mainfrom
K8SPSMDB-1537-fix

Conversation

@pooknull

@pooknull pooknull commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

https://perconadev.atlassian.net/browse/K8SPSMDB-1537

DESCRIPTION

This PR fixes internal mongos connection strings when LoadBalancer service type is used.

Previously, internal connection strings used the service ClusterIP for LoadBalancer services:

<user>_mongos_connectionString: mongodb://<user>:<password>@10.0.0.20:27017/?authSource=<auth-db>

With this change, internal mongos connection strings now use FQDNs instead:

<user>_mongos_connectionString: mongodb://<user>:<password>@cluster-mongos.database.svc.cluster.local:27017/?authSource=<auth-db>

This PR also changes connection string secret owner references to point to the cluster instead of the user secret, so the secrets are removed when the cluster is deleted. It makes more sense because connection string secret after the cluster was deleted could remain with outdated connection strings.

Also, connection string generation now skips terminating pods, preventing generated connection strings from containing pods that are being removed.

CHECKLIST

Jira

  • Is the Jira ticket created and referenced properly?
  • Does the Jira ticket have the proper statuses for documentation (Needs Doc) and QA (Needs QA)?
  • Does the Jira ticket link to the proper milestone (Fix Version field)?

Tests

  • Is an E2E test/test case added for the new feature/change?
  • Are unit tests added where appropriate?
  • Are OpenShift compare files changed for E2E tests (compare/*-oc.yml)?

Config/Logging/Testability

  • Are all needed new/changed options added to default YAML files?
  • Are all needed new/changed options added to the Helm Chart?
  • Did we add proper logging messages for operator actions?
  • Did we ensure compatibility with the previous version or cluster upgrade process?
  • Does the change support oldest and newest supported MongoDB version?
  • Does the change support oldest and newest supported Kubernetes version?

@pull-request-size pull-request-size Bot added the size/L 100-499 lines label Jul 8, 2026

Copilot AI left a comment

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.

Pull request overview

This PR updates how the operator builds MongoDB connection strings and manages the lifecycle of the generated connection-string Secrets, primarily improving correctness for LoadBalancer mongos services and avoiding references to terminating pods.

Changes:

  • Use mongos Service FQDNs for internal connection strings when mongos is exposed via LoadBalancer (instead of using Service ClusterIP).
  • Skip terminating (DeletionTimestamp != nil) replset and mongos pods when generating host lists for connection strings.
  • Set connection-string Secret owner references to the PerconaServerMongoDB CR (instead of the system users Secret), so they are removed with cluster deletion; update tests accordingly.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/psmdb/service.go Adjust mongos internal host resolution for LoadBalancer; skip terminating pods when building replset/mongos address lists.
pkg/psmdb/service_test.go Update MongosHost unit tests to expect FQDN for internal LB addressing.
pkg/psmdb/client_test.go Add tests ensuring terminating pods are skipped in generated replset/mongos URIs; update LB-internal expectation to FQDN.
pkg/controller/perconaservermongodb/users.go Update call-site for connection-string Secret creation after signature/ownership change.
pkg/controller/perconaservermongodb/secrets.go Change connection-string Secret owner reference to the cluster CR.
pkg/controller/perconaservermongodb/secrets_test.go Update expected mongos connection string values and owner-reference assertions; minor formatting cleanup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/psmdb/service.go
Comment on lines 239 to +243
for _, pod := range pods {
if pod.DeletionTimestamp != nil {
continue
}

Comment thread pkg/psmdb/service.go
Comment on lines 270 to +274
for _, pod := range list.Items {
if pod.DeletionTimestamp != nil {
continue
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L 100-499 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants