@@ -396,13 +396,19 @@ func isInstanceSizeTheSame(currentDeployment *mongodbatlas.AdvancedCluster, desi
396
396
397
397
func (r * AtlasDeploymentReconciler ) ensureConnectionSecrets (ctx * workflow.Context , project * mdbv1.AtlasProject , name string , connectionStrings * mongodbatlas.ConnectionStrings , deploymentResource * mdbv1.AtlasDeployment ) workflow.Result {
398
398
databaseUsers := mdbv1.AtlasDatabaseUserList {}
399
- err := r .Client .List (context .TODO (), & databaseUsers , client .InNamespace ( project . Namespace ) )
399
+ err := r .Client .List (context .TODO (), & databaseUsers , & client.ListOptions {} )
400
400
if err != nil {
401
401
return workflow .Terminate (workflow .Internal , err .Error ())
402
402
}
403
403
404
404
secrets := make ([]string , 0 )
405
- for _ , dbUser := range databaseUsers .Items {
405
+ for i := range databaseUsers .Items {
406
+ dbUser := databaseUsers .Items [i ]
407
+
408
+ if ! dbUserBelongsToProject (& dbUser , project ) {
409
+ continue
410
+ }
411
+
406
412
found := false
407
413
for _ , c := range dbUser .Status .Conditions {
408
414
if c .Type == status .ReadyType && c .Status == v1 .ConditionTrue {
@@ -436,7 +442,7 @@ func (r *AtlasDeploymentReconciler) ensureConnectionSecrets(ctx *workflow.Contex
436
442
437
443
ctx .Log .Debugw ("Creating a connection Secret" , "data" , data )
438
444
439
- secretName , err := connectionsecret .Ensure (r .Client , project .Namespace , project .Spec .Name , project .ID (), name , data )
445
+ secretName , err := connectionsecret .Ensure (r .Client , dbUser .Namespace , project .Spec .Name , project .ID (), name , data )
440
446
if err != nil {
441
447
return workflow .Terminate (workflow .DeploymentConnectionSecretsNotCreated , err .Error ())
442
448
}
@@ -449,3 +455,19 @@ func (r *AtlasDeploymentReconciler) ensureConnectionSecrets(ctx *workflow.Contex
449
455
450
456
return workflow .OK ()
451
457
}
458
+
459
+ func dbUserBelongsToProject (dbUser * mdbv1.AtlasDatabaseUser , project * mdbv1.AtlasProject ) bool {
460
+ if dbUser .Spec .Project .Name != project .Name {
461
+ return false
462
+ }
463
+
464
+ if dbUser .Spec .Project .Namespace == "" && dbUser .Namespace != project .Namespace {
465
+ return false
466
+ }
467
+
468
+ if dbUser .Spec .Project .Namespace != "" && dbUser .Spec .Project .Namespace != project .Namespace {
469
+ return false
470
+ }
471
+
472
+ return true
473
+ }
0 commit comments