Skip to content

Commit 9479e53

Browse files
m1kolafealebenpae
authored andcommitted
CLOUDP-294917: Fix MongoDBUser status being updated prematurely (#4093)
We now wait for automation state to indicate that the processes have reached the goal state before updating MongoDBUser to indicate "Updated" status.
1 parent cdc2dc0 commit 9479e53

File tree

7 files changed

+73
-20
lines changed

7 files changed

+73
-20
lines changed

RELEASE_NOTES.md

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
[//]: # (Consider renaming or removing the header for next release, otherwise it appears as duplicate in the published release, e.g: https://github.com/mongodb/mongodb-enterprise-kubernetes/releases/tag/1.22.0 )
22
<!-- Next Release -->
3+
# MongoDB Enterprise Kubernetes Operator 1.32.0
4+
5+
## Bug Fixes
6+
* Fixes the bug when status of `MongoDBUser` was being set to `Updated` prematurely. For example, new users were not immediately usable following `MongoDBUser` creation despite the operator reporting `Updated` state.
7+
8+
<!-- Past releases -->
9+
310
# MongoDB Enterprise Kubernetes Operator 1.31.0
411

512
## Kubernetes versions
@@ -14,7 +21,7 @@
1421
## New Features
1522

1623
* **MongoDB**: fixes and improvements to Multi-Cluster Sharded Cluster deployments (Public Preview)
17-
* **MongoDB**: `spec.shardOverrides` field, which was added in 1.28.0 as part of Multi-Cluster Sharded Cluster Public Preview is now fully supported for single-cluster topologies and is the recommended way of customizing settings for specific shards.
24+
* **MongoDB**: `spec.shardOverrides` field, which was added in 1.28.0 as part of Multi-Cluster Sharded Cluster Public Preview is now fully supported for single-cluster topologies and is the recommended way of customizing settings for specific shards.
1825
* **MongoDB**: `spec.shardSpecificPodSpec` was deprecated. The recommended way of customizing specific shard settings is to use `spec.shardOverrides` for both Single and Multi Cluster topology. An example of how to migrate the settings to spec.shardOverrides is available [here](https://github.com/mongodb/mongodb-enterprise-kubernetes/blob/master/samples/sharded_multicluster/shardSpecificPodSpec_migration.yaml).
1926

2027
## Bug Fixes
@@ -24,8 +31,6 @@
2431
## Kubernetes versions
2532
* The minimum supported Kubernetes version for this operator is 1.29 and OpenShift 4.17.
2633

27-
<!-- Past Releases -->
28-
2934
# MongoDB Enterprise Kubernetes Operator 1.29.0
3035

3136
## New Features
@@ -40,12 +45,12 @@
4045

4146
## New Features
4247

43-
* **MongoDB**: public preview release of multi kubernetes cluster support for sharded clusters. This can be enabled by setting `spec.topology=MultiCluster` when creating `MongoDB` resource of `spec.type=ShardedCluster`. More details can be found [here](https://www.mongodb.com/docs/kubernetes-operator/master/multi-cluster-sharded-cluster/).
48+
* **MongoDB**: public preview release of multi kubernetes cluster support for sharded clusters. This can be enabled by setting `spec.topology=MultiCluster` when creating `MongoDB` resource of `spec.type=ShardedCluster`. More details can be found [here](https://www.mongodb.com/docs/kubernetes-operator/master/multi-cluster-sharded-cluster/).
4449
* **MongoDB**, **MongoDBMultiCluster**: support for automated expansion of the PVC.
4550
More details can be found [here](https://www.mongodb.com/docs/kubernetes-operator/upcoming/tutorial/resize-pv-storage/).
4651
**Note**: Expansion of the pvc is only supported if the storageClass supports expansion.
4752
Please ensure that the storageClass supports in-place expansion without data-loss.
48-
* **MongoDB** This can be done by increasing the size of the PVC in the CRD setting:
53+
* **MongoDB** This can be done by increasing the size of the PVC in the CRD setting:
4954
* one PVC - increase: `spec.persistence.single.storage`
5055
* multiple PVCs - increase: `spec.persistence.multiple.(data/journal/logs).storage`
5156
* **MongoDBMulti** This can be done by increasing the storage via the statefulset override:
@@ -61,7 +66,7 @@
6166
storage: 2Gi # this is my increased storage
6267
storageClass: <my-class-that-supports-expansion>
6368
```
64-
* **MongoDB**, **MongoDBMultiCluster** **AppDB**: change default behaviour of setting featurecompatibilityversion (fcv) for the database.
69+
* **MongoDB**, **MongoDBMultiCluster** **AppDB**: change default behaviour of setting featurecompatibilityversion (fcv) for the database.
6570
* When upgrading mongoDB version the operator sets the FCV to the prior version we are upgrading from. This allows to
6671
have sanity checks before setting the fcv to the upgraded version. More information can be found [here](https://www.mongodb.com/docs/kubernetes-operator/current/reference/k8s-operator-specification/#mongodb-setting-spec.featureCompatibilityVersion).
6772
* To keep the prior behaviour to always use the mongoDB version as FCV; set `spec.featureCompatibilityVersion: "AlwaysMatchVersion"`
@@ -78,7 +83,7 @@ For a full `ubi9` setup, the [Static Containers](https://www.mongodb.com/docs/ku
7883

7984
## New Features
8085

81-
* **MongoDB** Added Support for enabling LogRotation for MongoDB processes, MonitoringAgent and BackupAgent. More can be found in the following [documentation](LINK TO DOCS).
86+
* **MongoDB** Added Support for enabling LogRotation for MongoDB processes, MonitoringAgent and BackupAgent. More can be found in the following [documentation](LINK TO DOCS).
8287
* `spec.agent.mongod.logRotation` to configure the mongoDB processes
8388
* `spec.agent.mongod.auditLogRotation` to configure the mongoDB processes audit logs
8489
* `spec.agent.backupAgent.logRotation` to configure the backup agent
@@ -88,14 +93,14 @@ For a full `ubi9` setup, the [Static Containers](https://www.mongodb.com/docs/ku
8893
the supported environment settings can be found [here](https://github.com/mongodb/mongodb-kubernetes-operator/blob/master/docs/logging.md#readinessprobe).
8994
* the same applies for AppDB:
9095
* you can configure AppDB via `spec.applicationDatabase.agent.mongod.logRotation`
91-
* Please Note: For shardedCluster we only support configuring logRotation under `spec.Agent`
92-
and not per process type (mongos, configsrv etc.)
96+
* Please Note: For shardedCluster we only support configuring logRotation under `spec.Agent`
97+
and not per process type (mongos, configsrv etc.)
9398

9499
* **Opsmanager** Added support for replacing the logback.xml which configures general logging settings like logRotation
95100
* `spec.logging.LogBackAccessRef` points at a ConfigMap/key with the logback access configuration file to mount on the Pod
96101
* the key of the configmap has to be `logback-access.xml`
97102
* `spec.logging.LogBackRef` points at a ConfigMap/key with the logback access configuration file to mount on the Pod
98-
* the key of the configmap has to be `logback.xml`
103+
* the key of the configmap has to be `logback.xml`
99104

100105
## Deprecations
101106

@@ -108,7 +113,7 @@ For a full `ubi9` setup, the [Static Containers](https://www.mongodb.com/docs/ku
108113
The agent now makes sure that there are not conflicting journal data and prioritizes the data from `/data/journal`.
109114
* To deactivate this behaviour set the environment variable in the operator `MDB_CLEAN_JOURNAL`
110115
to any other value than 1.
111-
* **MongoDB**, **AppDB**, **MongoDBMulti**: make sure to use external domains in the connectionString created if configured.
116+
* **MongoDB**, **AppDB**, **MongoDBMulti**: make sure to use external domains in the connectionString created if configured.
112117

113118
* **MongoDB**: Removed panic response when configuring shorter horizon config compared to number of members. The operator now signals a
114119
descriptive error in the status of the **MongoDB** resource.
@@ -120,8 +125,8 @@ descriptive error in the status of the **MongoDB** resource.
120125
## New Features
121126

122127
* Added the ability to control how many reconciles can be performed in parallel by the operator.
123-
This enables strongly improved cpu utilization and vertical scaling of the operator and will lead to quicker reconcile of all managed resources.
124-
* It might lead to increased load on the Ops Manager and K8s API server in the same time window.
128+
This enables strongly improved cpu utilization and vertical scaling of the operator and will lead to quicker reconcile of all managed resources.
129+
* It might lead to increased load on the Ops Manager and K8s API server in the same time window.
125130
by setting `MDB_MAX_CONCURRENT_RECONCILES` for the operator deployment or `operator.maxConcurrentReconciles` in the operator's Helm chart.
126131
If not provided, the default value is 1.
127132
* Observe the operator's resource usage and adjust (`operator.resources.requests` and `operator.resources.limits`) if needed.
@@ -148,7 +153,7 @@ descriptive error in the status of the **MongoDB** resource.
148153
* The Operator supports seamless migration between the Static and non-Static architectures.
149154
* To learn more please see the relevant documentation:
150155
* [Use Static Containers](https://www.mongodb.com/docs/kubernetes-operator/stable/tutorial/plan-k8s-op-considerations/#use-static-containers--beta-)
151-
* [Migrate to Static Containers](https://www.mongodb.com/docs/kubernetes-operator/stable/tutorial/plan-k8s-op-container-images/#migrate-to-static-containers)
156+
* [Migrate to Static Containers](https://www.mongodb.com/docs/kubernetes-operator/stable/tutorial/plan-k8s-op-container-images/#migrate-to-static-containers)
152157
* **MongoDB**: Recover Resource Due to Broken Automation Configuration has been extended to all types of MongoDB resources, now including Sharded Clusters. For more information see https://www.mongodb.com/docs/kubernetes-operator/master/reference/troubleshooting/#recover-resource-due-to-broken-automation-configuration
153158
* **MongoDB, MongoDBMultiCluster**: Placeholders in external services.
154159
* You can now define annotations for external services managed by the operator that contain placeholders which will be automatically replaced to the proper values.
@@ -159,9 +164,9 @@ descriptive error in the status of the **MongoDB** resource.
159164
* MongoDBMultiCluster: [spec.externalAccess.externalService.annotations](https://www.mongodb.com/docs/kubernetes-operator/stable/reference/k8s-operator-multi-cluster-specification/#mongodb-setting-spec.externalAccess.externalService.annotations)
160165
* `kubectl mongodb`:
161166
* Added printing build info when using the plugin.
162-
* `setup` command:
167+
* `setup` command:
163168
* Added `--image-pull-secrets` parameter. If specified, created service accounts will reference the specified secret on `ImagePullSecrets` field.
164-
* Improved handling of configurations when the operator is installed in a separate namespace than the resources it's watching and when the operator is watching more than one namespace.
169+
* Improved handling of configurations when the operator is installed in a separate namespace than the resources it's watching and when the operator is watching more than one namespace.
165170
* Optimized roles and permissions setup in member clusters, using a single service account per cluster with correctly configured Role and RoleBinding (no ClusterRoles necessary) for each watched namespace.
166171
* **OpsManager**: Added the `spec.internalConnectivity` field to allow overrides for the service used by the operator to ensure internal connectivity to the `OpsManager` pods.
167172
* Extended the existing event based reconciliation by a time-based one, that is triggered every 24 hours. This ensures all Agents are always upgraded on timely manner.
@@ -216,12 +221,12 @@ actually defined in `spec.externalAccess.externalDomain` or `spec.clusterSpecLis
216221
## Bug Fixes
217222
* Fix a bug with scaling a multi-cluster replica-set in the case of losing connectivity to a member cluster. The fix addresses both the manual and automated recovery procedures.
218223
* Fix of a bug where changing the names of the automation agent and MongoDB audit logs prevented them from being sent to Kubernetes pod logs. There are no longer restrictions on MongoDB audit log file names (mentioned in the previous release).
219-
* New log types from the `mongodb-enterprise-database` container are now streamed to Kubernetes logs.
220-
* New log types:
224+
* New log types from the `mongodb-enterprise-database` container are now streamed to Kubernetes logs.
225+
* New log types:
221226
* agent-launcher-script
222227
* monitoring-agent
223228
* backup-agent
224-
* The rest of available log types:
229+
* The rest of available log types:
225230
* automation-agent-verbose
226231
* automation-agent-stderr
227232
* automation-agent
@@ -578,7 +583,6 @@ spec:
578583
enabled ApplicationDB, when the ApplicationDB TLS certificate is stored in a
579584
`Secret` of type Opaque.
580585

581-
<!-- Past Releases -->
582586
# MongoDB Enterprise Kubernetes Operator 1.15.0
583587

584588

controllers/operator/mongodbuser_controller.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,13 @@ func (r *MongoDBUserReconciler) handleScramShaUser(ctx context.Context, user *us
370370
return r.updateStatus(ctx, user, workflow.Failed(xerrors.Errorf("error updating user %w", err)), log)
371371
}
372372

373+
// Before we update the MongoDBUser's status to Updated,
374+
// we need to wait for the cluster to be in a ready state
375+
// to ensure that the user has been created successfully and is usable.
376+
if err := waitForReadyState(conn, log); err != nil {
377+
return r.updateStatus(ctx, user, workflow.Pending("error waiting for ready state: %s", err.Error()).WithRetry(10), log)
378+
}
379+
373380
annotationsToAdd, err := getAnnotationsForUserResource(user)
374381
if err != nil {
375382
return r.updateStatus(ctx, user, workflow.Failed(err), log)
@@ -413,6 +420,13 @@ func (r *MongoDBUserReconciler) handleExternalAuthUser(ctx context.Context, user
413420
return r.updateStatus(ctx, user, workflow.Failed(xerrors.Errorf("error updating user %w", err)), log)
414421
}
415422

423+
// Before we update the MongoDBUser's status to Updated,
424+
// we need to wait for the cluster to be in a ready state
425+
// to ensure that the user has been created successfully and is usable.
426+
if err := waitForReadyState(conn, log); err != nil {
427+
return r.updateStatus(ctx, user, workflow.Pending("error waiting for ready state: %s", err.Error()).WithRetry(10), log)
428+
}
429+
416430
annotationsToAdd, err := getAnnotationsForUserResource(user)
417431
if err != nil {
418432
return r.updateStatus(ctx, user, workflow.Failed(err), log)
@@ -426,6 +440,16 @@ func (r *MongoDBUserReconciler) handleExternalAuthUser(ctx context.Context, user
426440
return r.updateStatus(ctx, user, workflow.OK(), log)
427441
}
428442

443+
func waitForReadyState(conn om.Connection, log *zap.SugaredLogger) error {
444+
automationConfig, err := conn.ReadAutomationConfig()
445+
if err != nil {
446+
return err
447+
}
448+
449+
processes := automationConfig.Deployment.GetAllProcessNames()
450+
return om.WaitForReadyState(conn, processes, false, log)
451+
}
452+
429453
func externalAuthMechanismsAvailable(mechanisms []string) bool {
430454
return stringutil.ContainsAny(mechanisms, util.AutomationConfigLDAPOption, util.AutomationConfigX509Option)
431455
}

docker/mongodb-enterprise-tests/tests/authentication/replica_set_agent_ldap.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ def test_replica_set(replica_set: MongoDB):
6767
replica_set.assert_reaches_phase(Phase.Running, timeout=400)
6868

6969

70+
@mark.e2e_replica_set_ldap_agent_auth
71+
def test_ldap_user_mongodb_reaches_updated_phase(ldap_user_mongodb: MongoDBUser):
72+
ldap_user_mongodb.assert_reaches_phase(Phase.Updated, timeout=150)
73+
74+
7075
@mark.e2e_replica_set_ldap_agent_auth
7176
def test_new_ldap_users_can_authenticate(replica_set: MongoDB, ldap_user_mongodb: MongoDBUser):
7277
tester = replica_set.tester()

docker/mongodb-enterprise-tests/tests/authentication/replica_set_ldap_agent_client_certs.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ def test_replica_set(replica_set: MongoDB):
140140
replica_set.assert_reaches_phase(Phase.Running, timeout=400, ignore_errors=True)
141141

142142

143+
@mark.e2e_replica_set_ldap_agent_client_certs
144+
def test_ldap_user_mongodb_reaches_updated_phase(ldap_user_mongodb: MongoDBUser):
145+
ldap_user_mongodb.assert_reaches_phase(Phase.Updated, timeout=150)
146+
147+
143148
@mark.e2e_replica_set_ldap_agent_client_certs
144149
def test_new_ldap_users_can_authenticate(replica_set: MongoDB, ldap_user_mongodb: MongoDBUser, ca_path: str):
145150
tester = replica_set.tester()

docker/mongodb-enterprise-tests/tests/authentication/replica_set_ldap_group_dn.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ def test_replica_set(
7373
replica_set.assert_reaches_phase(Phase.Running, timeout=400)
7474

7575

76+
@mark.e2e_replica_set_ldap_group_dn
77+
def test_ldap_user_mongodb_reaches_updated_phase(ldap_user_mongodb: MongoDBUser):
78+
ldap_user_mongodb.assert_reaches_phase(Phase.Updated, timeout=150)
79+
80+
7681
@mark.e2e_replica_set_ldap_group_dn
7782
def test_new_ldap_users_can_authenticate(replica_set: MongoDB, ldap_user_mongodb: MongoDBUser):
7883
tester = replica_set.tester()

docker/mongodb-enterprise-tests/tests/authentication/replica_set_ldap_group_dn_with_x509_agent.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ def test_replica_set(replica_set: MongoDB, ldap_mongodb_x509_agent_user: LDAPUse
8888
replica_set.assert_reaches_phase(Phase.Running, timeout=400)
8989

9090

91+
@mark.e2e_replica_set_ldap_group_dn_with_x509_agent
92+
def test_ldap_user_mongodb_reaches_updated_phase(ldap_user_mongodb: MongoDBUser):
93+
ldap_user_mongodb.assert_reaches_phase(Phase.Updated, timeout=150)
94+
95+
9196
@mark.e2e_replica_set_ldap_group_dn_with_x509_agent
9297
def test_new_ldap_users_can_authenticate(replica_set: MongoDB, ldap_user_mongodb: MongoDBUser, ca_path: str):
9398
tester = replica_set.tester()

docker/mongodb-enterprise-tests/tests/authentication/sharded_cluster_scram_sha_and_x509.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ def test_ops_manager_state_correctly_updated_sha_and_x509():
144144
tester.assert_expected_users(1)
145145

146146

147+
@pytest.mark.e2e_sharded_cluster_scram_sha_and_x509
148+
def test_x509_user_reaches_updated_phase(x509_user: MongoDBUser):
149+
x509_user.assert_reaches_phase(Phase.Updated, timeout=150)
150+
151+
147152
@pytest.mark.e2e_sharded_cluster_scram_sha_and_x509
148153
def test_x509_user_exists_in_automation_config(x509_user: MongoDBUser):
149154
ac = KubernetesTester.get_automation_config()

0 commit comments

Comments
 (0)