@@ -544,6 +544,42 @@ func TestMinioBucket(t *testing.T) {
544
544
td .Require .True (be , "check if bucket exists" )
545
545
})
546
546
547
+ t .Run ("does not create a minio bucket if one exists" , func (t * testing.T ) {
548
+ td := Setup (t )
549
+
550
+ b := createBucket (td )
551
+ err := td .Minio .MakeBucket (td .Ctx , b .Spec .Name , minio.MakeBucketOptions {})
552
+ td .Require .NoError (err , "create minio bucket" )
553
+
554
+ WaitForReconcilerError (td , func (err error ) error {
555
+ merr , ok := err .(minio.ErrorResponse )
556
+ if ! ok {
557
+ return nil
558
+ }
559
+ if merr .Code != "BucketAlreadyOwnedByYou" {
560
+ return nil
561
+ }
562
+ if merr .BucketName != b .Spec .Name {
563
+ return nil
564
+ }
565
+ return StopIteration {}
566
+ })
567
+ })
568
+
569
+ t .Run ("migrates an existing bucket if migrate set to true" , func (t * testing.T ) {
570
+ td := Setup (t )
571
+
572
+ b := createBucket (td )
573
+ err := td .Minio .MakeBucket (td .Ctx , b .Spec .Name , minio.MakeBucketOptions {})
574
+ td .Require .NoError (err , "create minio bucket" )
575
+ b .Spec .Migrate = true
576
+ err = td .Kube .Update (td .Ctx , b )
577
+ td .Require .NoError (err , "update bucket resource" )
578
+
579
+ waitForReconcile (td , b )
580
+ td .Require .False (b .Spec .Migrate , "migrate unset on reconcile" )
581
+ })
582
+
547
583
t .Run ("deletes a minio bucket" , func (t * testing.T ) {
548
584
td := Setup (t )
549
585
@@ -691,6 +727,35 @@ func TestMinioGroup(t *testing.T) {
691
727
td .Require .NoError (err , "check if group exists" )
692
728
})
693
729
730
+ t .Run ("does not create a minio group if one exists" , func (t * testing.T ) {
731
+ td := Setup (t )
732
+
733
+ g := createGroup (td )
734
+ err := td .Madmin .UpdateGroupMembers (td .Ctx , madmin.GroupAddRemove {Group : g .Spec .Name })
735
+ td .Require .NoError (err , "create minio group" )
736
+
737
+ WaitForReconcilerError (td , func (err error ) error {
738
+ if err .Error () != fmt .Sprintf ("group %s already exists" , g .Spec .Name ) {
739
+ return nil
740
+ }
741
+ return StopIteration {}
742
+ })
743
+ })
744
+
745
+ t .Run ("migrates an existing group if migrate set to true" , func (t * testing.T ) {
746
+ td := Setup (t )
747
+
748
+ g := createGroup (td )
749
+ err := td .Madmin .UpdateGroupMembers (td .Ctx , madmin.GroupAddRemove {Group : g .Spec .Name })
750
+ td .Require .NoError (err , "create minio group" )
751
+ g .Spec .Migrate = true
752
+ err = td .Kube .Update (td .Ctx , g )
753
+ td .Require .NoError (err , "update group resource" )
754
+
755
+ waitForReconcile (td , g )
756
+ td .Require .False (g .Spec .Migrate , "migrate unset on reconcile" )
757
+ })
758
+
694
759
t .Run ("deletes a minio group" , func (t * testing.T ) {
695
760
td := Setup (t )
696
761
@@ -773,7 +838,7 @@ func TestMinioGroupBinding(t *testing.T) {
773
838
waitForReconcile := func (td TestData , gb * v1.MinioGroupBinding ) {
774
839
RunOperatorUntil (td , func () error {
775
840
err := td .Kube .Get (td .Ctx , client .ObjectKeyFromObject (gb ), gb )
776
- td .Require .NoError (err , "waiting for group reconcile" )
841
+ td .Require .NoError (err , "waiting for group binding reconcile" )
777
842
if gb .Status .CurrentSpec == nil {
778
843
return nil
779
844
}
@@ -795,6 +860,51 @@ func TestMinioGroupBinding(t *testing.T) {
795
860
td .Require .True (slices .Contains (gd .Members , gb .Spec .User ), "user not member of group" )
796
861
})
797
862
863
+ t .Run ("does not create a minio group binding if one exists" , func (t * testing.T ) {
864
+ td := Setup (t )
865
+
866
+ gb := createGroupBinding (td )
867
+ waitForReconcile (td , gb )
868
+
869
+ err := td .Kube .Delete (td .Ctx , gb )
870
+ td .Require .NoError (err , "delete minio group binding resource" )
871
+ WaitForDelete (td , gb )
872
+
873
+ gb = builtinGroupToBuiltinUser .DeepCopy ()
874
+ err = td .Kube .Create (td .Ctx , gb )
875
+ td .Require .NoError (err , "create minio group binding resource" )
876
+ err = td .Madmin .UpdateGroupMembers (td .Ctx , madmin.GroupAddRemove {Group : gb .Spec .Group , Members : []string {gb .Spec .User }})
877
+ td .Require .NoError (err , "create minio group binding" )
878
+
879
+ WaitForReconcilerError (td , func (err error ) error {
880
+ if err .Error () != fmt .Sprintf ("user %s already member of group %s" , gb .Spec .User , gb .Spec .Group ) {
881
+ return nil
882
+ }
883
+ return StopIteration {}
884
+ })
885
+ })
886
+
887
+ t .Run ("migrates an existing group if migrate set to true" , func (t * testing.T ) {
888
+ td := Setup (t )
889
+
890
+ gb := createGroupBinding (td )
891
+ waitForReconcile (td , gb )
892
+
893
+ err := td .Kube .Delete (td .Ctx , gb )
894
+ td .Require .NoError (err , "delete minio group binding resource" )
895
+ WaitForDelete (td , gb )
896
+
897
+ gb = builtinGroupToBuiltinUser .DeepCopy ()
898
+ gb .Spec .Migrate = true
899
+ err = td .Kube .Create (td .Ctx , gb )
900
+ td .Require .NoError (err , "create minio group binding resource" )
901
+ err = td .Madmin .UpdateGroupMembers (td .Ctx , madmin.GroupAddRemove {Group : gb .Spec .Group , Members : []string {gb .Spec .User }})
902
+ td .Require .NoError (err , "create minio group binding" )
903
+
904
+ waitForReconcile (td , gb )
905
+ td .Require .False (gb .Spec .Migrate , "migrate unset on reconcile" )
906
+ })
907
+
798
908
t .Run ("deletes a minio group binding" , func (t * testing.T ) {
799
909
td := Setup (t )
800
910
@@ -917,6 +1027,39 @@ func TestMinioPolicy(t *testing.T) {
917
1027
td .Require .NoError (err , "check if policy exists" )
918
1028
})
919
1029
1030
+ t .Run ("does not create a minio policy if one exists" , func (t * testing.T ) {
1031
+ td := Setup (t )
1032
+
1033
+ p := createPolicy (td )
1034
+ pb , err := json .Marshal (map [string ]any {"Version" : p .Spec .Version , "Statement" : p .Spec .Statement })
1035
+ td .Require .NoError (err , "marshal minio policy" )
1036
+ err = td .Madmin .AddCannedPolicy (td .Ctx , p .Spec .Name , pb )
1037
+ td .Require .NoError (err , "create minio policy" )
1038
+
1039
+ WaitForReconcilerError (td , func (err error ) error {
1040
+ if err .Error () != fmt .Sprintf ("policy %s already exists" , p .Spec .Name ) {
1041
+ return nil
1042
+ }
1043
+ return StopIteration {}
1044
+ })
1045
+ })
1046
+
1047
+ t .Run ("migrates an existing policy if migrate set to true" , func (t * testing.T ) {
1048
+ td := Setup (t )
1049
+
1050
+ p := createPolicy (td )
1051
+ p .Spec .Migrate = true
1052
+ err := td .Kube .Update (td .Ctx , p )
1053
+ td .Require .NoError (err , "update minio policy resource" )
1054
+ pb , err := json .Marshal (map [string ]any {"Version" : p .Spec .Version , "Statement" : p .Spec .Statement })
1055
+ td .Require .NoError (err , "marshal minio policy" )
1056
+ err = td .Madmin .AddCannedPolicy (td .Ctx , p .Spec .Name , pb )
1057
+ td .Require .NoError (err , "create minio policy" )
1058
+
1059
+ waitForReconcile (td , p )
1060
+ td .Require .False (p .Spec .Migrate , "migrate unset on reconcile" )
1061
+ })
1062
+
920
1063
t .Run ("deletes a minio policy" , func (t * testing.T ) {
921
1064
td := Setup (t )
922
1065
@@ -1106,6 +1249,51 @@ func TestMinioPolicyBinding(t *testing.T) {
1106
1249
td .Require .True (slices .Contains (pes .PolicyMappings [0 ].Users , pb .Spec .User .Builtin ))
1107
1250
})
1108
1251
1252
+ t .Run ("does not create a builtin user minio policy binding if one exists" , func (t * testing.T ) {
1253
+ td := Setup (t )
1254
+
1255
+ pb := createBuiltinUserPolicyBinding (td )
1256
+ waitForReconcile (td , pb )
1257
+ err := td .Kube .Delete (td .Ctx , pb )
1258
+ td .Require .NoError (err , "delete policy binding resource" )
1259
+ WaitForDelete (td , pb )
1260
+ _ , err = td .Madmin .AttachPolicy (td .Ctx , madmin.PolicyAssociationReq {Policies : []string {pb .Spec .Policy }, User : pb .Spec .User .Builtin })
1261
+ td .Require .NoError (err , "create policy binding" )
1262
+ pb = policyToBuiltinUser .DeepCopy ()
1263
+ err = td .Kube .Create (td .Ctx , pb )
1264
+ td .Require .NoError (err , "create policy binding resource" )
1265
+
1266
+ WaitForReconcilerError (td , func (err error ) error {
1267
+ merr , ok := err .(madmin.ErrorResponse )
1268
+ if ! ok {
1269
+ return nil
1270
+ }
1271
+ if merr .Code != "XMinioAdminPolicyChangeAlreadyApplied" {
1272
+ return nil
1273
+ }
1274
+ return StopIteration {}
1275
+ })
1276
+ })
1277
+
1278
+ t .Run ("migrates an existing builtin user policy binding if migrate set to true" , func (t * testing.T ) {
1279
+ td := Setup (t )
1280
+
1281
+ pb := createBuiltinUserPolicyBinding (td )
1282
+ waitForReconcile (td , pb )
1283
+ err := td .Kube .Delete (td .Ctx , pb )
1284
+ td .Require .NoError (err , "delete policy binding resource" )
1285
+ WaitForDelete (td , pb )
1286
+ _ , err = td .Madmin .AttachPolicy (td .Ctx , madmin.PolicyAssociationReq {Policies : []string {pb .Spec .Policy }, User : pb .Spec .User .Builtin })
1287
+ td .Require .NoError (err , "create policy binding" )
1288
+ pb = policyToBuiltinUser .DeepCopy ()
1289
+ pb .Spec .Migrate = true
1290
+ err = td .Kube .Create (td .Ctx , pb )
1291
+ td .Require .NoError (err , "create policy binding resource" )
1292
+
1293
+ waitForReconcile (td , pb )
1294
+ td .Require .False (pb .Spec .Migrate , "migrate unset on reconcile" )
1295
+ })
1296
+
1109
1297
t .Run ("creates an ldap group minio policy binding" , func (t * testing.T ) {
1110
1298
td := Setup (t )
1111
1299
SetMinioLDAPIdentityProvider (td )
@@ -1364,6 +1552,37 @@ func TestMinioUser(t *testing.T) {
1364
1552
td .Require .NoError (err , "check if user credentials valid" )
1365
1553
})
1366
1554
1555
+ t .Run ("does not create a minio group if one exists" , func (t * testing.T ) {
1556
+ td := Setup (t )
1557
+
1558
+ u := createUser (td )
1559
+ sk := builtinUserSecret .StringData ["SecretKey" ]
1560
+ err := td .Madmin .AddUser (td .Ctx , u .Spec .AccessKey , sk )
1561
+ td .Require .NoError (err , "create minio user" )
1562
+
1563
+ WaitForReconcilerError (td , func (err error ) error {
1564
+ if err .Error () != fmt .Sprintf ("user %s already exists" , u .Spec .AccessKey ) {
1565
+ return nil
1566
+ }
1567
+ return StopIteration {}
1568
+ })
1569
+ })
1570
+
1571
+ t .Run ("migrates an existing group if migrate set to true" , func (t * testing.T ) {
1572
+ td := Setup (t )
1573
+
1574
+ u := createUser (td )
1575
+ sk := builtinUserSecret .StringData ["SecretKey" ]
1576
+ err := td .Madmin .AddUser (td .Ctx , u .Spec .AccessKey , string (sk ))
1577
+ td .Require .NoError (err , "create minio user" )
1578
+ u .Spec .Migrate = true
1579
+ err = td .Kube .Update (td .Ctx , u )
1580
+ td .Require .NoError (err , "update user resource" )
1581
+
1582
+ waitForReconcile (td , u )
1583
+ td .Require .False (u .Spec .Migrate , "migrate unset on reconcile" )
1584
+ })
1585
+
1367
1586
t .Run ("deletes a minio user" , func (t * testing.T ) {
1368
1587
td := Setup (t )
1369
1588
0 commit comments