|
| 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 | + testNamespace 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 | + testNamespace = 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: operatorNamespace, |
| 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 | + }, |
| 58 | + } |
| 59 | + _ = determinedE2eClient.Create(context.Background(), globalCatalog) |
| 60 | + |
| 61 | + By("creating a healthy catalog in the test namespace") |
| 62 | + localCatalogName := genName("good-catsrc-") |
| 63 | + var err error = nil |
| 64 | + |
| 65 | + fbcPath := filepath.Join(testdataDir, magicCatalogDir, "fbc_initial.yaml") |
| 66 | + localCatalog, err = NewMagicCatalogFromFile(determinedE2eClient, testNamespace.GetName(), localCatalogName, fbcPath) |
| 67 | + Expect(err).To(Succeed()) |
| 68 | + |
| 69 | + // deploy catalog blocks until the catalog has reached a ready state or fails |
| 70 | + Expect(localCatalog.DeployCatalog(context.Background())).To(Succeed()) |
| 71 | + |
| 72 | + By("checking that the global catalog is broken") |
| 73 | + // Adding this check here to speed up the test |
| 74 | + // the global catalog can fail while we wait for the local catalog to get to a ready state |
| 75 | + EventuallyResource(globalCatalog).Should(HaveGrpcConnectionWithLastConnectionState(connectivity.TransientFailure)) |
| 76 | + }) |
| 77 | + |
| 78 | + AfterEach(func() { |
| 79 | + TeardownNamespace(testNamespace.GetName()) |
| 80 | + }) |
| 81 | + |
| 82 | + When("a subscription referring to the local catalog is created", func() { |
| 83 | + var subscription *v1alpha1.Subscription |
| 84 | + |
| 85 | + BeforeEach(func() { |
| 86 | + subscription = &v1alpha1.Subscription{ |
| 87 | + ObjectMeta: metav1.ObjectMeta{ |
| 88 | + Namespace: testNamespace.GetName(), |
| 89 | + Name: genName("local-subscription-"), |
| 90 | + }, |
| 91 | + Spec: &v1alpha1.SubscriptionSpec{ |
| 92 | + CatalogSource: localCatalog.GetName(), |
| 93 | + CatalogSourceNamespace: localCatalog.GetNamespace(), |
| 94 | + Package: "packageA", |
| 95 | + Channel: "stable", |
| 96 | + InstallPlanApproval: v1alpha1.ApprovalAutomatic, |
| 97 | + }, |
| 98 | + } |
| 99 | + |
| 100 | + By("creating a subscription") |
| 101 | + _ = determinedE2eClient.Create(context.Background(), subscription) |
| 102 | + }) |
| 103 | + |
| 104 | + When("the operator group is annotated with olm.operatorframework.io/exclude-global-namespace-resolution=true", func() { |
| 105 | + |
| 106 | + It("the broken subscription should resolve and have state AtLatest", func() { |
| 107 | + By("checking that the subscription is not resolving and has a condition with type ResolutionFailed") |
| 108 | + EventuallyResource(subscription).Should(ContainSubscriptionConditionOfType(v1alpha1.SubscriptionResolutionFailed)) |
| 109 | + |
| 110 | + By("annotating the operator group with olm.operatorframework.io/exclude-global-namespace-resolution=true") |
| 111 | + Eventually(func() error { |
| 112 | + annotatedOperatorGroup := operatorGroup.DeepCopy() |
| 113 | + if err := determinedE2eClient.Get(context.Background(), k8scontrollerclient.ObjectKeyFromObject(annotatedOperatorGroup), annotatedOperatorGroup); err != nil { |
| 114 | + return err |
| 115 | + } |
| 116 | + |
| 117 | + if annotatedOperatorGroup.Annotations == nil { |
| 118 | + annotatedOperatorGroup.Annotations = map[string]string{} |
| 119 | + } |
| 120 | + |
| 121 | + annotatedOperatorGroup.Annotations["olm.operatorframework.io/exclude-global-namespace-resolution"] = "true" |
| 122 | + if err := determinedE2eClient.Update(context.Background(), annotatedOperatorGroup); err != nil { |
| 123 | + return err |
| 124 | + } |
| 125 | + return nil |
| 126 | + }).Should(Succeed()) |
| 127 | + |
| 128 | + By("checking that the subscription resolves and has state AtLatest") |
| 129 | + EventuallyResource(subscription).Should(HaveSubscriptionState(v1alpha1.SubscriptionStateAtLatest)) |
| 130 | + }) |
| 131 | + }) |
| 132 | + }) |
| 133 | +}) |
0 commit comments