github.com/operator-framework/operator-lifecycle-manager@v0.30.0/test/e2e/dynamic_resource_e2e_test.go (about) 1 package e2e 2 3 import ( 4 "context" 5 "strings" 6 7 corev1 "k8s.io/api/core/v1" 8 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 9 "k8s.io/apimachinery/pkg/runtime/schema" 10 "k8s.io/client-go/dynamic" 11 12 . "github.com/onsi/ginkgo/v2" 13 . "github.com/onsi/gomega" 14 "github.com/operator-framework/api/pkg/operators/v1alpha1" 15 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned" 16 "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry" 17 "github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx" 18 ) 19 20 // This test was disabled because both of its tests are currently being skipped 21 // We need to understand why and whether this test is even needed: 22 // https://github.com/operator-framework/operator-lifecycle-manager/issues/3402 23 var _ = XDescribe("Subscriptions create required objects from Catalogs", func() { 24 var ( 25 crc versioned.Interface 26 generatedNamespace corev1.Namespace 27 dynamicClient dynamic.Interface 28 deleteOpts *metav1.DeleteOptions 29 ) 30 31 BeforeEach(func() { 32 crc = ctx.Ctx().OperatorClient() 33 dynamicClient = ctx.Ctx().DynamicClient() 34 35 deleteOpts = &metav1.DeleteOptions{} 36 generatedNamespace = SetupGeneratedTestNamespace(genName("dynamic-resource-e2e-")) 37 }) 38 39 AfterEach(func() { 40 TearDown(generatedNamespace.GetName()) 41 }) 42 43 Context("Given a Namespace", func() { 44 When("a CatalogSource is created with a bundle that contains prometheus objects", func() { 45 Context("creating a subscription using the CatalogSource", func() { 46 var ( 47 catsrc *v1alpha1.CatalogSource 48 subName string 49 cleanupSub cleanupFunc 50 ) 51 52 BeforeEach(func() { 53 54 By("Create CatalogSource") 55 catsrc = &v1alpha1.CatalogSource{ 56 ObjectMeta: metav1.ObjectMeta{ 57 Name: genName("dynamic-catalog-"), 58 Namespace: generatedNamespace.GetName(), 59 }, 60 Spec: v1alpha1.CatalogSourceSpec{ 61 Image: "quay.io/olmtest/catsrc_dynamic_resources:e2e-test", 62 SourceType: v1alpha1.SourceTypeGrpc, 63 GrpcPodConfig: &v1alpha1.GrpcPodConfig{ 64 SecurityContextConfig: v1alpha1.Restricted, 65 }, 66 }, 67 } 68 69 catsrc, err := crc.OperatorsV1alpha1().CatalogSources(catsrc.GetNamespace()).Create(context.TODO(), catsrc, metav1.CreateOptions{}) 70 Expect(err).NotTo(HaveOccurred()) 71 72 By("Wait for the CatalogSource to be ready") 73 _, err = fetchCatalogSourceOnStatus(crc, catsrc.GetName(), catsrc.GetNamespace(), catalogSourceRegistryPodSynced()) 74 Expect(err).NotTo(HaveOccurred()) 75 76 By("Generate a Subscription") 77 subName = genName("dynamic-resources") 78 cleanupSub = createSubscriptionForCatalog(crc, catsrc.GetNamespace(), subName, catsrc.GetName(), "etcd", "singlenamespace-alpha", "", v1alpha1.ApprovalAutomatic) 79 80 }) 81 82 AfterEach(func() { 83 84 By("clean up subscription") 85 if cleanupSub != nil { 86 cleanupSub() 87 } 88 89 By("Delete CatalogSource") 90 if catsrc != nil { 91 err := crc.OperatorsV1alpha1().CatalogSources(catsrc.GetNamespace()).Delete(context.TODO(), catsrc.GetName(), *deleteOpts) 92 Expect(err).NotTo(HaveOccurred()) 93 } 94 95 }) 96 97 It("should install the operator successfully", func() { 98 Skip("this test disabled pending fix of the v1 CRD feature") 99 _, err := fetchSubscription(crc, catsrc.GetNamespace(), subName, subscriptionHasInstallPlanChecker()) 100 Expect(err).NotTo(HaveOccurred()) 101 }) 102 103 It("should have created the expected prometheus objects", func() { 104 Skip("this test disabled pending fix of the v1 CRD feature") 105 sub, err := fetchSubscription(crc, catsrc.GetNamespace(), subName, subscriptionHasInstallPlanChecker()) 106 Expect(err).NotTo(HaveOccurred()) 107 108 ipName := sub.Status.InstallPlanRef.Name 109 ip, err := waitForInstallPlan(crc, ipName, sub.GetNamespace(), buildInstallPlanPhaseCheckFunc(v1alpha1.InstallPlanPhaseFailed, v1alpha1.InstallPlanPhaseComplete)) 110 Expect(err).NotTo(HaveOccurred()) 111 112 By("Ensure the InstallPlan contains the steps resolved from the bundle image") 113 expectedSteps := map[registry.ResourceKey]struct{}{ 114 {Name: "my-prometheusrule", Kind: "PrometheusRule"}: {}, 115 {Name: "my-servicemonitor", Kind: "ServiceMonitor"}: {}, 116 } 117 118 By("Verify Resource steps match expected steps") 119 for _, step := range ip.Status.Plan { 120 key := registry.ResourceKey{ 121 Name: step.Resource.Name, 122 Kind: step.Resource.Kind, 123 } 124 for expected := range expectedSteps { 125 if strings.HasPrefix(key.Name, expected.Name) && key.Kind == expected.Kind { 126 delete(expectedSteps, expected) 127 } 128 } 129 } 130 Expect(len(expectedSteps)).To(BeZero(), "Resource steps do not match expected: %#v", expectedSteps) 131 132 By("Confirm that the expected types exist") 133 gvr := schema.GroupVersionResource{ 134 Group: "monitoring.coreos.com", 135 Version: "v1", 136 Resource: "prometheusrules", 137 } 138 139 err = waitForGVR(dynamicClient, gvr, "my-prometheusrule", generatedNamespace.GetName()) 140 Expect(err).NotTo(HaveOccurred()) 141 142 gvr.Resource = "servicemonitors" 143 err = waitForGVR(dynamicClient, gvr, "my-servicemonitor", generatedNamespace.GetName()) 144 Expect(err).NotTo(HaveOccurred()) 145 }) 146 }) 147 }) 148 149 }) 150 151 })