Skip to content

Commit 303d610

Browse files
committed
Update e2e to create test namespace if it does not exist
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]>
1 parent 6e0d407 commit 303d610

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

Diff for: Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ endif
139139
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
140140
E2E_INSTALL_NS ?= operator-lifecycle-manager
141141
E2E_CATALOG_NS ?= $(E2E_INSTALL_NS)
142-
E2E_TEST_NS ?= operators
142+
E2E_TEST_NS ?= nonexistent-namespace
143143

144144
e2e:
145145
$(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})

Diff for: test/e2e/e2e_test.go

+22-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99

1010
. "github.com/onsi/ginkgo/v2"
1111
. "github.com/onsi/gomega"
12+
corev1 "k8s.io/api/core/v1"
13+
k8serrors "k8s.io/apimachinery/pkg/api/errors"
1214
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1315
"sigs.k8s.io/controller-runtime/pkg/client"
1416

@@ -91,13 +93,32 @@ var _ = BeforeSuite(func() {
9193
deprovision = ctx.MustProvision(ctx.Ctx())
9294
ctx.MustInstall(ctx.Ctx())
9395

96+
// Create the test namespace if it doesn't exist
97+
Eventually(func() error {
98+
err := ctx.Ctx().Client().Create(context.Background(), &corev1.Namespace{
99+
ObjectMeta: metav1.ObjectMeta{
100+
Name: testNamespace,
101+
Annotations: map[string]string{
102+
"olm.e2e": "no-e2e-kube-client-reset",
103+
},
104+
},
105+
})
106+
if err != nil && !k8serrors.IsAlreadyExists(err) {
107+
return err
108+
}
109+
return nil
110+
}).Should(Succeed())
111+
94112
var groups operatorsv1.OperatorGroupList
95113
Expect(ctx.Ctx().Client().List(context.Background(), &groups, client.InNamespace(testNamespace))).To(Succeed())
96114
if len(groups.Items) == 0 {
97115
og := operatorsv1.OperatorGroup{
98116
ObjectMeta: metav1.ObjectMeta{
99-
Name: "opgroup",
117+
Name: "global-operators",
100118
Namespace: testNamespace,
119+
Annotations: map[string]string{
120+
"olm.e2e": "no-e2e-kube-client-reset",
121+
},
101122
},
102123
}
103124
Expect(ctx.Ctx().Client().Create(context.TODO(), &og)).To(Succeed())

Diff for: test/e2e/util/e2e_client.go

+5
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ func (m *E2EKubeClient) Reset() error {
5959
break
6060
}
6161

62+
// Don't delete e2e resources we don't testNamespace.
63+
if obj.GetAnnotations()["olm.e2e"] == "no-e2e-kube-client-reset" {
64+
continue
65+
}
66+
6267
namespace := obj.GetNamespace()
6368
if namespace == "" {
6469
namespace = "<global>"

0 commit comments

Comments
 (0)