8
8
"crypto/x509"
9
9
"crypto/x509/pkix"
10
10
"encoding/pem"
11
+ "errors"
11
12
"fmt"
12
13
"math"
13
14
"math/big"
@@ -51,6 +52,9 @@ import (
51
52
52
53
operatorsv1 "github.com/operator-framework/api/pkg/operators/v1"
53
54
"github.com/operator-framework/api/pkg/operators/v1alpha1"
55
+ opregistry "github.com/operator-framework/operator-registry/pkg/registry"
56
+ clienttesting "k8s.io/client-go/testing"
57
+
54
58
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
55
59
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned/fake"
56
60
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/certs"
@@ -65,8 +69,6 @@ import (
65
69
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/ownerutil"
66
70
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/queueinformer"
67
71
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/scoped"
68
- opregistry "github.com/operator-framework/operator-registry/pkg/registry"
69
- clienttesting "k8s.io/client-go/testing"
70
72
)
71
73
72
74
type TestStrategy struct {}
@@ -4518,6 +4520,304 @@ func TestSyncOperatorGroups(t *testing.T) {
4518
4520
LastUpdated : & now ,
4519
4521
},
4520
4522
},
4523
+ {
4524
+ name : "MatchingNamespace/NoCSVs/CreatesClusterRoles" ,
4525
+ expectedEqual : true ,
4526
+ initial : initial {
4527
+ operatorGroup : & operatorsv1.OperatorGroup {
4528
+ ObjectMeta : metav1.ObjectMeta {
4529
+ Name : "operator-group-1" ,
4530
+ Namespace : operatorNamespace ,
4531
+ },
4532
+ Spec : operatorsv1.OperatorGroupSpec {
4533
+ Selector : & metav1.LabelSelector {
4534
+ MatchLabels : map [string ]string {"app" : "app-a" },
4535
+ },
4536
+ },
4537
+ },
4538
+ k8sObjs : []runtime.Object {
4539
+ & corev1.Namespace {
4540
+ ObjectMeta : metav1.ObjectMeta {
4541
+ Name : operatorNamespace ,
4542
+ },
4543
+ },
4544
+ & corev1.Namespace {
4545
+ ObjectMeta : metav1.ObjectMeta {
4546
+ Name : targetNamespace ,
4547
+ Labels : map [string ]string {"app" : "app-a" },
4548
+ },
4549
+ },
4550
+ },
4551
+ },
4552
+ expectedStatus : operatorsv1.OperatorGroupStatus {
4553
+ Namespaces : []string {targetNamespace },
4554
+ LastUpdated : & now ,
4555
+ },
4556
+ final : final {objects : map [string ][]runtime.Object {
4557
+ "" : {
4558
+ & rbacv1.ClusterRole {
4559
+ ObjectMeta : metav1.ObjectMeta {
4560
+ ResourceVersion : "" ,
4561
+ Name : "olm.operatorgroup.admin-aaaaa" ,
4562
+ Labels : map [string ]string {
4563
+ "olm.owner" : "operator-group-1" ,
4564
+ "olm.owner.namespace" : "operator-ns" ,
4565
+ "olm.owner.kind" : "OperatorGroup" ,
4566
+ "olm.operatorgroup.rolelevel" : "admin" ,
4567
+ },
4568
+ },
4569
+ },
4570
+ & rbacv1.ClusterRole {
4571
+ ObjectMeta : metav1.ObjectMeta {
4572
+ ResourceVersion : "" ,
4573
+ Name : "olm.operatorgroup.edit-aaaaa" ,
4574
+ Labels : map [string ]string {
4575
+ "olm.owner" : "operator-group-1" ,
4576
+ "olm.owner.namespace" : "operator-ns" ,
4577
+ "olm.owner.kind" : "OperatorGroup" ,
4578
+ "olm.operatorgroup.rolelevel" : "edit" ,
4579
+ },
4580
+ },
4581
+ },
4582
+ & rbacv1.ClusterRole {
4583
+ ObjectMeta : metav1.ObjectMeta {
4584
+ ResourceVersion : "" ,
4585
+ Name : "olm.operatorgroup.view-aaaaa" ,
4586
+ Labels : map [string ]string {
4587
+ "olm.owner" : "operator-group-1" ,
4588
+ "olm.owner.namespace" : "operator-ns" ,
4589
+ "olm.owner.kind" : "OperatorGroup" ,
4590
+ "olm.operatorgroup.rolelevel" : "view" ,
4591
+ },
4592
+ },
4593
+ },
4594
+ },
4595
+ }},
4596
+ },
4597
+ {
4598
+ // check that even if old cluster roles exist, we create the new ones and leave the old ones unchanged
4599
+ name : "MatchingNamespace/NoCSVs/UpdatesOldClusterRoles" ,
4600
+ expectedEqual : true ,
4601
+ initial : initial {
4602
+ operatorGroup : & operatorsv1.OperatorGroup {
4603
+ ObjectMeta : metav1.ObjectMeta {
4604
+ Name : "operator-group-1" ,
4605
+ Namespace : operatorNamespace ,
4606
+ },
4607
+ Spec : operatorsv1.OperatorGroupSpec {
4608
+ Selector : & metav1.LabelSelector {
4609
+ MatchLabels : map [string ]string {"app" : "app-a" },
4610
+ },
4611
+ },
4612
+ },
4613
+ k8sObjs : []runtime.Object {
4614
+ & corev1.Namespace {
4615
+ ObjectMeta : metav1.ObjectMeta {
4616
+ Name : operatorNamespace ,
4617
+ },
4618
+ },
4619
+ & corev1.Namespace {
4620
+ ObjectMeta : metav1.ObjectMeta {
4621
+ Name : targetNamespace ,
4622
+ Labels : map [string ]string {"app" : "app-a" },
4623
+ },
4624
+ },
4625
+ & rbacv1.ClusterRole {
4626
+ ObjectMeta : metav1.ObjectMeta {
4627
+ ResourceVersion : "" ,
4628
+ Name : "operator-group-1-admin" ,
4629
+ Labels : map [string ]string {
4630
+ "olm.owner" : "operator-group-1" ,
4631
+ "olm.owner.namespace" : "operator-ns" ,
4632
+ "olm.owner.kind" : "OperatorGroup" ,
4633
+ },
4634
+ },
4635
+ },
4636
+ & rbacv1.ClusterRole {
4637
+ ObjectMeta : metav1.ObjectMeta {
4638
+ ResourceVersion : "" ,
4639
+ Name : "operator-group-1-view" ,
4640
+ Labels : map [string ]string {
4641
+ "olm.owner" : "operator-group-1" ,
4642
+ "olm.owner.namespace" : "operator-ns" ,
4643
+ "olm.owner.kind" : "OperatorGroup" ,
4644
+ },
4645
+ },
4646
+ },
4647
+ & rbacv1.ClusterRole {
4648
+ ObjectMeta : metav1.ObjectMeta {
4649
+ ResourceVersion : "" ,
4650
+ Name : "operator-group-1-edit" ,
4651
+ Labels : map [string ]string {
4652
+ "olm.owner" : "operator-group-1" ,
4653
+ "olm.owner.namespace" : "operator-ns" ,
4654
+ "olm.owner.kind" : "OperatorGroup" ,
4655
+ },
4656
+ },
4657
+ },
4658
+ },
4659
+ },
4660
+ expectedStatus : operatorsv1.OperatorGroupStatus {
4661
+ Namespaces : []string {targetNamespace },
4662
+ LastUpdated : & now ,
4663
+ },
4664
+ final : final {objects : map [string ][]runtime.Object {
4665
+ "" : {
4666
+ & rbacv1.ClusterRole {
4667
+ ObjectMeta : metav1.ObjectMeta {
4668
+ ResourceVersion : "" ,
4669
+ Name : "olm.operatorgroup.admin-aaaaa" ,
4670
+ Labels : map [string ]string {
4671
+ "olm.owner" : "operator-group-1" ,
4672
+ "olm.owner.namespace" : "operator-ns" ,
4673
+ "olm.owner.kind" : "OperatorGroup" ,
4674
+ "olm.operatorgroup.rolelevel" : "admin" ,
4675
+ },
4676
+ },
4677
+ },
4678
+ & rbacv1.ClusterRole {
4679
+ ObjectMeta : metav1.ObjectMeta {
4680
+ ResourceVersion : "" ,
4681
+ Name : "olm.operatorgroup.edit-aaaaa" ,
4682
+ Labels : map [string ]string {
4683
+ "olm.owner" : "operator-group-1" ,
4684
+ "olm.owner.namespace" : "operator-ns" ,
4685
+ "olm.owner.kind" : "OperatorGroup" ,
4686
+ "olm.operatorgroup.rolelevel" : "edit" ,
4687
+ },
4688
+ },
4689
+ },
4690
+ & rbacv1.ClusterRole {
4691
+ ObjectMeta : metav1.ObjectMeta {
4692
+ ResourceVersion : "" ,
4693
+ Name : "olm.operatorgroup.view-aaaaa" ,
4694
+ Labels : map [string ]string {
4695
+ "olm.owner" : "operator-group-1" ,
4696
+ "olm.owner.namespace" : "operator-ns" ,
4697
+ "olm.owner.kind" : "OperatorGroup" ,
4698
+ "olm.operatorgroup.rolelevel" : "view" ,
4699
+ },
4700
+ },
4701
+ },
4702
+ & rbacv1.ClusterRole {
4703
+ ObjectMeta : metav1.ObjectMeta {
4704
+ ResourceVersion : "" ,
4705
+ Name : "operator-group-1-admin" ,
4706
+ Labels : map [string ]string {
4707
+ "olm.owner" : "operator-group-1" ,
4708
+ "olm.owner.namespace" : "operator-ns" ,
4709
+ "olm.owner.kind" : "OperatorGroup" ,
4710
+ },
4711
+ },
4712
+ },
4713
+ & rbacv1.ClusterRole {
4714
+ ObjectMeta : metav1.ObjectMeta {
4715
+ ResourceVersion : "" ,
4716
+ Name : "operator-group-1-view" ,
4717
+ Labels : map [string ]string {
4718
+ "olm.owner" : "operator-group-1" ,
4719
+ "olm.owner.namespace" : "operator-ns" ,
4720
+ "olm.owner.kind" : "OperatorGroup" ,
4721
+ },
4722
+ },
4723
+ },
4724
+ & rbacv1.ClusterRole {
4725
+ ObjectMeta : metav1.ObjectMeta {
4726
+ ResourceVersion : "" ,
4727
+ Name : "operator-group-1-edit" ,
4728
+ Labels : map [string ]string {
4729
+ "olm.owner" : "operator-group-1" ,
4730
+ "olm.owner.namespace" : "operator-ns" ,
4731
+ "olm.owner.kind" : "OperatorGroup" ,
4732
+ },
4733
+ },
4734
+ },
4735
+ },
4736
+ }},
4737
+ },
4738
+ {
4739
+ name : "MatchingNamespace/NoCSVs/Updates" +
4740
+ "" +
4741
+ "" +
4742
+ "" +
4743
+ "" +
4744
+ "" +
4745
+ "" +
4746
+ "" +
4747
+ "ClusterRoles" ,
4748
+ expectedEqual : true ,
4749
+ initial : initial {
4750
+ operatorGroup : & operatorsv1.OperatorGroup {
4751
+ ObjectMeta : metav1.ObjectMeta {
4752
+ Name : "operator-group-1" ,
4753
+ Namespace : operatorNamespace ,
4754
+ UID : "1234" ,
4755
+ },
4756
+ Spec : operatorsv1.OperatorGroupSpec {
4757
+ Selector : & metav1.LabelSelector {
4758
+ MatchLabels : map [string ]string {"app" : "app-a" },
4759
+ },
4760
+ },
4761
+ },
4762
+ k8sObjs : []runtime.Object {
4763
+ & corev1.Namespace {
4764
+ ObjectMeta : metav1.ObjectMeta {
4765
+ Name : operatorNamespace ,
4766
+ },
4767
+ },
4768
+ & corev1.Namespace {
4769
+ ObjectMeta : metav1.ObjectMeta {
4770
+ Name : targetNamespace ,
4771
+ Labels : map [string ]string {"app" : "app-a" },
4772
+ },
4773
+ },
4774
+ },
4775
+ },
4776
+ expectedStatus : operatorsv1.OperatorGroupStatus {
4777
+ Namespaces : []string {targetNamespace },
4778
+ LastUpdated : & now ,
4779
+ },
4780
+ final : final {objects : map [string ][]runtime.Object {
4781
+ "" : {
4782
+ & rbacv1.ClusterRole {
4783
+ ObjectMeta : metav1.ObjectMeta {
4784
+ ResourceVersion : "" ,
4785
+ Name : "olm.operatorgroup.admin-aaaaa" ,
4786
+ Labels : map [string ]string {
4787
+ "olm.owner" : "1234" ,
4788
+ "olm.owner.namespace" : "operator-ns" ,
4789
+ "olm.owner.kind" : "OperatorGroup" ,
4790
+ "olm.operatorgroup.rolelevel" : "admin" ,
4791
+ },
4792
+ },
4793
+ },
4794
+ & rbacv1.ClusterRole {
4795
+ ObjectMeta : metav1.ObjectMeta {
4796
+ ResourceVersion : "" ,
4797
+ Name : "olm.operatorgroup.edit-aaaaa" ,
4798
+ Labels : map [string ]string {
4799
+ "olm.owner" : "1234" ,
4800
+ "olm.owner.namespace" : "operator-ns" ,
4801
+ "olm.owner.kind" : "OperatorGroup" ,
4802
+ "olm.operatorgroup.rolelevel" : "edit" ,
4803
+ },
4804
+ },
4805
+ },
4806
+ & rbacv1.ClusterRole {
4807
+ ObjectMeta : metav1.ObjectMeta {
4808
+ ResourceVersion : "" ,
4809
+ Name : "olm.operatorgroup.view-aaaaa" ,
4810
+ Labels : map [string ]string {
4811
+ "olm.owner" : "1234" ,
4812
+ "olm.owner.namespace" : "operator-ns" ,
4813
+ "olm.owner.kind" : "OperatorGroup" ,
4814
+ "olm.operatorgroup.rolelevel" : "view" ,
4815
+ },
4816
+ },
4817
+ },
4818
+ },
4819
+ }},
4820
+ },
4521
4821
{
4522
4822
name : "MatchingNamespace/CSVPresent/Found" ,
4523
4823
expectedEqual : true ,
@@ -4967,6 +5267,10 @@ func TestSyncOperatorGroups(t *testing.T) {
4967
5267
return copied
4968
5268
}
4969
5269
5270
+ // change the genName function to return a predictable value
5271
+ genName = func (prefix string ) string {
5272
+ return fmt .Sprintf ("%saaaaa" , prefix )
5273
+ }
4970
5274
for _ , tt := range tests {
4971
5275
t .Run (tt .name , func (t * testing.T ) {
4972
5276
// Pick out Namespaces
@@ -5106,7 +5410,10 @@ func TestSyncOperatorGroups(t *testing.T) {
5106
5410
for namespace , objects := range tt .final .objects {
5107
5411
if err := RequireObjectsInCache (t , op .lister , namespace , objects , true ); err != nil {
5108
5412
foundErr = err
5109
- return false , nil
5413
+ if apierrors .IsNotFound (err ) {
5414
+ return false , nil
5415
+ }
5416
+ return false , err
5110
5417
}
5111
5418
}
5112
5419
@@ -5349,7 +5656,10 @@ func RequireObjectsInCache(t *testing.T, lister operatorlister.OperatorLister, n
5349
5656
require .Failf (t , "couldn't find expected object" , "%#v" , object )
5350
5657
}
5351
5658
if err != nil {
5352
- return fmt .Errorf ("namespace: %v, error: %v" , namespace , err )
5659
+ if apierrors .IsNotFound (err ) {
5660
+ return err
5661
+ }
5662
+ return errors .Join (err , fmt .Errorf ("namespace: %v, error: %v" , namespace , err ))
5353
5663
}
5354
5664
if doCompare {
5355
5665
if ! reflect .DeepEqual (object , fetched ) {
0 commit comments