diff --git a/.gitignore b/.gitignore index 4efa7ce90a..5c77f3d21b 100644 --- a/.gitignore +++ b/.gitignore @@ -455,5 +455,5 @@ apiserver.key !vendor/** test/e2e-local.image.tar - +test/e2e/.kube dist/ diff --git a/Makefile b/Makefile index 001008f3ea..6220e2f24d 100644 --- a/Makefile +++ b/Makefile @@ -139,11 +139,10 @@ E2E_TEST_NS ?= operators e2e: $(GINKGO) $(E2E_OPTS) $(or $(run), ./test/e2e) $< -- -namespace=$(E2E_TEST_NS) -olmNamespace=$(E2E_INSTALL_NS) -dummyImage=bitnami/nginx:latest $(or $(extra_args), -kubeconfig=${KUBECONFIG}) - # See workflows/e2e-tests.yml See test/e2e/README.md for details. .PHONY: e2e-local e2e-local: BUILD_TAGS="json1 experimental_metrics" -e2e-local: extra_args=-kind.images=../test/e2e-local.image.tar -test-data-dir=../test/e2e/testdata +e2e-local: extra_args=-kind.images=../test/e2e-local.image.tar -test-data-dir=../test/e2e/testdata -gather-artifacts-script-path=../test/e2e/collect-ci-artifacts.sh e2e-local: run=bin/e2e-local.test e2e-local: bin/e2e-local.test test/e2e-local.image.tar e2e-local: e2e diff --git a/test/e2e/ctx/ctx.go b/test/e2e/ctx/ctx.go index 5ee37787b5..8bf3dc8465 100644 --- a/test/e2e/ctx/ctx.go +++ b/test/e2e/ctx/ctx.go @@ -42,8 +42,9 @@ type TestContext struct { e2eClient *util.E2EKubeClient ssaClient *controllerclient.ServerSideApplier - kubeconfigPath string - artifactsDir string + kubeconfigPath string + artifactsDir string + artifactsScriptPath string scheme *runtime.Scheme @@ -132,8 +133,7 @@ func (ctx TestContext) DumpNamespaceArtifacts(namespace string) error { "KUBECONFIG=" + kubeconfigPath, } - // compiled test binary running e2e tests is run from the root ./bin directory - cmd := exec.Command("../test/e2e/collect-ci-artifacts.sh") + cmd := exec.Command(ctx.artifactsScriptPath) cmd.Env = append(cmd.Env, envvars...) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr @@ -153,6 +153,17 @@ func setDerivedFields(ctx *TestContext) error { return fmt.Errorf("nil RESTClient") } + if ctx.artifactsDir == "" { + if artifactsDir := os.Getenv("ARTIFACT_DIR"); artifactsDir != "" { + ctx.artifactsDir = artifactsDir + } + } + if ctx.artifactsScriptPath == "" { + if scriptPath := os.Getenv("E2E_ARTIFACT_SCRIPT"); scriptPath != "" { + ctx.artifactsScriptPath = scriptPath + } + } + kubeClient, err := operatorclient.NewClientFromRestConfig(ctx.restConfig) if err != nil { return err diff --git a/test/e2e/ctx/provisioner_kind.go b/test/e2e/ctx/provisioner_kind.go index f9f7971ffc..27f6d7c78c 100644 --- a/test/e2e/ctx/provisioner_kind.go +++ b/test/e2e/ctx/provisioner_kind.go @@ -1,3 +1,4 @@ +//go:build kind // +build kind package ctx @@ -135,10 +136,6 @@ func Provision(ctx *TestContext) (func(), error) { return nil, fmt.Errorf("error loading kubeconfig: %s", err.Error()) } ctx.restConfig = restConfig - - if artifactsDir := os.Getenv("ARTIFACTS_DIR"); artifactsDir != "" { - ctx.artifactsDir = artifactsDir - } ctx.kubeconfigPath = kubeconfigPath var once sync.Once diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index f37f2c8d08..5566632d6e 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -42,6 +42,12 @@ var ( "dummy image to treat as an operator in tests", ) + collectArtifactsScriptPath = flag.String( + "gather-artifacts-script-path", + "./collect-ci-artifacts.sh", + "configures the relative/absolute path to the script resposible for collecting CI artifacts", + ) + testdataPath = flag.String( "test-data-dir", "./testdata", @@ -79,6 +85,9 @@ var _ = BeforeSuite(func() { // This flag can be deprecated in favor of the kubeconfig provisioner: os.Setenv("KUBECONFIG", *kubeConfigPath) } + if collectArtifactsScriptPath != nil && *collectArtifactsScriptPath != "" { + os.Setenv("E2E_ARTIFACT_SCRIPT", *collectArtifactsScriptPath) + } testNamespace = *namespace operatorNamespace = *olmNamespace @@ -114,6 +123,7 @@ var _ = BeforeSuite(func() { HaveLen(1), ContainElement(Not(BeZero())), )) + _, err := fetchCatalogSourceOnStatus(ctx.Ctx().OperatorClient(), "operatorhubio-catalog", operatorNamespace, catalogSourceRegistryPodSynced) Expect(err).NotTo(HaveOccurred())