@@ -173,7 +173,7 @@ func (r ReplicaSetReconciler) Reconcile(ctx context.Context, request reconcile.R
173
173
withFailedPhase ())
174
174
}
175
175
176
- ready , err := r .deployMongoDBReplicaSet (ctx , mdb )
176
+ ready , err := r .deployMongoDBReplicaSet (ctx , mdb , lastAppliedSpec )
177
177
if err != nil {
178
178
return status .Update (ctx , r .client .Status (), & mdb , statusOptions ().
179
179
withMessage (Error , fmt .Sprintf ("Error deploying MongoDB ReplicaSet: %s" , err )).
@@ -225,6 +225,7 @@ func (r ReplicaSetReconciler) Reconcile(ctx context.Context, request reconcile.R
225
225
if lastAppliedSpec != nil {
226
226
r .cleanupScramSecrets (ctx , mdb .Spec , * lastAppliedSpec , mdb .Namespace )
227
227
r .cleanupPemSecret (ctx , mdb .Spec , * lastAppliedSpec , mdb .Namespace )
228
+ r .cleanupConnectionStringSecrets (ctx , mdb .Spec , * lastAppliedSpec , mdb .Namespace , mdb .Name )
228
229
}
229
230
230
231
if err := r .updateLastSuccessfulConfiguration (ctx , mdb ); err != nil {
@@ -331,15 +332,15 @@ func (r *ReplicaSetReconciler) deployStatefulSet(ctx context.Context, mdb mdbv1.
331
332
332
333
// deployAutomationConfig deploys the AutomationConfig for the MongoDBCommunity resource.
333
334
// The returned boolean indicates whether or not that Agents have all reached goal state.
334
- func (r * ReplicaSetReconciler ) deployAutomationConfig (ctx context.Context , mdb mdbv1.MongoDBCommunity ) (bool , error ) {
335
+ func (r * ReplicaSetReconciler ) deployAutomationConfig (ctx context.Context , mdb mdbv1.MongoDBCommunity , lastAppliedSpec * mdbv1. MongoDBCommunitySpec ) (bool , error ) {
335
336
r .log .Infof ("Creating/Updating AutomationConfig" )
336
337
337
338
sts , err := r .client .GetStatefulSet (ctx , mdb .NamespacedName ())
338
339
if err != nil && ! apiErrors .IsNotFound (err ) {
339
340
return false , fmt .Errorf ("failed to get StatefulSet: %s" , err )
340
341
}
341
342
342
- ac , err := r .ensureAutomationConfig (mdb , ctx )
343
+ ac , err := r .ensureAutomationConfig (mdb , ctx , lastAppliedSpec )
343
344
if err != nil {
344
345
return false , fmt .Errorf ("failed to ensure AutomationConfig: %s" , err )
345
346
}
@@ -408,10 +409,10 @@ func (r *ReplicaSetReconciler) shouldRunInOrder(ctx context.Context, mdb mdbv1.M
408
409
// deployMongoDBReplicaSet will ensure that both the AutomationConfig secret and backing StatefulSet
409
410
// have been successfully created. A boolean is returned indicating if the process is complete
410
411
// and an error if there was one.
411
- func (r * ReplicaSetReconciler ) deployMongoDBReplicaSet (ctx context.Context , mdb mdbv1.MongoDBCommunity ) (bool , error ) {
412
+ func (r * ReplicaSetReconciler ) deployMongoDBReplicaSet (ctx context.Context , mdb mdbv1.MongoDBCommunity , lastAppliedSpec * mdbv1. MongoDBCommunitySpec ) (bool , error ) {
412
413
return functions .RunSequentially (r .shouldRunInOrder (ctx , mdb ),
413
414
func () (bool , error ) {
414
- return r .deployAutomationConfig (ctx , mdb )
415
+ return r .deployAutomationConfig (ctx , mdb , lastAppliedSpec )
415
416
},
416
417
func () (bool , error ) {
417
418
return r .deployStatefulSet (ctx , mdb )
@@ -489,8 +490,8 @@ func (r *ReplicaSetReconciler) createOrUpdateStatefulSet(ctx context.Context, md
489
490
490
491
// ensureAutomationConfig makes sure the AutomationConfig secret has been successfully created. The automation config
491
492
// that was updated/created is returned.
492
- func (r ReplicaSetReconciler ) ensureAutomationConfig (mdb mdbv1.MongoDBCommunity , ctx context.Context ) (automationconfig.AutomationConfig , error ) {
493
- ac , err := r .buildAutomationConfig (ctx , mdb )
493
+ func (r ReplicaSetReconciler ) ensureAutomationConfig (mdb mdbv1.MongoDBCommunity , ctx context.Context , lastAppliedSpec * mdbv1. MongoDBCommunitySpec ) (automationconfig.AutomationConfig , error ) {
494
+ ac , err := r .buildAutomationConfig (ctx , mdb , lastAppliedSpec )
494
495
if err != nil {
495
496
return automationconfig.AutomationConfig {}, fmt .Errorf ("could not build automation config: %s" , err )
496
497
}
@@ -622,7 +623,7 @@ func getCustomRolesModification(mdb mdbv1.MongoDBCommunity) (automationconfig.Mo
622
623
}, nil
623
624
}
624
625
625
- func (r ReplicaSetReconciler ) buildAutomationConfig (ctx context.Context , mdb mdbv1.MongoDBCommunity ) (automationconfig.AutomationConfig , error ) {
626
+ func (r ReplicaSetReconciler ) buildAutomationConfig (ctx context.Context , mdb mdbv1.MongoDBCommunity , lastAppliedSpec * mdbv1. MongoDBCommunitySpec ) (automationconfig.AutomationConfig , error ) {
626
627
tlsModification , err := getTLSConfigModification (ctx , r .client , r .client , mdb )
627
628
if err != nil {
628
629
return automationconfig.AutomationConfig {}, fmt .Errorf ("could not configure TLS modification: %s" , err )
@@ -643,6 +644,10 @@ func (r ReplicaSetReconciler) buildAutomationConfig(ctx context.Context, mdb mdb
643
644
return automationconfig.AutomationConfig {}, err
644
645
}
645
646
647
+ if lastAppliedSpec != nil {
648
+ authentication .AddRemovedUsers (& auth , mdb , lastAppliedSpec )
649
+ }
650
+
646
651
prometheusModification := automationconfig .NOOP ()
647
652
if mdb .Spec .Prometheus != nil {
648
653
secretNamespacedName := types.NamespacedName {Name : mdb .Spec .Prometheus .PasswordSecretRef .Name , Namespace : mdb .Namespace }
0 commit comments