@@ -31,6 +31,7 @@ import (
3131 "github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper/conditions"
3232 "github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper/events"
3333 "github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper/resources"
34+ "github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper/retry"
3435)
3536
3637const (
@@ -74,7 +75,8 @@ var _ = Describe("Atlas Database User", Label("int", "AtlasDatabaseUser", "prote
7475 })
7576
7677 By ("Creating a deployment" , func () {
77- testDeployment = akov2 .DefaultAWSDeployment (testNamespace .Name , projectName ).Lightweight ()
78+ testDeployment = akov2 .NewDefaultAWSFlexInstance (testNamespace .Name , projectName ).
79+ WithName ("test-flex-deployment" ).WithAtlasName ("test-flex-deployment" )
7880 Expect (k8sClient .Create (context .Background (), testDeployment )).To (Succeed ())
7981
8082 Eventually (func () bool {
@@ -276,7 +278,7 @@ var _ = Describe("Atlas Database User", Label("int", "AtlasDatabaseUser", "prote
276278 })
277279 })
278280
279- It ("Adds connection secret when new deployment is created" , Label ("user-add-secret" ), func () {
281+ It ("Adds connection secret when new deployment is created with an existing user " , Label ("user-add-secret" ), func () {
280282 secondDeployment := & akov2.AtlasDeployment {}
281283
282284 By ("Creating a database user for existing deployment only" , func () {
@@ -298,13 +300,13 @@ var _ = Describe("Atlas Database User", Label("int", "AtlasDatabaseUser", "prote
298300 Expect (tryConnect (testProject .ID (), * testDeployment , * testDBUser1 )).Should (Succeed ())
299301 })
300302
301- By ("Creating a second deployment" , func () {
302- secondDeployment = akov2 .DefaultAzureDeployment (testNamespace .Name , projectName ). Lightweight ( )
303+ By ("Creating a second deployment" , func () {
304+ secondDeployment = akov2 .NewDefaultAzureFlexInstance (testNamespace .Name , projectName )
303305 Expect (k8sClient .Create (context .Background (), secondDeployment )).To (Succeed ())
304306
305307 Eventually (func () bool {
306308 return resources .CheckCondition (k8sClient , secondDeployment , api .TrueCondition (api .ReadyType ))
307- }).WithTimeout (20 * time .Minute ).WithPolling (PollingInterval ).Should (BeTrue ())
309+ }).WithTimeout (5 * time .Minute ).WithPolling (PollingInterval ).Should (BeTrue ())
308310 })
309311
310312 By ("Validating connection secrets for second deployment were not created" , func () {
@@ -338,8 +340,8 @@ var _ = Describe("Atlas Database User", Label("int", "AtlasDatabaseUser", "prote
338340 Expect (k8sClient .Delete (context .Background (), secondDeployment )).To (Succeed ())
339341
340342 Eventually (func () bool {
341- _ , r , err := atlasClient . ClustersApi .
342- GetCluster (context .Background (), testProject .ID (), deploymentName ).
343+ _ , r , err := atlasClientv20241113001 . FlexClustersApi .
344+ GetFlexCluster (context .Background (), testProject .ID (), deploymentName ).
343345 Execute ()
344346 if err != nil {
345347 if r != nil && r .StatusCode == http .StatusNotFound {
@@ -348,7 +350,33 @@ var _ = Describe("Atlas Database User", Label("int", "AtlasDatabaseUser", "prote
348350 }
349351
350352 return false
351- }).WithTimeout (20 * time .Minute ).WithPolling (PollingInterval ).Should (BeTrue ())
353+ }).WithTimeout (5 * time .Minute ).WithPolling (PollingInterval ).Should (BeTrue ())
354+ })
355+ })
356+
357+ It ("Adds connection secret when new user is created with an existing deployment" , Label ("user-add-secret" ), func () {
358+ By ("Creating a database user" , func () {
359+ passwordSecret := buildPasswordSecret (testNamespace .Name , UserPasswordSecret , DBUserPassword )
360+ Expect (k8sClient .Create (context .Background (), & passwordSecret )).To (Succeed ())
361+
362+ testDBUser1 = akov2 .NewDBUser (testNamespace .Name , dbUserName1 , dbUserName1 , projectName ).
363+ WithPasswordSecret (UserPasswordSecret ).
364+ WithRole ("readWriteAnyDatabase" , "admin" , "" )
365+ Expect (k8sClient .Create (context .Background (), testDBUser1 )).To (Succeed ())
366+
367+ Eventually (func () bool {
368+ return resources .CheckCondition (k8sClient , testDBUser1 , api .TrueCondition (api .ReadyType ))
369+ }).WithTimeout (databaseUserTimeout ).WithPolling (PollingInterval ).Should (BeTrue ())
370+
371+ validateSecret (k8sClient , * testProject , * testDeployment , * testDBUser1 )
372+
373+ Expect (tryConnect (testProject .ID (), * testDeployment , * testDBUser1 )).Should (Succeed ())
374+ })
375+
376+ By ("Validating connection secrets were created" , func () {
377+ validateSecret (k8sClient , * testProject , * testDeployment , * testDBUser1 )
378+
379+ Expect (tryConnect (testProject .ID (), * testDeployment , * testDBUser1 )).Should (Succeed ())
352380 })
353381 })
354382
@@ -407,7 +435,7 @@ var _ = Describe("Atlas Database User", Label("int", "AtlasDatabaseUser", "prote
407435 secondTestDeployment := & akov2.AtlasDeployment {}
408436
409437 By ("Creating a second deployment" , func () {
410- secondTestDeployment = akov2 .DefaultAzureDeployment (testNamespace .Name , projectName ). Lightweight ( )
438+ secondTestDeployment = akov2 .NewDefaultAzureFlexInstance (testNamespace .Name , projectName )
411439 Expect (k8sClient .Create (context .Background (), secondTestDeployment )).To (Succeed ())
412440
413441 Eventually (func () bool {
@@ -451,9 +479,15 @@ var _ = Describe("Atlas Database User", Label("int", "AtlasDatabaseUser", "prote
451479
452480 checkNumberOfConnectionSecrets (k8sClient , * testProject , testNamespace .Name , 2 )
453481 secret := validateSecret (k8sClient , * testProject , * testDeployment , * testDBUser1 )
454- Expect (secret .Name ).To (Equal (fmt .Sprintf ("%s-test-deployment-aws-new-user" , kube .NormalizeIdentifier (testProject .Spec .Name ))))
482+ Expect (secret .Name ).To (Equal (fmt .Sprintf ("%s-%s-new-user" ,
483+ kube .NormalizeIdentifier (testProject .Spec .Name ),
484+ kube .NormalizeIdentifier (testDeployment .GetDeploymentName ()),
485+ )))
455486 secret = validateSecret (k8sClient , * testProject , * secondTestDeployment , * testDBUser1 )
456- Expect (secret .Name ).To (Equal (fmt .Sprintf ("%s-test-deployment-azure-new-user" , kube .NormalizeIdentifier (testProject .Spec .Name ))))
487+ Expect (secret .Name ).To (Equal (fmt .Sprintf ("%s-%s-new-user" ,
488+ kube .NormalizeIdentifier (testProject .Spec .Name ),
489+ kube .NormalizeIdentifier (secondTestDeployment .GetDeploymentName ()),
490+ )))
457491
458492 Expect (tryConnect (testProject .ID (), * testDeployment , * testDBUser1 )).Should (Succeed ())
459493 Expect (tryConnect (testProject .ID (), * secondTestDeployment , * testDBUser1 )).Should (Succeed ())
@@ -479,8 +513,8 @@ var _ = Describe("Atlas Database User", Label("int", "AtlasDatabaseUser", "prote
479513 Expect (k8sClient .Delete (context .Background (), secondTestDeployment )).To (Succeed ())
480514
481515 Eventually (func () bool {
482- _ , r , err := atlasClient . ClustersApi .
483- GetCluster (context .Background (), testProject .ID (), deploymentName ).
516+ _ , r , err := atlasClientv20241113001 . FlexClustersApi .
517+ GetFlexCluster (context .Background (), testProject .ID (), deploymentName ).
484518 Execute ()
485519 if err != nil {
486520 if r != nil && r .StatusCode == http .StatusNotFound {
@@ -520,9 +554,11 @@ var _ = Describe("Atlas Database User", Label("int", "AtlasDatabaseUser", "prote
520554
521555 By ("Fixing the user date expiration" , func () {
522556 after := time .Now ().UTC ().Add (time .Hour * 10 ).Format ("2006-01-02T15:04:05" )
523- testDBUser1 = testDBUser1 .WithDeleteAfterDate (after )
524557
525558 Expect (k8sClient .Update (context .Background (), testDBUser1 )).To (Succeed ())
559+ retry .RetryUpdateOnConflict (context .Background (), k8sClient , client .ObjectKeyFromObject (testDBUser1 ), func (user * akov2.AtlasDatabaseUser ) {
560+ user .Spec .DeleteAfterDate = after
561+ })
526562 Eventually (func () bool {
527563 return resources .CheckCondition (k8sClient , testDBUser1 , api .TrueCondition (api .ReadyType ))
528564 }).WithTimeout (databaseUserTimeout ).WithPolling (PollingInterval ).Should (BeTrue ())
@@ -533,9 +569,11 @@ var _ = Describe("Atlas Database User", Label("int", "AtlasDatabaseUser", "prote
533569
534570 By ("Expiring the User" , func () {
535571 before := time .Now ().UTC ().Add (time .Minute * - 5 ).Format ("2006-01-02T15:04:05" )
536- testDBUser1 = testDBUser1 .WithDeleteAfterDate (before )
537572
538573 Expect (k8sClient .Update (context .Background (), testDBUser1 )).To (Succeed ())
574+ retry .RetryUpdateOnConflict (context .Background (), k8sClient , client .ObjectKeyFromObject (testDBUser1 ), func (user * akov2.AtlasDatabaseUser ) {
575+ user .Spec .DeleteAfterDate = before
576+ })
539577 Eventually (func () bool {
540578 return resources .CheckCondition (k8sClient , testDBUser1 , api .FalseCondition (api .DatabaseUserReadyType ).WithReason (string (workflow .DatabaseUserExpired )))
541579 }).WithTimeout (databaseUserTimeout ).WithPolling (PollingInterval ).Should (BeTrue ())
@@ -604,8 +642,8 @@ var _ = Describe("Atlas Database User", Label("int", "AtlasDatabaseUser", "prote
604642 Expect (k8sClient .Delete (context .Background (), testDeployment )).To (Succeed ())
605643
606644 Eventually (func () bool {
607- _ , r , err := atlasClient . ClustersApi .
608- GetCluster (context .Background (), testProject .ID (), deploymentName ).
645+ _ , r , err := atlasClientv20241113001 . FlexClustersApi .
646+ GetFlexCluster (context .Background (), testProject .ID (), deploymentName ).
609647 Execute ()
610648 if err != nil {
611649 if r != nil && r .StatusCode == http .StatusNotFound {
@@ -614,7 +652,7 @@ var _ = Describe("Atlas Database User", Label("int", "AtlasDatabaseUser", "prote
614652 }
615653
616654 return false
617- }).WithTimeout (20 * time .Minute ).WithPolling (PollingInterval ).Should (BeTrue ())
655+ }).WithTimeout (10 * time .Minute ).WithPolling (PollingInterval ).Should (BeTrue ())
618656 })
619657
620658 By ("Deleting the project" , func () {
@@ -630,7 +668,7 @@ var _ = Describe("Atlas Database User", Label("int", "AtlasDatabaseUser", "prote
630668 }
631669
632670 return false
633- }).WithTimeout (15 * time .Minute ).WithPolling (PollingInterval ).Should (BeTrue ())
671+ }).WithTimeout (5 * time .Minute ).WithPolling (PollingInterval ).Should (BeTrue ())
634672 })
635673
636674 By ("Stopping the operator" , func () {
@@ -665,8 +703,8 @@ func validateSecret(k8sClient client.Client, project akov2.AtlasProject, deploym
665703 password , err := user .ReadPassword (context .Background (), k8sClient )
666704 Expect (err ).NotTo (HaveOccurred ())
667705
668- c , _ , err := atlasClient . ClustersApi .
669- GetCluster (context .Background (), project .ID (), deployment .GetDeploymentName ()).
706+ c , _ , err := atlasClientv20241113001 . FlexClustersApi .
707+ GetFlexCluster (context .Background (), project .ID (), deployment .GetDeploymentName ()).
670708 Execute ()
671709 Expect (err ).NotTo (HaveOccurred ())
672710
@@ -675,8 +713,8 @@ func validateSecret(k8sClient client.Client, project akov2.AtlasProject, deploym
675713 expectedData := map [string ][]byte {
676714 "connectionStringStandard" : []byte (buildConnectionURL (connectionStrings .GetStandard (), username , password )),
677715 "connectionStringStandardSrv" : []byte (buildConnectionURL (connectionStrings .GetStandardSrv (), username , password )),
678- "connectionStringPrivate" : []byte (buildConnectionURL ( connectionStrings . GetPrivate (), username , password ) ),
679- "connectionStringPrivateSrv" : []byte (buildConnectionURL ( connectionStrings . GetPrivateSrv (), username , password ) ),
716+ "connectionStringPrivate" : []byte ("" ),
717+ "connectionStringPrivateSrv" : []byte ("" ),
680718 "username" : []byte (username ),
681719 "password" : []byte (password ),
682720 }
@@ -717,8 +755,8 @@ func buildConnectionURL(connURL, userName, password string) string {
717755func mongoClient (projectID string , deployment akov2.AtlasDeployment , user akov2.AtlasDatabaseUser ) (* mongo.Client , error ) {
718756 ctx , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
719757 defer cancel ()
720- c , _ , err := atlasClient . ClustersApi .
721- GetCluster (context .Background (), projectID , deployment .GetDeploymentName ()).
758+ c , _ , err := atlasClientv20241113001 . FlexClustersApi .
759+ GetFlexCluster (context .Background (), projectID , deployment .GetDeploymentName ()).
722760 Execute ()
723761 Expect (err ).NotTo (HaveOccurred ())
724762
0 commit comments