github.com/operator-framework/operator-lifecycle-manager@v0.30.0/test/e2e/catalog_exclusion_test.go (about) 1 package e2e 2 3 import ( 4 "context" 5 "path/filepath" 6 7 . "github.com/onsi/ginkgo/v2" 8 . "github.com/onsi/gomega" 9 operatorsv1 "github.com/operator-framework/api/pkg/operators/v1" 10 "github.com/operator-framework/api/pkg/operators/v1alpha1" 11 "github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx" 12 "github.com/operator-framework/operator-lifecycle-manager/test/e2e/util" 13 . "github.com/operator-framework/operator-lifecycle-manager/test/e2e/util/gomega" 14 "google.golang.org/grpc/connectivity" 15 corev1 "k8s.io/api/core/v1" 16 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 17 k8scontrollerclient "sigs.k8s.io/controller-runtime/pkg/client" 18 ) 19 20 const magicCatalogDir = "magiccatalog" 21 22 var _ = Describe("Global Catalog Exclusion", func() { 23 var ( 24 generatedNamespace corev1.Namespace 25 determinedE2eClient *util.DeterminedE2EClient 26 operatorGroup operatorsv1.OperatorGroup 27 localCatalog *MagicCatalog 28 ) 29 30 BeforeEach(func() { 31 determinedE2eClient = util.NewDeterminedClient(ctx.Ctx().E2EClient()) 32 33 By("creating a namespace with an own namespace operator group without annotations") 34 e2eTestNamespace := genName("global-catalog-exclusion-e2e-") 35 operatorGroup = operatorsv1.OperatorGroup{ 36 ObjectMeta: metav1.ObjectMeta{ 37 Namespace: e2eTestNamespace, 38 Name: genName("og-"), 39 Annotations: nil, 40 }, 41 Spec: operatorsv1.OperatorGroupSpec{ 42 TargetNamespaces: []string{e2eTestNamespace}, 43 }, 44 } 45 generatedNamespace = SetupGeneratedTestNamespaceWithOperatorGroup(e2eTestNamespace, operatorGroup) 46 47 By("creating a broken catalog in the global namespace") 48 globalCatalog := &v1alpha1.CatalogSource{ 49 ObjectMeta: metav1.ObjectMeta{ 50 Name: genName("bad-global-catalog-"), 51 Namespace: globalCatalogNamespace, 52 }, 53 Spec: v1alpha1.CatalogSourceSpec{ 54 DisplayName: "Broken Global Catalog Source", 55 SourceType: v1alpha1.SourceTypeGrpc, 56 Address: "1.1.1.1:1337", // points to non-existing service 57 GrpcPodConfig: &v1alpha1.GrpcPodConfig{ 58 SecurityContextConfig: v1alpha1.Restricted, 59 }, 60 }, 61 } 62 _ = determinedE2eClient.Create(context.Background(), globalCatalog) 63 64 By("creating a healthy catalog in the test namespace") 65 localCatalogName := genName("good-catsrc-") 66 var err error = nil 67 68 fbcPath := filepath.Join(testdataDir, magicCatalogDir, "fbc_initial.yaml") 69 localCatalog, err = NewMagicCatalogFromFile(determinedE2eClient, generatedNamespace.GetName(), localCatalogName, fbcPath) 70 Expect(err).To(Succeed()) 71 72 By("deploy catalog blocks until the catalog has reached a ready state or fails") 73 Expect(localCatalog.DeployCatalog(context.Background())).To(Succeed()) 74 75 By("checking that the global catalog is broken") 76 By("Adding this check here to speed up the test") 77 By("the global catalog can fail while we wait for the local catalog to get to a ready state") 78 EventuallyResource(globalCatalog).Should(HaveGrpcConnectionWithLastConnectionState(connectivity.TransientFailure)) 79 }) 80 81 AfterEach(func() { 82 TeardownNamespace(generatedNamespace.GetName()) 83 }) 84 85 When("a subscription referring to the local catalog is created", func() { 86 var subscription *v1alpha1.Subscription 87 88 BeforeEach(func() { 89 subscription = &v1alpha1.Subscription{ 90 ObjectMeta: metav1.ObjectMeta{ 91 Namespace: generatedNamespace.GetName(), 92 Name: genName("local-subscription-"), 93 }, 94 Spec: &v1alpha1.SubscriptionSpec{ 95 CatalogSource: localCatalog.GetName(), 96 CatalogSourceNamespace: localCatalog.GetNamespace(), 97 Package: "test-package", 98 Channel: "stable", 99 InstallPlanApproval: v1alpha1.ApprovalAutomatic, 100 }, 101 } 102 103 By("creating a subscription") 104 _ = determinedE2eClient.Create(context.Background(), subscription) 105 }) 106 107 When("the operator group is annotated with olm.operatorframework.io/exclude-global-namespace-resolution=true", func() { 108 109 It("the broken subscription should resolve and have state AtLatest", func() { 110 By("checking that the subscription is not resolving and has a condition with type ResolutionFailed") 111 EventuallyResource(subscription).Should(ContainSubscriptionConditionOfType(v1alpha1.SubscriptionResolutionFailed)) 112 113 By("annotating the operator group with olm.operatorframework.io/exclude-global-namespace-resolution=true") 114 Eventually(func() error { 115 annotatedOperatorGroup := operatorGroup.DeepCopy() 116 if err := determinedE2eClient.Get(context.Background(), k8scontrollerclient.ObjectKeyFromObject(annotatedOperatorGroup), annotatedOperatorGroup); err != nil { 117 return err 118 } 119 120 if annotatedOperatorGroup.Annotations == nil { 121 annotatedOperatorGroup.Annotations = map[string]string{} 122 } 123 124 annotatedOperatorGroup.Annotations["olm.operatorframework.io/exclude-global-namespace-resolution"] = "true" 125 if err := determinedE2eClient.Update(context.Background(), annotatedOperatorGroup); err != nil { 126 return err 127 } 128 return nil 129 }).Should(Succeed()) 130 131 By("checking that the subscription resolves and has state AtLatest") 132 EventuallyResource(subscription).Should(HaveSubscriptionState(v1alpha1.SubscriptionStateAtLatest)) 133 }) 134 }) 135 }) 136 })