From c1644f1596db9b0dbdd5aa4b320a5d197d5591d9 Mon Sep 17 00:00:00 2001 From: Evan Cordell Date: Wed, 28 Nov 2018 09:01:34 -0500 Subject: [PATCH] fix(e2e): set up variables for non-bare e2e runs --- Makefile | 9 +- ...000_30_11-catalog-operator.deployment.yaml | 1 + scripts/build_bare.sh | 11 +- scripts/install_bare.sh | 3 - scripts/run_e2e_bare.sh | 33 +----- scripts/run_e2e_local.sh | 10 +- test/e2e/catalog_e2e_test.go | 13 +-- test/e2e/csv_e2e_test.go | 54 +++++++-- test/e2e/installplan_e2e_test.go | 20 ++-- test/e2e/metrics_e2e_test.go | 4 +- test/e2e/ocs_e2e_test.go | 8 +- test/e2e/setup_bare_test.go | 107 ++++++++++++++++++ test/e2e/setup_test.go | 76 ++----------- test/e2e/subscription_e2e_test.go | 2 +- test/e2e/util_test.go | 6 +- 15 files changed, 207 insertions(+), 150 deletions(-) create mode 100644 test/e2e/setup_bare_test.go diff --git a/Makefile b/Makefile index af2b151278b..8ddc0acc89b 100644 --- a/Makefile +++ b/Makefile @@ -69,21 +69,20 @@ run-local-shift: . ./scripts/install_local.sh local build/resources rm -rf build +# useful if running e2e directly with `go test -tags=bare` setup-bare: . ./scripts/build_bare.sh . ./scripts/package-release.sh 1.0.0-e2e test/e2e/resources test/e2e/e2e-bare-values.yaml - . ./scripts/install_bare.sh e2e test/e2e/resources + . ./scripts/install_bare.sh $(shell cat ./e2e.namespace) test/e2e/resources e2e: - export NAMESPACE=default - go test ./test/e2e/... + go test -v -timeout 20m ./test/e2e/... -namespace=default -kubeconfig=${KUBECONFIG} -olmNamespace=openshift-operator-lifecycle-manager e2e-local: . ./scripts/build_local.sh . ./scripts/run_e2e_local.sh $(TEST) -e2e-bare: - . ./scripts/build_bare.sh +e2e-bare: setup-bare . ./scripts/run_e2e_bare.sh $(TEST) e2e-local-shift: diff --git a/manifests/0000_30_11-catalog-operator.deployment.yaml b/manifests/0000_30_11-catalog-operator.deployment.yaml index a0c78542d6e..1af94d9f7ee 100644 --- a/manifests/0000_30_11-catalog-operator.deployment.yaml +++ b/manifests/0000_30_11-catalog-operator.deployment.yaml @@ -26,6 +26,7 @@ spec: - /bin/catalog - '-namespace' - openshift-operator-lifecycle-manager + - -debug image: quay.io/coreos/olm@sha256:1639d570809c5827810a1870763016e8c046283632d47e0b47183c82f8e515f2 imagePullPolicy: IfNotPresent ports: diff --git a/scripts/build_bare.sh b/scripts/build_bare.sh index 42e1c07f31c..c6112adea4e 100644 --- a/scripts/build_bare.sh +++ b/scripts/build_bare.sh @@ -12,10 +12,9 @@ if [ -z "$NO_MINIKUBE" ]; then umask 0077 && kubectl config view --minify --flatten --context=minikube > minikube.kubeconfig fi -kubectl delete crds --all -kubectl delete namespace e2e || true -kubectl wait --for=delete namespace/e2e || true -kubectl create namespace e2e +timestamp=$(date +%s) +namespace="e2e-tests-${timestamp}-$RANDOM" +printf "${namespace}" > e2e.namespace -# only used for package server, other operators run locally -docker build -t quay.io/coreos/olm:local . +kubectl delete crds --all +kubectl create namespace ${namespace} diff --git a/scripts/install_bare.sh b/scripts/install_bare.sh index 52d083abaae..d1849d0342c 100755 --- a/scripts/install_bare.sh +++ b/scripts/install_bare.sh @@ -28,6 +28,3 @@ do kubectl apply -f ${f}; fi done - -# wait for package server to be ready -#kubectl rollout status -w deployment.apps/package-server --namespace=${namespace} diff --git a/scripts/run_e2e_bare.sh b/scripts/run_e2e_bare.sh index 0b57ecfd4fb..2064a7fdd1a 100755 --- a/scripts/run_e2e_bare.sh +++ b/scripts/run_e2e_bare.sh @@ -1,38 +1,10 @@ #!/usr/bin/env bash # Note: run from root -# Individual tests can be run by calling ./test/e2e/run_e2e_local.sh TestName +# Individual tests can be run by calling ./test/e2e/run_e2e_bare.sh TestName set -e -timestamp=$(date +%s) -namespace="e2e-tests-${timestamp}-$RANDOM" - -function cleanup { - kubectl delete namespace ${namespace} - rm -rf test/e2e/resources -} - -function cleanupAndExit { - exitCode=$? - if [ "$exitCode" -ne "0" ]; then - echo "error running tests. logs written to package.log"; - kubectl -n ${namespace} logs -l app=package-server > package.log - else - cleanup - fi - - exit $exitCode -} - -trap cleanupAndExit SIGINT SIGTERM EXIT - - -kubectl create namespace ${namespace} - -./scripts/package-release.sh 1.0.0-e2e test/e2e/resources test/e2e/e2e-bare-values.yaml -./scripts/install_bare.sh ${namespace} test/e2e/resources - # run tests if [ -z "$1" ]; then test_flags=""; @@ -41,4 +13,5 @@ else fi echo "${test_flags}" -go test -tags=bare -mod=vendor -covermode=count -coverpkg ./pkg/controller/... -test.v -test.timeout 20m ${test_flags} ./test/e2e/... -kubeconfig=${KUBECONFIG:-~/.kube/config} -namespace=${namespace} +go test -c -tags=bare -mod=vendor -v -o e2e-bare github.com/operator-framework/operator-lifecycle-manager/test/e2e +./e2e-bare -test.v -test.timeout 20m ${test_flags} -kubeconfig=minikube.kubeconfig -namespace=$(cat e2e.namespace) diff --git a/scripts/run_e2e_local.sh b/scripts/run_e2e_local.sh index ecfc81b5ac2..dc7a6864cc2 100755 --- a/scripts/run_e2e_local.sh +++ b/scripts/run_e2e_local.sh @@ -41,5 +41,11 @@ trap cleanupAndExit SIGINT SIGTERM EXIT ./scripts/install_local.sh ${namespace} test/e2e/resources # run tests -e2e_kubeconfig=${KUBECONFIG:-~/.kube/config} -KUBECONFIG=${e2e_kubeconfig} NAMESPACE=${namespace} go test -v -timeout 20m ./test/e2e/... ${1/[[:alnum:]-]*/-run ${1}} +if [ -z "$1" ]; then + test_flags=""; +else + test_flags="-test.run ${1}" +fi + +echo "${test_flags}" +go test -mod=vendor -tags=local -covermode=count -coverpkg ./pkg/controller/... -test.v -test.timeout 20m ${test_flags} ./test/e2e/... -kubeconfig=${KUBECONFIG:-~/.kube/config} -namespace=${namespace} -olmNamespace=${namespace} diff --git a/test/e2e/catalog_e2e_test.go b/test/e2e/catalog_e2e_test.go index e0e6effc979..fe2da16fba2 100644 --- a/test/e2e/catalog_e2e_test.go +++ b/test/e2e/catalog_e2e_test.go @@ -4,9 +4,9 @@ package e2e import ( "fmt" - "github.com/coreos/go-semver/semver" "testing" + "github.com/coreos/go-semver/semver" "github.com/stretchr/testify/require" appsv1 "k8s.io/api/apps/v1" extv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" @@ -45,14 +45,13 @@ func TestCatalogLoadingBetweenRestarts(t *testing.T) { crc := newCRClient(t) catalogSourceName := genName("mock-ocs") - _, cleanupCatalogSource, err := createInternalCatalogSource(t, c, crc, catalogSourceName, testNamespace, manifests, []extv1beta1.CustomResourceDefinition{crd}, []v1alpha1.ClusterServiceVersion{csv}) + _, cleanupCatalogSource, err := createInternalCatalogSource(t, c, crc, catalogSourceName, operatorNamespace, manifests, []extv1beta1.CustomResourceDefinition{crd}, []v1alpha1.ClusterServiceVersion{csv}) require.NoError(t, err) defer cleanupCatalogSource() // ensure the mock catalog exists and has been synced by the catalog operator - catalogSource, err := fetchCatalogSource(t, crc, catalogSourceName, testNamespace, catalogSourceSynced) + catalogSource, err := fetchCatalogSource(t, crc, catalogSourceName, operatorNamespace, catalogSourceSynced) require.NoError(t, err) - t.Logf("catalogSource: %+v", catalogSource) // get catalog operator deployment deployment, err := getOperatorDeployment(c, labels.Set{"app": "catalog-operator"}) @@ -67,7 +66,7 @@ func TestCatalogLoadingBetweenRestarts(t *testing.T) { // check for last synced update to catalogsource t.Log("Checking for catalogsource lastSync updates") - _, err = fetchCatalogSource(t, crc, catalogSourceName, testNamespace, func(cs *v1alpha1.CatalogSource) bool { + _, err = fetchCatalogSource(t, crc, catalogSourceName, operatorNamespace, func(cs *v1alpha1.CatalogSource) bool { if cs.Status.LastSync.After(catalogSource.Status.LastSync.Time) { t.Logf("lastSync updated: %s -> %s", catalogSource.Status.LastSync, cs.Status.LastSync) return true @@ -79,7 +78,7 @@ func TestCatalogLoadingBetweenRestarts(t *testing.T) { } func getOperatorDeployment(c operatorclient.ClientInterface, operatorLabels labels.Set) (*appsv1.Deployment, error) { - deployments, err := c.ListDeploymentsWithLabels(testNamespace, operatorLabels) + deployments, err := c.ListDeploymentsWithLabels(operatorNamespace, operatorLabels) if err != nil || deployments == nil || len(deployments.Items) != 1 { return nil, fmt.Errorf("Error getting single operator deployment for label: %v", operatorLabels) } @@ -96,7 +95,7 @@ func rescaleDeployment(c operatorclient.ClientInterface, deployment *appsv1.Depl } waitForScaleup := func() (bool, error) { - fetchedDeployment, err := c.GetDeployment(testNamespace, deployment.GetName()) + fetchedDeployment, err := c.GetDeployment(operatorNamespace, deployment.GetName()) if err != nil { return true, err } diff --git a/test/e2e/csv_e2e_test.go b/test/e2e/csv_e2e_test.go index c95f05b2018..6b753b8c4bd 100644 --- a/test/e2e/csv_e2e_test.go +++ b/test/e2e/csv_e2e_test.go @@ -95,7 +95,7 @@ func newNginxDeployment(name string) appsv1.DeploymentSpec { Containers: []v1.Container{ { Name: genName("nginx"), - Image: "nginx:1.7.9", + Image: "bitnami/nginx:latest", Ports: []v1.ContainerPort{ { ContainerPort: 80, @@ -652,13 +652,30 @@ func TestCreateCSVRequirementsMetCRD(t *testing.T) { require.NoError(t, err) defer cleanupCSV() - fetchedCSV, err := fetchCSV(t, crc, csv.Name, csvSucceededChecker) + fmt.Println("checking for deployment") + // Poll for deployment to be ready + err = wait.Poll(pollInterval, pollDuration, func() (bool, error) { + dep, err := c.GetDeployment(testNamespace, depName) + if k8serrors.IsNotFound(err) { + fmt.Printf("deployment %s not found", depName) + return false, nil + } else if err != nil { + fmt.Printf("unexpected error fetching deployment %s", depName) + return false, err + } + if dep.Status.UpdatedReplicas == *(dep.Spec.Replicas) && + dep.Status.Replicas == *(dep.Spec.Replicas) && + dep.Status.AvailableReplicas == *(dep.Spec.Replicas) { + fmt.Printf("deployment ready") + return true, nil + } + fmt.Printf("deployment not ready") + return false, nil + }) require.NoError(t, err) - // Should create deployment - dep, err := c.GetDeployment(testNamespace, depName) + fetchedCSV, err := fetchCSV(t, crc, csv.Name, csvSucceededChecker) require.NoError(t, err) - require.Equal(t, depName, dep.Name) // Fetch cluster service version again to check for unnecessary control loops sameCSV, err := fetchCSV(t, crc, csv.Name, csvSucceededChecker) @@ -817,13 +834,32 @@ func TestCreateCSVRequirementsMetAPIService(t *testing.T) { require.NoError(t, err) defer cleanupCSV() - fetchedCSV, err := fetchCSV(t, crc, csv.Name, csvSucceededChecker) + fmt.Println("checking for deployment") + // Poll for deployment to be ready + err = wait.Poll(pollInterval, pollDuration, func() (bool, error) { + dep, err := c.GetDeployment(testNamespace, depName) + if k8serrors.IsNotFound(err) { + fmt.Printf("deployment %s not found", depName) + return false, nil + } else if err != nil { + fmt.Printf("unexpected error fetching deployment %s", depName) + return false, err + } + fmt.Printf("waiting for deployment to be available: %#v", dep) + + if dep.Status.UpdatedReplicas == *(dep.Spec.Replicas) && + dep.Status.Replicas == *(dep.Spec.Replicas) && + dep.Status.AvailableReplicas == *(dep.Spec.Replicas) { + fmt.Printf("deployment ready") + return true, nil + } + fmt.Printf("deployment not ready") + return false, nil + }) require.NoError(t, err) - // Should create deployment - dep, err := c.GetDeployment(testNamespace, depName) + fetchedCSV, err := fetchCSV(t, crc, csv.Name, csvSucceededChecker) require.NoError(t, err) - require.Equal(t, depName, dep.Name) // Fetch cluster service version again to check for unnecessary control loops sameCSV, err := fetchCSV(t, crc, csv.Name, csvSucceededChecker) diff --git a/test/e2e/installplan_e2e_test.go b/test/e2e/installplan_e2e_test.go index e79c6e91e45..ca635e8dabb 100644 --- a/test/e2e/installplan_e2e_test.go +++ b/test/e2e/installplan_e2e_test.go @@ -103,7 +103,7 @@ func newNginxInstallStrategy(name string, permissions []install.StrategyDeployme Spec: corev1.PodSpec{Containers: []corev1.Container{ { Name: genName("nginx"), - Image: "nginx:1.7.9", + Image: "bitnami/nginx:latest", Ports: []corev1.ContainerPort{{ContainerPort: 80}}, }, }}, @@ -222,7 +222,7 @@ func TestCreateInstallPlanManualApproval(t *testing.T) { } // Attempt to get the catalog source before creating install plan - _, err = fetchCatalogSource(t, crc, ocsConfigMap, testNamespace, catalogSourceSynced) + _, err = fetchCatalogSource(t, crc, ocsConfigMap, operatorNamespace, catalogSourceSynced) require.NoError(t, err) // Create a new InstallPlan for Vault with manual approval @@ -322,7 +322,7 @@ func TestCreateInstallPlanFromInvalidClusterServiceVersionName(t *testing.T) { } // Attempt to get the catalog source before creating install plan - _, err := fetchCatalogSource(t, crc, ocsConfigMap, testNamespace, catalogSourceSynced) + _, err := fetchCatalogSource(t, crc, ocsConfigMap, operatorNamespace, catalogSourceSynced) require.NoError(t, err) cleanup, err := decorateCommonAndCreateInstallPlan(crc, testNamespace, installPlan) @@ -396,14 +396,14 @@ func TestCreateInstallPlanWithCSVsAcrossMultipleCatalogSources(t *testing.T) { require.NoError(t, err) defer cleanupDependentCatalogSource() // Attempt to get the catalog source before creating install plan - _, err = fetchCatalogSource(t, crc, dependentCatalogName, testNamespace, catalogSourceSynced) + _, err = fetchCatalogSource(t, crc, dependentCatalogName, operatorNamespace, catalogSourceSynced) require.NoError(t, err) _, cleanupMainCatalogSource, err := createInternalCatalogSource(t, c, crc, mainCatalogName, testNamespace, mainManifests, nil, []v1alpha1.ClusterServiceVersion{mainCSV}) require.NoError(t, err) defer cleanupMainCatalogSource() // Attempt to get the catalog source before creating install plan - _, err = fetchCatalogSource(t, crc, mainCatalogName, testNamespace, catalogSourceSynced) + _, err = fetchCatalogSource(t, crc, mainCatalogName, operatorNamespace, catalogSourceSynced) require.NoError(t, err) // Create expected install plan step sources @@ -546,7 +546,7 @@ func TestCreateInstallPlanWithPreExistingCRDOwners(t *testing.T) { require.NoError(t, err) defer cleanupCatalogSource() // Attempt to get the catalog source before creating install plan(s) - _, err = fetchCatalogSource(t, crc, catalogSourceName, testNamespace, catalogSourceSynced) + _, err = fetchCatalogSource(t, crc, catalogSourceName, operatorNamespace, catalogSourceSynced) require.NoError(t, err) expectedSteps := map[registry.ResourceKey]struct{}{ @@ -677,7 +677,7 @@ func TestCreateInstallPlanWithPreExistingCRDOwners(t *testing.T) { require.NoError(t, err) defer cleanupCatalogSource() // Attempt to get the catalog source before creating install plan(s) - _, err = fetchCatalogSource(t, crc, catalogSourceName, testNamespace, catalogSourceSynced) + _, err = fetchCatalogSource(t, crc, catalogSourceName, operatorNamespace, catalogSourceSynced) require.NoError(t, err) secondOwnerCSV := v1alpha1.ClusterServiceVersion{ @@ -796,7 +796,7 @@ func TestCreateInstallPlanWithPreExistingCRDOwners(t *testing.T) { require.NoError(t, err) defer cleanupCatalogSource() // Attempt to get the catalog source before creating install plan(s) - _, err = fetchCatalogSource(t, crc, catalogSourceName, testNamespace, catalogSourceSynced) + _, err = fetchCatalogSource(t, crc, catalogSourceName, operatorNamespace, catalogSourceSynced) require.NoError(t, err) // Create default test installplan @@ -978,7 +978,7 @@ func TestCreateInstallPlanWithPreExistingCRDOwners(t *testing.T) { require.NoError(t, err) defer cleanupCatalogSource() // Attempt to get the catalog source before creating install plan(s) - _, err = fetchCatalogSource(t, crc, catalogSourceName, testNamespace, catalogSourceSynced) + _, err = fetchCatalogSource(t, crc, catalogSourceName, operatorNamespace, catalogSourceSynced) require.NoError(t, err) // Create a dummy installplan with a non-existent csv @@ -1137,7 +1137,7 @@ func TestCreateInstallPlanWithPermissions(t *testing.T) { defer cleanupCatalogSource() // Attempt to get CatalogSource - _, err = fetchCatalogSource(t, crc, catalogSourceName, testNamespace, catalogSourceSynced) + _, err = fetchCatalogSource(t, crc, catalogSourceName, operatorNamespace, catalogSourceSynced) require.NoError(t, err) // Create InstallPlan diff --git a/test/e2e/metrics_e2e_test.go b/test/e2e/metrics_e2e_test.go index 0257ad73324..e62dbdf6b16 100644 --- a/test/e2e/metrics_e2e_test.go +++ b/test/e2e/metrics_e2e_test.go @@ -16,7 +16,7 @@ func TestMetricsEndpoint(t *testing.T) { c := newKubeClient(t) listOptions := metav1.ListOptions{LabelSelector: "app=olm-operator"} - podList, err := c.KubernetesInterface().CoreV1().Pods(testNamespace).List(listOptions) + podList, err := c.KubernetesInterface().CoreV1().Pods(operatorNamespace).List(listOptions) if err != nil { log.Infof("Error %v\n", err) t.Fatalf("Listing pods failed: %v\n", err) @@ -27,7 +27,7 @@ func TestMetricsEndpoint(t *testing.T) { podName := podList.Items[0].GetName() - rawOutput, err := getMetricsFromPod(t, c, podName, testNamespace, 8080) + rawOutput, err := getMetricsFromPod(t, c, podName, operatorNamespace, 8080) if err != nil { t.Fatalf("Metrics test failed: %v\n", err) } diff --git a/test/e2e/ocs_e2e_test.go b/test/e2e/ocs_e2e_test.go index f98243078b7..44d54d453f4 100644 --- a/test/e2e/ocs_e2e_test.go +++ b/test/e2e/ocs_e2e_test.go @@ -26,10 +26,10 @@ func TestInstallEtcdOCS(t *testing.T) { c := newKubeClient(t) crc := newCRClient(t) - catalogSource, err := fetchCatalogSource(t, crc, ocsConfigMap, testNamespace, catalogSourceSynced) + catalogSource, err := fetchCatalogSource(t, crc, ocsConfigMap, operatorNamespace, catalogSourceSynced) require.NoError(t, err) require.NotNil(t, catalogSource) - inMem, err := registry.NewInMemoryFromConfigMap(c, testNamespace, catalogSource.Spec.ConfigMap) + inMem, err := registry.NewInMemoryFromConfigMap(c, operatorNamespace, catalogSource.Spec.ConfigMap) require.NoError(t, err) require.NotNil(t, inMem) latestEtcdCSV, err := inMem.FindCSVForPackageNameUnderChannel("etcd", "alpha") @@ -166,10 +166,10 @@ func TestInstallPrometheusOCS(t *testing.T) { c := newKubeClient(t) crc := newCRClient(t) - catalogSource, err := fetchCatalogSource(t, crc, ocsConfigMap, testNamespace, catalogSourceSynced) + catalogSource, err := fetchCatalogSource(t, crc, ocsConfigMap, operatorNamespace, catalogSourceSynced) require.NoError(t, err) require.NotNil(t, catalogSource) - inMem, err := registry.NewInMemoryFromConfigMap(c, testNamespace, catalogSource.Spec.ConfigMap) + inMem, err := registry.NewInMemoryFromConfigMap(c, operatorNamespace, catalogSource.Spec.ConfigMap) require.NoError(t, err) require.NotNil(t, inMem) latestPrometheusCSV, err := inMem.FindCSVForPackageNameUnderChannel("prometheus", "preview") diff --git a/test/e2e/setup_bare_test.go b/test/e2e/setup_bare_test.go new file mode 100644 index 00000000000..0e88d3eabd2 --- /dev/null +++ b/test/e2e/setup_bare_test.go @@ -0,0 +1,107 @@ +// +build bare + +package e2e + +import ( + "flag" + "io" + "io/ioutil" + "os" + "strings" + "testing" + "time" + + "github.com/sirupsen/logrus" + + "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client" + "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install" + "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/catalog" + "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/olm" + "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient" +) + +var ( + kubeConfigPath = flag.String( + "kubeconfig", "", "path to the kubeconfig file") + + watchedNamespaces = flag.String( + "watchedNamespaces", "", "comma separated list of namespaces for alm operator to watch. "+ + "If not set, or set to the empty string (e.g. `-watchedNamespaces=\"\"`), "+ + "olm operator will watch all namespaces in the cluster.") + + namespace = flag.String( + "namespace", "", "namespace where tests will run") + + testNamespace = "" +) + +func TestMain(m *testing.M) { + if err := flag.Set("logtostderr", "true"); err != nil { + panic(err) + } + flag.Parse() + + testNamespace = *namespace + if testNamespace == "" { + testNamespaceBytes, err := ioutil.ReadFile("e2e.namespace") + if err != nil || testNamespaceBytes == nil { + panic("no namespace set") + } + testNamespace = string(testNamespaceBytes) + } + cleaner = newNamespaceCleaner(testNamespace) + namespaces := strings.Split(*watchedNamespaces, ",") + + olmStopCh := make(chan struct{}, 1) + catalogStopCh := make(chan struct{}, 1) + + // operator dependencies + crClient, err := client.NewClient(*kubeConfigPath) + if err != nil { + logrus.WithError(err).Fatalf("error configuring client") + } + + olmLog, err := os.Create("test/log/e2e-olm.log") + if err != nil { + panic(err) + } + defer olmLog.Close() + olmlogger := logrus.New() + mw := io.MultiWriter(os.Stderr, olmLog) + olmlogger.SetOutput(mw) + olmlogger.SetFormatter(&logrus.TextFormatter{ + ForceColors: true, + DisableTimestamp: true, + }) + olmOpClient := operatorclient.NewClientFromConfig(*kubeConfigPath, olmlogger) + + catLog, err := os.Create("test/log/e2e-catalog.log") + if err != nil { + panic(err) + } + defer catLog.Close() + catlogger := logrus.New() + cmw := io.MultiWriter(os.Stderr, catLog) + catlogger.SetOutput(cmw) + catlogger.SetFormatter(&logrus.TextFormatter{ + ForceColors: true, + DisableTimestamp: true, + }) + + // start operators + olmOperator, err := olm.NewOperator(olmlogger, crClient, olmOpClient, &install.StrategyResolver{}, time.Minute, namespaces) + if err != nil { + logrus.WithError(err).Fatalf("error configuring olm") + } + olmready, _ := olmOperator.Run(olmStopCh) + catalogOperator, err := catalog.NewOperator(*kubeConfigPath, catlogger, time.Minute, *namespace, namespaces...) + if err != nil { + logrus.WithError(err).Fatalf("error configuring catalog") + } + catready, _ := catalogOperator.Run(catalogStopCh) + <-olmready + <-catready + + // run tests + os.Exit(m.Run()) +} diff --git a/test/e2e/setup_test.go b/test/e2e/setup_test.go index 0181f18368a..5e6b3515ca5 100644 --- a/test/e2e/setup_test.go +++ b/test/e2e/setup_test.go @@ -1,37 +1,25 @@ -// +build bare +// +build !bare package e2e import ( "flag" - "io" "os" - "strings" "testing" - "time" - - "github.com/sirupsen/logrus" - - "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client" - "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install" - "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/catalog" - "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/olm" - "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient" ) var ( kubeConfigPath = flag.String( "kubeconfig", "", "path to the kubeconfig file") - watchedNamespaces = flag.String( - "watchedNamespaces", "", "comma separated list of namespaces for alm operator to watch. "+ - "If not set, or set to the empty string (e.g. `-watchedNamespaces=\"\"`), "+ - "olm operator will watch all namespaces in the cluster.") - namespace = flag.String( "namespace", "", "namespace where tests will run") - testNamespace = "" + olmNamespace = flag.String( + "olmNamespace", "", "namespace where olm is running") + + testNamespace = "" + operatorNamespace = "" ) func TestMain(m *testing.M) { @@ -41,58 +29,8 @@ func TestMain(m *testing.M) { flag.Parse() testNamespace = *namespace + operatorNamespace = *olmNamespace cleaner = newNamespaceCleaner(testNamespace) - namespaces := strings.Split(*watchedNamespaces, ",") - - olmStopCh := make(chan struct{}, 1) - catalogStopCh := make(chan struct{}, 1) - - // operator dependencies - crClient, err := client.NewClient(*kubeConfigPath) - if err != nil { - logrus.WithError(err).Fatalf("error configuring client") - } - - olmLog, err := os.Create("test/log/e2e-olm.log") - if err != nil { - panic(err) - } - defer olmLog.Close() - olmlogger := logrus.New() - mw := io.MultiWriter(os.Stderr, olmLog) - olmlogger.SetOutput(mw) - olmlogger.SetFormatter(&logrus.TextFormatter{ - ForceColors: true, - DisableTimestamp: true, - }) - olmOpClient := operatorclient.NewClientFromConfig(*kubeConfigPath, olmlogger) - - catLog, err := os.Create("test/log/e2e-catalog.log") - if err != nil { - panic(err) - } - defer catLog.Close() - catlogger := logrus.New() - cmw := io.MultiWriter(os.Stderr, catLog) - catlogger.SetOutput(cmw) - catlogger.SetFormatter(&logrus.TextFormatter{ - ForceColors: true, - DisableTimestamp: true, - }) - - // start operators - olmOperator, err := olm.NewOperator(olmlogger, crClient, olmOpClient, &install.StrategyResolver{}, time.Minute, namespaces) - if err != nil { - logrus.WithError(err).Fatalf("error configuring olm") - } - olmready, _ := olmOperator.Run(olmStopCh) - catalogOperator, err := catalog.NewOperator(*kubeConfigPath, catlogger, time.Minute, *namespace, namespaces...) - if err != nil { - logrus.WithError(err).Fatalf("error configuring catalog") - } - catready, _ := catalogOperator.Run(catalogStopCh) - <-olmready - <-catready // run tests os.Exit(m.Run()) diff --git a/test/e2e/subscription_e2e_test.go b/test/e2e/subscription_e2e_test.go index 19a7965de3e..6c59fe736fd 100644 --- a/test/e2e/subscription_e2e_test.go +++ b/test/e2e/subscription_e2e_test.go @@ -152,7 +152,7 @@ var ( Spec: corev1.PodSpec{Containers: []corev1.Container{ { Name: genName("nginx"), - Image: "nginx:1.7.9", + Image: "bitnami/nginx:latest", Ports: []corev1.ContainerPort{{ContainerPort: 80}}, }, }}, diff --git a/test/e2e/util_test.go b/test/e2e/util_test.go index b6735be958e..5febb67abbe 100644 --- a/test/e2e/util_test.go +++ b/test/e2e/util_test.go @@ -2,11 +2,12 @@ package e2e import ( "fmt" - "github.com/sirupsen/logrus" "strings" "testing" "time" + "github.com/sirupsen/logrus" + "github.com/ghodss/yaml" "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" @@ -31,7 +32,7 @@ import ( const ( pollInterval = 1 * time.Second - pollDuration = 5 * time.Minute + pollDuration = 1 * time.Minute etcdVersion = "3.2.13" prometheusVersion = "v2.3.2" @@ -239,6 +240,7 @@ func catalogSourceSynced(catalog *v1alpha1.CatalogSource) bool { if !catalog.Status.LastSync.IsZero() { return true } + fmt.Printf("not synced: %#v", catalog) return false }