Skip to content

Commit

Permalink
Update e2e to create test namespace if it does not exist
Browse files Browse the repository at this point in the history
This commit updates the OLM e2e test framework to create the test
namespace if it does not already exist. It also makes a few small
changes to prevent the e2e client from deleting resources in a namespace
that shouldn't be deleted in the case of a failed test.

Signed-off-by: Alexander Greene <[email protected]>
  • Loading branch information
awgreene committed Sep 22, 2023
1 parent 6e0d407 commit 303d610
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ endif
E2E_OPTS ?= $(if $(E2E_SEED),-seed '$(E2E_SEED)') $(if $(SKIP), -skip '$(SKIP)') $(if $(TEST),-focus '$(TEST)') $(if $(ARTIFACT_DIR), -output-dir $(ARTIFACT_DIR) -junit-report junit_e2e.xml) -flake-attempts $(E2E_FLAKE_ATTEMPTS) -nodes $(E2E_NODES) -timeout $(E2E_TIMEOUT) -v -randomize-suites -race -trace -progress
E2E_INSTALL_NS ?= operator-lifecycle-manager
E2E_CATALOG_NS ?= $(E2E_INSTALL_NS)
E2E_TEST_NS ?= operators
E2E_TEST_NS ?= nonexistent-namespace

e2e:
$(GINKGO) $(E2E_OPTS) $(or $(run), ./test/e2e) $< -- -namespace=$(E2E_TEST_NS) -olmNamespace=$(E2E_INSTALL_NS) -catalogNamespace=$(E2E_CATALOG_NS) -dummyImage=bitnami/nginx:latest $(or $(extra_args), -kubeconfig=${KUBECONFIG})
Expand Down
23 changes: 22 additions & 1 deletion test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -91,13 +93,32 @@ var _ = BeforeSuite(func() {
deprovision = ctx.MustProvision(ctx.Ctx())
ctx.MustInstall(ctx.Ctx())

// Create the test namespace if it doesn't exist
Eventually(func() error {
err := ctx.Ctx().Client().Create(context.Background(), &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: testNamespace,
Annotations: map[string]string{
"olm.e2e": "no-e2e-kube-client-reset",
},
},
})
if err != nil && !k8serrors.IsAlreadyExists(err) {
return err
}
return nil
}).Should(Succeed())

var groups operatorsv1.OperatorGroupList
Expect(ctx.Ctx().Client().List(context.Background(), &groups, client.InNamespace(testNamespace))).To(Succeed())
if len(groups.Items) == 0 {
og := operatorsv1.OperatorGroup{
ObjectMeta: metav1.ObjectMeta{
Name: "opgroup",
Name: "global-operators",
Namespace: testNamespace,
Annotations: map[string]string{
"olm.e2e": "no-e2e-kube-client-reset",
},
},
}
Expect(ctx.Ctx().Client().Create(context.TODO(), &og)).To(Succeed())
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/util/e2e_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ func (m *E2EKubeClient) Reset() error {
break
}

// Don't delete e2e resources we don't testNamespace.
if obj.GetAnnotations()["olm.e2e"] == "no-e2e-kube-client-reset" {
continue
}

namespace := obj.GetNamespace()
if namespace == "" {
namespace = "<global>"
Expand Down

0 comments on commit 303d610

Please sign in to comment.