@@ -243,9 +243,10 @@ var _ = Describe("Atlas Database User", Label("int", "AtlasDatabaseUser", "prote
243
243
244
244
By ("Giving user readWrite permissions" , func () {
245
245
// Adding the role allowing read/write
246
- testDBUser1 = testDBUser1 .WithRole ("readWriteAnyDatabase" , "admin" , "" )
247
-
248
- Expect (k8sClient .Update (context .Background (), testDBUser1 )).To (Succeed ())
246
+ _ , err := retry .RetryUpdateOnConflict (context .Background (), k8sClient , client .ObjectKeyFromObject (testDBUser1 ), func (user * akov2.AtlasDatabaseUser ) {
247
+ user .WithRole ("readWriteAnyDatabase" , "admin" , "" )
248
+ })
249
+ Expect (err ).NotTo (HaveOccurred ())
249
250
250
251
Eventually (func () bool {
251
252
return resources .CheckCondition (k8sClient , testDBUser1 , api .TrueCondition (api .ReadyType ))
@@ -317,10 +318,10 @@ var _ = Describe("Atlas Database User", Label("int", "AtlasDatabaseUser", "prote
317
318
})
318
319
319
320
By ("Removing database user scope for first deployment" , func () {
320
- Expect ( k8sClient . Get (context .Background (), client .ObjectKeyFromObject (testDBUser1 ), testDBUser1 )). Should ( Succeed ())
321
- testDBUser1 .Spec .Scopes = nil
322
-
323
- Expect (k8sClient . Update ( context . Background (), testDBUser1 )). To ( Succeed ())
321
+ _ , err := retry . RetryUpdateOnConflict (context .Background (), k8sClient , client .ObjectKeyFromObject (testDBUser1 ), func ( user * akov2. AtlasDatabaseUser ) {
322
+ user .Spec .Scopes = nil
323
+ })
324
+ Expect (err ). NotTo ( HaveOccurred ())
324
325
325
326
Eventually (func () bool {
326
327
return resources .CheckCondition (k8sClient , testDBUser1 , api .TrueCondition (api .ReadyType ))
@@ -400,8 +401,12 @@ var _ = Describe("Atlas Database User", Label("int", "AtlasDatabaseUser", "prote
400
401
})
401
402
402
403
By ("Breaking the password secret" , func () {
403
- passwordSecret := buildPasswordSecret (testNamespace .Name , UserPasswordSecret , "" )
404
- Expect (k8sClient .Update (context .Background (), & passwordSecret )).To (Succeed ())
404
+ _ , err := retry .RetryUpdateOnConflict (context .Background (), k8sClient , client.ObjectKey {Namespace : testNamespace .Name , Name : UserPasswordSecret }, func (secret * corev1.Secret ) {
405
+ empty := buildPasswordSecret (secret .GetNamespace (), secret .GetName (), "" )
406
+ secret .Labels = empty .Labels
407
+ secret .StringData = empty .StringData
408
+ })
409
+ Expect (err ).NotTo (HaveOccurred ())
405
410
406
411
expectedCondition := api .FalseCondition (api .DatabaseUserReadyType ).WithReason (string (workflow .Internal )).WithMessageRegexp ("the 'password' field is empty" )
407
412
Eventually (func () bool {
@@ -412,8 +417,12 @@ var _ = Describe("Atlas Database User", Label("int", "AtlasDatabaseUser", "prote
412
417
})
413
418
414
419
By ("Fixing the password secret" , func () {
415
- passwordSecret := buildPasswordSecret (testNamespace .Name , UserPasswordSecret , "someNewPassw00rd" )
416
- Expect (k8sClient .Update (context .Background (), & passwordSecret )).To (Succeed ())
420
+ _ , err := retry .RetryUpdateOnConflict (context .Background (), k8sClient , client.ObjectKey {Namespace : testNamespace .Name , Name : UserPasswordSecret }, func (secret * corev1.Secret ) {
421
+ somePassword := buildPasswordSecret (secret .GetNamespace (), secret .GetName (), "someNewPassw00rd" )
422
+ secret .Labels = somePassword .Labels
423
+ secret .StringData = somePassword .StringData
424
+ })
425
+ Expect (err ).NotTo (HaveOccurred ())
417
426
418
427
Eventually (func () bool {
419
428
return resources .CheckCondition (k8sClient , testDBUser1 , api .TrueCondition (api .ReadyType ))
@@ -466,14 +475,17 @@ var _ = Describe("Atlas Database User", Label("int", "AtlasDatabaseUser", "prote
466
475
By ("Renaming username, new user is added and stale secrets are removed" , func () {
467
476
Expect (k8sClient .Get (context .Background (), client .ObjectKeyFromObject (testDBUser1 ), testDBUser1 )).To (Succeed ())
468
477
oldName := testDBUser1 .Spec .Username
469
- testDBUser1 = testDBUser1 .WithAtlasUserName ("new-user" )
470
- Expect (k8sClient .Update (context .Background (), testDBUser1 )).To (Succeed ())
478
+
479
+ _ , err := retry .RetryUpdateOnConflict (context .Background (), k8sClient , client .ObjectKeyFromObject (testDBUser1 ), func (user * akov2.AtlasDatabaseUser ) {
480
+ user .WithAtlasUserName ("new-user" )
481
+ })
482
+ Expect (err ).NotTo (HaveOccurred ())
471
483
472
484
Eventually (func () bool {
473
485
return resources .CheckCondition (k8sClient , testDBUser1 , api .TrueCondition (api .ReadyType ))
474
486
}).WithTimeout (databaseUserTimeout ).WithPolling (PollingInterval ).Should (BeTrue ())
475
487
476
- _ , _ , err : = atlasClient .DatabaseUsersApi .
488
+ _ , _ , err = atlasClient .DatabaseUsersApi .
477
489
GetDatabaseUser (context .Background (), testProject .ID (), testDBUser1 .Spec .DatabaseName , oldName ).
478
490
Execute ()
479
491
Expect (err ).To (HaveOccurred ())
@@ -495,8 +507,10 @@ var _ = Describe("Atlas Database User", Label("int", "AtlasDatabaseUser", "prote
495
507
})
496
508
497
509
By ("Scoping user to one cluster, a stale secret is removed" , func () {
498
- testDBUser1 = testDBUser1 .ClearScopes ().WithScope (akov2 .DeploymentScopeType , testDeployment .GetDeploymentName ())
499
- Expect (k8sClient .Update (context .Background (), testDBUser1 )).To (Succeed ())
510
+ _ , err := retry .RetryUpdateOnConflict (context .Background (), k8sClient , client .ObjectKeyFromObject (testDBUser1 ), func (user * akov2.AtlasDatabaseUser ) {
511
+ user .ClearScopes ().WithScope (akov2 .DeploymentScopeType , testDeployment .GetDeploymentName ())
512
+ })
513
+ Expect (err ).NotTo (HaveOccurred ())
500
514
501
515
Eventually (func () bool {
502
516
return resources .CheckCondition (k8sClient , testDBUser1 , api .TrueCondition (api .ReadyType ))
@@ -556,10 +570,10 @@ var _ = Describe("Atlas Database User", Label("int", "AtlasDatabaseUser", "prote
556
570
By ("Fixing the user date expiration" , func () {
557
571
after := time .Now ().UTC ().Add (time .Hour * 10 ).Format ("2006-01-02T15:04:05" )
558
572
559
- Expect (k8sClient .Update (context .Background (), testDBUser1 )).To (Succeed ())
560
- retry .RetryUpdateOnConflict (context .Background (), k8sClient , client .ObjectKeyFromObject (testDBUser1 ), func (user * akov2.AtlasDatabaseUser ) {
573
+ _ , err := retry .RetryUpdateOnConflict (context .Background (), k8sClient , client .ObjectKeyFromObject (testDBUser1 ), func (user * akov2.AtlasDatabaseUser ) {
561
574
user .Spec .DeleteAfterDate = after
562
575
})
576
+ Expect (err ).NotTo (HaveOccurred ())
563
577
Eventually (func () bool {
564
578
return resources .CheckCondition (k8sClient , testDBUser1 , api .TrueCondition (api .ReadyType ))
565
579
}).WithTimeout (databaseUserTimeout ).WithPolling (PollingInterval ).Should (BeTrue ())
@@ -571,10 +585,10 @@ var _ = Describe("Atlas Database User", Label("int", "AtlasDatabaseUser", "prote
571
585
By ("Expiring the User" , func () {
572
586
before := time .Now ().UTC ().Add (time .Minute * - 5 ).Format ("2006-01-02T15:04:05" )
573
587
574
- Expect (k8sClient .Update (context .Background (), testDBUser1 )).To (Succeed ())
575
- retry .RetryUpdateOnConflict (context .Background (), k8sClient , client .ObjectKeyFromObject (testDBUser1 ), func (user * akov2.AtlasDatabaseUser ) {
588
+ _ , err := retry .RetryUpdateOnConflict (context .Background (), k8sClient , client .ObjectKeyFromObject (testDBUser1 ), func (user * akov2.AtlasDatabaseUser ) {
576
589
user .Spec .DeleteAfterDate = before
577
590
})
591
+ Expect (err ).NotTo (HaveOccurred ())
578
592
Eventually (func () bool {
579
593
return resources .CheckCondition (k8sClient , testDBUser1 , api .FalseCondition (api .DatabaseUserReadyType ).WithReason (string (workflow .DatabaseUserExpired )))
580
594
}).WithTimeout (databaseUserTimeout ).WithPolling (PollingInterval ).Should (BeTrue ())
@@ -611,15 +625,15 @@ var _ = Describe("Atlas Database User", Label("int", "AtlasDatabaseUser", "prote
611
625
})
612
626
613
627
By ("Skipping reconciliation" , func () {
614
- Expect (k8sClient .Get (context .Background (), client .ObjectKeyFromObject (testDBUser1 ), testDBUser1 )).To (Succeed ())
615
- testDBUser1 .ObjectMeta .Annotations = map [string ]string {customresource .ReconciliationPolicyAnnotation : customresource .ReconciliationPolicySkip }
616
- testDBUser1 .Spec .Roles = append (testDBUser1 .Spec .Roles , akov2.RoleSpec {
617
- RoleName : "new-role" ,
618
- DatabaseName : "new-database" ,
619
- CollectionName : "new-collection" ,
628
+ _ , err := retry .RetryUpdateOnConflict (context .Background (), k8sClient , client .ObjectKeyFromObject (testDBUser1 ), func (user * akov2.AtlasDatabaseUser ) {
629
+ user .ObjectMeta .Annotations = map [string ]string {customresource .ReconciliationPolicyAnnotation : customresource .ReconciliationPolicySkip }
630
+ user .Spec .Roles = append (testDBUser1 .Spec .Roles , akov2.RoleSpec {
631
+ RoleName : "new-role" ,
632
+ DatabaseName : "new-database" ,
633
+ CollectionName : "new-collection" ,
634
+ })
620
635
})
621
-
622
- Expect (k8sClient .Update (context .Background (), testDBUser1 )).To (Succeed ())
636
+ Expect (err ).NotTo (HaveOccurred ())
623
637
624
638
ctx , cancel := context .WithTimeout (context .Background (), time .Minute * 2 )
625
639
defer cancel ()
0 commit comments