github.com/operator-framework/operator-lifecycle-manager@v0.30.0/test/e2e/e2e_test.go (about) 1 package e2e 2 3 import ( 4 "context" 5 "flag" 6 "fmt" 7 "os" 8 "path" 9 "strconv" 10 "testing" 11 "time" 12 13 . "github.com/onsi/ginkgo/v2" 14 . "github.com/onsi/gomega" 15 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 16 "sigs.k8s.io/controller-runtime/pkg/client" 17 "sigs.k8s.io/controller-runtime/pkg/log" 18 "sigs.k8s.io/controller-runtime/pkg/log/zap" 19 20 operatorsv1 "github.com/operator-framework/api/pkg/operators/v1" 21 "github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx" 22 ) 23 24 func init() { 25 log.SetLogger(zap.New()) 26 } 27 28 var ( 29 kubeConfigPath = flag.String( 30 "kubeconfig", "", "path to the kubeconfig file") 31 32 namespace = flag.String( 33 "namespace", "", "namespace where tests will run") 34 35 olmNamespace = flag.String( 36 "olmNamespace", "", "namespace where olm is running") 37 38 catalogNamespace = flag.String( 39 "catalogNamespace", "", "namespace where the global catalog content is stored") 40 41 communityOperators = flag.String( 42 "communityOperators", 43 "quay.io/operatorhubio/catalog:latest", 44 "reference to upstream-community-operators image", 45 ) 46 47 dummyImage = flag.String( 48 "dummyImage", 49 "bitnami/nginx:latest", 50 "dummy image to treat as an operator in tests", 51 ) 52 53 collectArtifactsScriptPath = flag.String( 54 "gather-artifacts-script-path", 55 "./collect-ci-artifacts.sh", 56 "configures the relative/absolute path to the script responsible for collecting CI artifacts", 57 ) 58 59 testdataPath = flag.String( 60 "test-data-dir", 61 "./testdata", 62 "configures where to find the testdata directory", 63 ) 64 65 kubeconfigRootDir = flag.String( 66 "kubeconfig-root", 67 "", 68 "configures the root directory for kubeconfig files when running tests in parallel. "+ 69 "Each test worker will expect their kubeconfig file to be <kubeconfig-root>/kubeconfig-<test-number>. "+ 70 "Where, <test-number> is the number of the test worker (> 0). "+ 71 "Note that this flag will override the kubeconfig flag.", 72 ) 73 74 testdataDir = "" 75 testNamespace = "" 76 operatorNamespace = "" 77 communityOperatorsImage = "" 78 globalCatalogNamespace = "" 79 ) 80 81 func TestEndToEnd(t *testing.T) { 82 RegisterFailHandler(Fail) 83 SetDefaultEventuallyTimeout(1 * time.Minute) 84 SetDefaultEventuallyPollingInterval(1 * time.Second) 85 SetDefaultConsistentlyDuration(30 * time.Second) 86 SetDefaultConsistentlyPollingInterval(1 * time.Second) 87 88 RunSpecs(t, "End-to-end") 89 } 90 91 var deprovision func() = func() {} 92 93 // This function initializes a client which is used to create an operator group for a given namespace 94 var _ = BeforeSuite(func() { 95 if kubeconfigRootDir != nil && *kubeconfigRootDir != "" { 96 os.Setenv("KUBECONFIG", path.Join(*kubeconfigRootDir, "kubeconfig-"+strconv.Itoa(GinkgoParallelProcess()))) 97 } else if kubeConfigPath != nil && *kubeConfigPath != "" { 98 os.Setenv("KUBECONFIG", *kubeConfigPath) 99 } 100 101 if collectArtifactsScriptPath != nil && *collectArtifactsScriptPath != "" { 102 os.Setenv("E2E_ARTIFACT_SCRIPT", *collectArtifactsScriptPath) 103 } 104 105 testNamespace = *namespace 106 operatorNamespace = *olmNamespace 107 communityOperatorsImage = *communityOperators 108 globalCatalogNamespace = *catalogNamespace 109 testdataDir = *testdataPath 110 deprovision = ctx.MustProvision(ctx.Ctx()) 111 ctx.MustInstall(ctx.Ctx()) 112 113 var groups operatorsv1.OperatorGroupList 114 Expect(ctx.Ctx().Client().List(context.Background(), &groups, client.InNamespace(testNamespace))).To(Succeed()) 115 if len(groups.Items) == 0 { 116 og := operatorsv1.OperatorGroup{ 117 ObjectMeta: metav1.ObjectMeta{ 118 Name: "opgroup", 119 Namespace: testNamespace, 120 }, 121 } 122 Expect(ctx.Ctx().Client().Create(context.TODO(), &og)).To(Succeed()) 123 } 124 125 // Tests can assume the group in the test namespace has been reconciled at least once. 126 Eventually(func() ([]operatorsv1.OperatorGroupStatus, error) { 127 var groups operatorsv1.OperatorGroupList 128 if err := ctx.Ctx().Client().List(context.Background(), &groups, client.InNamespace(testNamespace)); err != nil { 129 return nil, err 130 } 131 var statuses []operatorsv1.OperatorGroupStatus 132 for _, group := range groups.Items { 133 statuses = append(statuses, group.Status) 134 } 135 return statuses, nil 136 }).Should(And( 137 HaveLen(1), 138 ContainElement(Not(BeZero())), 139 )) 140 141 _, err := fetchCatalogSourceOnStatus(ctx.Ctx().OperatorClient(), "operatorhubio-catalog", operatorNamespace, catalogSourceRegistryPodSynced()) 142 Expect(err).NotTo(HaveOccurred()) 143 144 }) 145 146 var _ = AfterSuite(func() { 147 if env := os.Getenv("SKIP_CLEANUP"); env != "" { 148 fmt.Println("Skipping deprovisioning...") 149 return 150 } 151 deprovision() 152 })