Skip to content

K8SPSMDB-1610 handle user updates when no changes happen#2435

Merged
hors merged 7 commits into
mainfrom
K8SPSMDB-1610-manage-user-updates-optimally
Jul 7, 2026
Merged

K8SPSMDB-1610 handle user updates when no changes happen#2435
hors merged 7 commits into
mainfrom
K8SPSMDB-1610-manage-user-updates-optimally

Conversation

@gkech

@gkech gkech commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

CHANGE DESCRIPTION

Problem:

Related issue: #2430

Cause:
Short explanation of the root cause of the issue if applicable.

Solution:
Short explanation of the solution we are providing with this PR.

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 6, 2026
@gkech gkech force-pushed the K8SPSMDB-1610-manage-user-updates-optimally branch from 917f07a to 04ee1d5 Compare July 6, 2026 10:59
Comment thread pkg/controller/perconaservermongodbclustersync/target_user.go Fixed
@gkech gkech marked this pull request as ready for review July 6, 2026 11:31
@gkech gkech requested a review from Copilot July 6, 2026 11:44

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 addresses ClusterSync reconcile behavior that was re-applying MongoDB updateUser password/role updates on every reconcile even when the target user was already converged, reducing unnecessary admin writes and avoiding transient update failures in steady state.

Changes:

  • Tracks the Secret’s password via a SHA-256 annotation to avoid no-op UpdateUserPass calls.
  • Compares MongoDB user roles against the desired roles (order-insensitive) and skips UpdateUserRoles when already matching.
  • Updates unit tests to cover steady-state no-op behavior, password-hash mismatch behavior, and role-order tolerance.

Reviewed changes

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

File Description
pkg/controller/perconaservermongodbclustersync/target_user.go Adds password-hash annotation logic and role comparison to skip no-op MongoDB user updates; updates secret handling to return the Secret object.
pkg/controller/perconaservermongodbclustersync/psmdb_clustersync_controller_test.go Expands tests for the new “no-op when converged” behavior and annotation/role drift scenarios.

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

Comment thread pkg/controller/perconaservermongodbclustersync/target_user.go Outdated
Comment thread pkg/controller/perconaservermongodbclustersync/target_user.go Outdated

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

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

Comment on lines +181 to 185
func passwordAnnotationMAC(data []byte) string {
mac := hmac.New(sha256.New, []byte(targetUserPasswordMACKey))
mac.Write(data)
return hex.EncodeToString(mac.Sum(nil))
}
Comment on lines +31 to +33

targetUserPasswordMACAnnotation = "psmdb.percona.com/target-user-password-mac"
targetUserPasswordMACKey = "psmdb-target-user-password-annotation-v1"
Comment on lines 4 to +7
"context"
"crypto/hmac"
"crypto/sha256"
"encoding/hex"

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

// ref, kept its old password.
func ensureTargetMongoUser(ctx context.Context, mc mongo.Client, creds psmdb.Credentials) error {
existing, err := mc.GetUserInfo(ctx, creds.Username, "admin")
func ensureTargetMongoUser(ctx context.Context, mc mongo.Client, sec *corev1.Secret) (bool, error) {
@hors hors added this to the v1.23.0 milestone Jul 6, 2026
egegunes
egegunes previously approved these changes Jul 7, 2026
Comment thread pkg/controller/perconaservermongodbclustersync/target_user.go
Comment thread pkg/controller/perconaservermongodbclustersync/target_user.go
Comment thread pkg/controller/perconaservermongodbclustersync/target_user.go
targetUserSecretUsernameKey = "username"
targetUserSecretPasswordKey = "password"

admin = "admin"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we use a more descriptive name, like adminDBName

@gkech gkech requested a review from mayankshah1607 July 7, 2026 11:26
@JNKPercona

Copy link
Copy Markdown
Collaborator
Test Name Result Time
arbiter passed 00:00:00
balancer passed 00:00:00
cert-management-policy passed 00:00:00
clustersync passed 00:00:00
cross-site-sharded passed 00:00:00
custom-replset-name passed 00:00:00
custom-tls passed 00:00:00
custom-users-roles passed 00:00:00
custom-users-roles-sharded passed 00:00:00
data-at-rest-encryption passed 00:00:00
data-sharded passed 00:00:00
demand-backup passed 00:00:00
demand-backup-eks-credentials-irsa passed 00:00:00
demand-backup-fs passed 00:00:00
demand-backup-if-unhealthy passed 00:00:00
demand-backup-incremental-aws passed 00:00:00
demand-backup-incremental-azure passed 00:00:00
demand-backup-incremental-gcp-native passed 00:00:00
demand-backup-incremental-gcp-s3 passed 00:11:33
demand-backup-incremental-oss-s3 passed 00:00:00
demand-backup-incremental-oss-native passed 00:00:00
demand-backup-incremental-minio passed 00:00:00
demand-backup-incremental-sharded-aws passed 00:00:00
demand-backup-incremental-sharded-azure passed 00:00:00
demand-backup-incremental-sharded-gcp-native passed 00:00:00
demand-backup-incremental-sharded-gcp-s3 passed 00:00:00
demand-backup-incremental-sharded-oss-s3 passed 00:00:00
demand-backup-incremental-sharded-oss-native passed 00:00:00
demand-backup-incremental-sharded-minio passed 00:00:00
demand-backup-logical-minio-native-tls passed 00:00:00
demand-backup-physical-parallel passed 00:00:00
demand-backup-physical-aws passed 00:00:00
demand-backup-physical-azure passed 00:00:00
demand-backup-physical-gcp-s3 passed 00:00:00
demand-backup-gcs-workload-identity passed 00:00:00
demand-backup-physical-gcp-native passed 00:00:00
demand-backup-physical-oss-s3 passed 00:00:00
demand-backup-physical-oss-native passed 00:00:00
demand-backup-physical-minio passed 00:00:00
demand-backup-physical-minio-native passed 00:00:00
demand-backup-physical-minio-native-tls passed 00:00:00
demand-backup-physical-sharded-parallel passed 00:00:00
demand-backup-physical-sharded-aws passed 00:00:00
demand-backup-physical-sharded-azure passed 00:00:00
demand-backup-physical-sharded-gcp-native passed 00:00:00
demand-backup-physical-sharded-oss-s3 passed 00:00:00
demand-backup-physical-sharded-oss-native passed 00:00:00
demand-backup-physical-sharded-minio passed 00:00:00
demand-backup-physical-sharded-minio-native passed 00:00:00
demand-backup-sharded passed 00:00:00
demand-backup-snapshot passed 00:00:00
demand-backup-snapshot-vault passed 00:00:00
disabled-auth passed 00:00:00
expose-sharded passed 00:00:00
finalizer passed 00:00:00
ignore-labels-annotations passed 00:00:00
init-deploy passed 00:00:00
ldap passed 00:00:00
ldap-tls passed 00:00:00
limits passed 00:00:00
liveness passed 00:00:00
mongod-major-upgrade passed 00:00:00
mongod-major-upgrade-sharded passed 00:00:00
monitoring-2-0 passed 00:00:00
monitoring-pmm3 passed 00:00:00
multi-cluster-service failure 00:15:07
multi-storage passed 00:00:00
non-voting-and-hidden passed 00:00:00
one-pod passed 00:00:00
operator-self-healing-chaos passed 00:00:00
pitr passed 00:00:00
pitr-physical passed 00:00:00
pitr-sharded passed 00:00:00
pitr-to-new-cluster passed 00:00:00
pitr-physical-backup-source passed 00:00:00
preinit-updates passed 00:00:00
pvc-auto-resize passed 00:00:00
pvc-resize passed 00:00:00
recover-no-primary passed 00:00:00
replset-overrides passed 00:00:00
replset-remapping passed 00:00:00
replset-remapping-sharded passed 00:00:00
rs-shard-migration passed 00:00:00
scaling passed 00:00:00
scheduled-backup passed 00:00:00
security-context passed 00:00:00
self-healing-chaos passed 00:00:00
service-per-pod passed 00:00:00
serviceless-external-nodes passed 00:00:00
smart-update passed 00:00:00
split-horizon passed 00:00:00
split-horizon-manual-tls passed 00:00:00
stable-resource-version passed 00:00:00
storage passed 00:00:00
tls-clusterissuer-cert-manager passed 00:00:00
tls-issue-cert-manager passed 00:00:00
unsafe-psa passed 00:00:00
upgrade passed 00:00:00
upgrade-consistency passed 00:00:00
upgrade-consistency-sharded-tls passed 00:00:00
upgrade-sharded passed 00:00:00
upgrade-partial-backup passed 00:00:00
users passed 00:00:00
users-vault passed 00:00:00
vector-search passed 00:00:00
vector-search-sharded passed 00:00:00
version-service passed 00:00:00
Summary Value
Tests Run 107/107
Job Duration 00:55:53
Total Test Time 00:26:41

commit: 6101778
image: perconalab/percona-server-mongodb-operator:PR-2435-6101778cd

@hors hors merged commit 1911189 into main Jul 7, 2026
16 checks passed
@hors hors deleted the K8SPSMDB-1610-manage-user-updates-optimally branch July 7, 2026 19:38
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.

7 participants