Skip to content

Commit 29d4377

Browse files
committed
test/e2e: Refactor the bundle e2e tests to avoid using global test namespace
Signed-off-by: timflannagan <[email protected]>
1 parent 14e4f27 commit 29d4377

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

test/e2e/bundle_e2e_test.go

+20-16
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"encoding/json"
77

88
"github.com/ghodss/yaml"
9+
corev1 "k8s.io/api/core/v1"
910
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1011
k8serrors "k8s.io/apimachinery/pkg/api/errors"
1112
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -27,19 +28,23 @@ var vpaCRDRaw []byte
2728

2829
var _ = Describe("Installing bundles with new object types", func() {
2930
var (
30-
kubeClient operatorclient.ClientInterface
31-
operatorClient versioned.Interface
32-
dynamicClient dynamic.Interface
31+
kubeClient operatorclient.ClientInterface
32+
operatorClient versioned.Interface
33+
dynamicClient dynamic.Interface
34+
generatedNamespace corev1.Namespace
3335
)
3436

3537
BeforeEach(func() {
3638
kubeClient = ctx.Ctx().KubeClient()
3739
operatorClient = ctx.Ctx().OperatorClient()
3840
dynamicClient = ctx.Ctx().DynamicClient()
41+
42+
By("creating a test namespace")
43+
generatedNamespace = SetupGeneratedTestNamespace(genName("bundle-e2e-"))
3944
})
4045

4146
AfterEach(func() {
42-
TearDown(testNamespace)
47+
TeardownNamespace(&generatedNamespace)
4348
})
4449

4550
When("a bundle with a pdb, priorityclass, and VPA object is installed", func() {
@@ -66,7 +71,7 @@ var _ = Describe("Installing bundles with new object types", func() {
6671
Expect(err).ToNot(HaveOccurred(), "could not convert vpa crd to unstructured")
6772

6873
Eventually(func() error {
69-
err := ctx.Ctx().Client().Create(context.TODO(), &vpaCRD)
74+
err := ctx.Ctx().Client().Create(context.Background(), &vpaCRD)
7075
if err != nil {
7176
if !k8serrors.IsAlreadyExists(err) {
7277
return err
@@ -77,22 +82,21 @@ var _ = Describe("Installing bundles with new object types", func() {
7782

7883
// ensure vpa crd is established and accepted on the cluster before continuing
7984
Eventually(func() (bool, error) {
80-
crd, err := kubeClient.ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Get(context.TODO(), vpaCRD.GetName(), metav1.GetOptions{})
85+
crd, err := kubeClient.ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Get(context.Background(), vpaCRD.GetName(), metav1.GetOptions{})
8186
if err != nil {
8287
return false, err
8388
}
8489
return crdReady(&crd.Status), nil
8590
}).Should(BeTrue())
8691

87-
var installPlanRef string
8892
source := &v1alpha1.CatalogSource{
8993
TypeMeta: metav1.TypeMeta{
9094
Kind: v1alpha1.CatalogSourceKind,
9195
APIVersion: v1alpha1.CatalogSourceCRDAPIVersion,
9296
},
9397
ObjectMeta: metav1.ObjectMeta{
9498
Name: sourceName,
95-
Namespace: testNamespace,
99+
Namespace: generatedNamespace.GetName(),
96100
Labels: map[string]string{"olm.catalogSource": sourceName},
97101
},
98102
Spec: v1alpha1.CatalogSourceSpec{
@@ -102,7 +106,7 @@ var _ = Describe("Installing bundles with new object types", func() {
102106
}
103107

104108
Eventually(func() error {
105-
source, err = operatorClient.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Create(context.TODO(), source, metav1.CreateOptions{})
109+
source, err = operatorClient.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Create(context.Background(), source, metav1.CreateOptions{})
106110
return err
107111
}).Should(Succeed())
108112

@@ -114,13 +118,13 @@ var _ = Describe("Installing bundles with new object types", func() {
114118
_ = createSubscriptionForCatalog(operatorClient, source.GetNamespace(), subName, source.GetName(), packageName, channelName, "", v1alpha1.ApprovalAutomatic)
115119

116120
// Wait for the Subscription to succeed
117-
sub, err := fetchSubscription(operatorClient, testNamespace, subName, subscriptionStateAtLatestChecker)
121+
sub, err := fetchSubscription(operatorClient, generatedNamespace.GetName(), subName, subscriptionStateAtLatestChecker)
118122
Expect(err).ToNot(HaveOccurred(), "could not get subscription at latest status")
119123

120-
installPlanRef = sub.Status.InstallPlanRef.Name
124+
installPlanRef := sub.Status.InstallPlanRef
121125

122126
// Wait for the installplan to complete (5 minute timeout)
123-
_, err = fetchInstallPlan(GinkgoT(), operatorClient, installPlanRef, buildInstallPlanPhaseCheckFunc(v1alpha1.InstallPlanPhaseComplete))
127+
_, err = fetchInstallPlanWithNamespace(GinkgoT(), operatorClient, installPlanRef.Name, installPlanRef.Namespace, buildInstallPlanPhaseCheckFunc(v1alpha1.InstallPlanPhaseComplete))
124128
Expect(err).ToNot(HaveOccurred(), "could not get installplan at complete phase")
125129

126130
ctx.Ctx().Logf("install plan %s completed", installPlanRef)
@@ -144,25 +148,25 @@ var _ = Describe("Installing bundles with new object types", func() {
144148

145149
// confirm extra bundle objects are installed
146150
Eventually(func() error {
147-
_, err := kubeClient.KubernetesInterface().SchedulingV1().PriorityClasses().Get(context.TODO(), priorityClassName, metav1.GetOptions{})
151+
_, err := kubeClient.KubernetesInterface().SchedulingV1().PriorityClasses().Get(context.Background(), priorityClassName, metav1.GetOptions{})
148152
return err
149153
}).Should(Succeed(), "expected no error getting priorityclass object associated with CSV")
150154

151155
Eventually(func() error {
152-
_, err := dynamicClient.Resource(resource).Namespace(testNamespace).Get(context.TODO(), vpaName, metav1.GetOptions{})
156+
_, err := dynamicClient.Resource(resource).Namespace(generatedNamespace.GetName()).Get(context.Background(), vpaName, metav1.GetOptions{})
153157
return err
154158
}).Should(Succeed(), "expected no error finding vpa object associated with csv")
155159

156160
Eventually(func() error {
157-
_, err := kubeClient.KubernetesInterface().PolicyV1().PodDisruptionBudgets(testNamespace).Get(context.TODO(), pdbName, metav1.GetOptions{})
161+
_, err := kubeClient.KubernetesInterface().PolicyV1().PodDisruptionBudgets(generatedNamespace.GetName()).Get(context.Background(), pdbName, metav1.GetOptions{})
158162
return err
159163
}).Should(Succeed(), "expected no error getting pdb object associated with CSV")
160164
})
161165

162166
AfterEach(func() {
163167
By("Deleting the VPA CRD")
164168
Eventually(func() error {
165-
err := ctx.Ctx().Client().Delete(context.TODO(), &vpaCRD)
169+
err := ctx.Ctx().Client().Delete(context.Background(), &vpaCRD)
166170
if k8serrors.IsNotFound(err) {
167171
return nil
168172
}

0 commit comments

Comments
 (0)