Skip to content

Commit 8abe078

Browse files
perdasilvaPer Goncalves da Silva
and
Per Goncalves da Silva
authored
Improve catalog source e2e (#2738)
Signed-off-by: Per Goncalves da Silva <[email protected]> Co-authored-by: Per Goncalves da Silva <[email protected]>
1 parent f8d7f78 commit 8abe078

File tree

1 file changed

+92
-61
lines changed

1 file changed

+92
-61
lines changed

test/e2e/catalog_e2e_test.go

+92-61
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
8585

8686
defer func() {
8787
Eventually(func() error {
88-
return ctx.Ctx().KubeClient().ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Delete(context.TODO(), crd.GetName(), metav1.DeleteOptions{})
88+
return ctx.Ctx().KubeClient().ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Delete(context.Background(), crd.GetName(), metav1.DeleteOptions{})
8989
}).Should(Or(Succeed(), WithTransform(k8serror.IsNotFound, BeTrue())))
9090
Eventually(func() error {
91-
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.TODO(), &csv))
91+
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.Background(), &csv))
9292
}).Should(Succeed())
9393
}()
9494

@@ -151,13 +151,13 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
151151

152152
defer func() {
153153
Eventually(func() error {
154-
return ctx.Ctx().KubeClient().ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Delete(context.TODO(), mainCRD.GetName(), metav1.DeleteOptions{})
154+
return ctx.Ctx().KubeClient().ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Delete(context.Background(), mainCRD.GetName(), metav1.DeleteOptions{})
155155
}).Should(Or(Succeed(), WithTransform(k8serror.IsNotFound, BeTrue())))
156156
Eventually(func() error {
157-
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.TODO(), &mainCSV))
157+
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.Background(), &mainCSV))
158158
}).Should(Succeed())
159159
Eventually(func() error {
160-
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.TODO(), &replacementCSV))
160+
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.Background(), &replacementCSV))
161161
}).Should(Succeed())
162162
}()
163163

@@ -201,12 +201,17 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
201201

202202
installPlanName := subscription.Status.Install.Name
203203
requiresApprovalChecker := buildInstallPlanPhaseCheckFunc(v1alpha1.InstallPlanPhaseRequiresApproval)
204-
fetchedInstallPlan, err := fetchInstallPlanWithNamespace(GinkgoT(), crc, installPlanName, ns.GetName(), requiresApprovalChecker)
205-
Expect(err).ShouldNot(HaveOccurred())
206204

207-
fetchedInstallPlan.Spec.Approved = true
208-
_, err = crc.OperatorsV1alpha1().InstallPlans(ns.GetName()).Update(context.Background(), fetchedInstallPlan, metav1.UpdateOptions{})
209-
Expect(err).ShouldNot(HaveOccurred())
205+
Eventually(func() error {
206+
fetchedInstallPlan, err := fetchInstallPlanWithNamespace(GinkgoT(), crc, installPlanName, ns.GetName(), requiresApprovalChecker)
207+
if err != nil {
208+
return err
209+
}
210+
211+
fetchedInstallPlan.Spec.Approved = true
212+
_, err = crc.OperatorsV1alpha1().InstallPlans(ns.GetName()).Update(context.Background(), fetchedInstallPlan, metav1.UpdateOptions{})
213+
return err
214+
}).Should(Succeed())
210215

211216
_, err = awaitCSV(crc, ns.GetName(), mainCSV.GetName(), csvSucceededChecker)
212217
Expect(err).ShouldNot(HaveOccurred())
@@ -255,13 +260,13 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
255260

256261
defer func() {
257262
Eventually(func() error {
258-
return ctx.Ctx().KubeClient().ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Delete(context.TODO(), dependentCRD.GetName(), metav1.DeleteOptions{})
263+
return ctx.Ctx().KubeClient().ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Delete(context.Background(), dependentCRD.GetName(), metav1.DeleteOptions{})
259264
}).Should(Or(Succeed(), WithTransform(k8serror.IsNotFound, BeTrue())))
260265
Eventually(func() error {
261-
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.TODO(), &mainCSV))
266+
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.Background(), &mainCSV))
262267
}).Should(Succeed())
263268
Eventually(func() error {
264-
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.TODO(), &dependentCSV))
269+
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.Background(), &dependentCSV))
265270
}).Should(Succeed())
266271
}()
267272

@@ -388,13 +393,13 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
388393

389394
defer func() {
390395
Eventually(func() error {
391-
return ctx.Ctx().KubeClient().ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Delete(context.TODO(), dependentCRD.GetName(), metav1.DeleteOptions{})
396+
return ctx.Ctx().KubeClient().ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Delete(context.Background(), dependentCRD.GetName(), metav1.DeleteOptions{})
392397
}).Should(Or(Succeed(), WithTransform(k8serror.IsNotFound, BeTrue())))
393398
Eventually(func() error {
394-
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.TODO(), &mainCSV))
399+
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.Background(), &mainCSV))
395400
}).Should(Succeed())
396401
Eventually(func() error {
397-
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.TODO(), &dependentCSV))
402+
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.Background(), &dependentCSV))
398403
}).Should(Succeed())
399404
}()
400405

@@ -482,16 +487,16 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
482487

483488
defer func() {
484489
Eventually(func() error {
485-
return ctx.Ctx().KubeClient().ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Delete(context.TODO(), dependentCRD.GetName(), metav1.DeleteOptions{})
490+
return ctx.Ctx().KubeClient().ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Delete(context.Background(), dependentCRD.GetName(), metav1.DeleteOptions{})
486491
}).Should(Or(Succeed(), WithTransform(k8serror.IsNotFound, BeTrue())))
487492
Eventually(func() error {
488-
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.TODO(), &mainCSV))
493+
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.Background(), &mainCSV))
489494
}).Should(Succeed())
490495
Eventually(func() error {
491-
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.TODO(), &dependentCSV))
496+
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.Background(), &dependentCSV))
492497
}).Should(Succeed())
493498
Eventually(func() error {
494-
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.TODO(), &replacementCSV))
499+
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.Background(), &replacementCSV))
495500
}).Should(Succeed())
496501
}()
497502

@@ -592,11 +597,16 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
592597
Expect(err).ShouldNot(HaveOccurred())
593598

594599
// Update the catalog's address to point at the other registry pod's cluster ip
595-
addressSource, err = crc.OperatorsV1alpha1().CatalogSources(ns.GetName()).Get(context.Background(), addressSourceName, metav1.GetOptions{})
596-
Expect(err).ShouldNot(HaveOccurred())
597-
addressSource.Spec.Address = net.JoinHostPort(replacementCopy.Status.PodIP, "50051")
598-
_, err = crc.OperatorsV1alpha1().CatalogSources(ns.GetName()).Update(context.Background(), addressSource, metav1.UpdateOptions{})
599-
Expect(err).ShouldNot(HaveOccurred())
600+
Eventually(func() error {
601+
addressSource, err = crc.OperatorsV1alpha1().CatalogSources(ns.GetName()).Get(context.Background(), addressSourceName, metav1.GetOptions{})
602+
if err != nil {
603+
return err
604+
}
605+
606+
addressSource.Spec.Address = net.JoinHostPort(replacementCopy.Status.PodIP, "50051")
607+
_, err = crc.OperatorsV1alpha1().CatalogSources(ns.GetName()).Update(context.Background(), addressSource, metav1.UpdateOptions{})
608+
return err
609+
}).Should(Succeed())
600610

601611
// Wait for the replacement CSV to be installed
602612
_, err = awaitCSV(crc, ns.GetName(), replacementCSV.GetName(), csvSucceededChecker)
@@ -629,10 +639,10 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
629639

630640
defer func() {
631641
Eventually(func() error {
632-
return ctx.Ctx().KubeClient().ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Delete(context.TODO(), crd.GetName(), metav1.DeleteOptions{})
642+
return ctx.Ctx().KubeClient().ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Delete(context.Background(), crd.GetName(), metav1.DeleteOptions{})
633643
}).Should(Or(Succeed(), WithTransform(k8serror.IsNotFound, BeTrue())))
634644
Eventually(func() error {
635-
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.TODO(), &csv))
645+
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.Background(), &csv))
636646
}).Should(Succeed())
637647
}()
638648

@@ -892,12 +902,17 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
892902
}
893903

894904
// update catalog source with annotation (to kick resync)
895-
source, err = crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Get(context.Background(), source.GetName(), metav1.GetOptions{})
896-
Expect(err).ShouldNot(HaveOccurred(), "error awaiting registry pod")
897-
source.Annotations = make(map[string]string)
898-
source.Annotations["testKey"] = "testValue"
899-
_, err = crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Update(context.Background(), source, metav1.UpdateOptions{})
900-
Expect(err).ShouldNot(HaveOccurred(), "error awaiting registry pod")
905+
Eventually(func() error {
906+
source, err = crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Get(context.Background(), source.GetName(), metav1.GetOptions{})
907+
if err != nil {
908+
return nil
909+
}
910+
911+
source.Annotations = make(map[string]string)
912+
source.Annotations["testKey"] = "testValue"
913+
_, err = crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Update(context.Background(), source, metav1.UpdateOptions{})
914+
return err
915+
}).Should(Succeed())
901916

902917
time.Sleep(11 * time.Second)
903918

@@ -916,11 +931,21 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
916931
}
917932
}
918933
// update catalog source with annotation (to kick resync)
919-
source, err = crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Get(context.Background(), source.GetName(), metav1.GetOptions{})
920-
Expect(err).ShouldNot(HaveOccurred(), "error getting catalog source pod")
921-
source.Annotations["testKey"] = genName("newValue")
922-
_, err = crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Update(context.Background(), source, metav1.UpdateOptions{})
923-
Expect(err).ShouldNot(HaveOccurred(), "error updating catalog source pod with test annotation")
934+
Eventually(func() error {
935+
source, err = crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Get(context.Background(), source.GetName(), metav1.GetOptions{})
936+
if err != nil {
937+
return err
938+
}
939+
940+
if source.Annotations == nil {
941+
source.Annotations = make(map[string]string)
942+
}
943+
944+
source.Annotations["testKey"] = genName("newValue")
945+
_, err = crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Update(context.Background(), source, metav1.UpdateOptions{})
946+
return err
947+
}).Should(Succeed())
948+
924949
return false
925950
}
926951
// await new catalog source and ensure old one was deleted
@@ -930,11 +955,16 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
930955
Expect(registryPods.Items).To(HaveLen(1), "unexpected number of registry pods found")
931956

932957
// update catalog source with annotation (to kick resync)
933-
source, err = crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Get(context.Background(), source.GetName(), metav1.GetOptions{})
934-
Expect(err).ShouldNot(HaveOccurred(), "error awaiting registry pod")
935-
source.Annotations["testKey"] = "newValue"
936-
_, err = crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Update(context.Background(), source, metav1.UpdateOptions{})
937-
Expect(err).ShouldNot(HaveOccurred(), "error awaiting registry pod")
958+
Eventually(func() error {
959+
source, err = crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Get(context.Background(), source.GetName(), metav1.GetOptions{})
960+
if err != nil {
961+
return err
962+
}
963+
964+
source.Annotations["testKey"] = "newValue"
965+
_, err = crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Update(context.Background(), source, metav1.UpdateOptions{})
966+
return err
967+
}).Should(Succeed())
938968

939969
subChecker := func(sub *v1alpha1.Subscription) bool {
940970
return sub.Status.InstalledCSV == "busybox.v2.0.0"
@@ -1030,19 +1060,16 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
10301060
Expect(subscription.Status.InstalledCSV).To(Equal("busybox-dependency.v1.0.0"))
10311061

10321062
// Update the catalog image
1033-
Eventually(func() (bool, error) {
1063+
Eventually(func() error {
10341064
existingSource, err := crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Get(context.Background(), sourceName, metav1.GetOptions{})
10351065
if err != nil {
1036-
return false, err
1066+
return err
10371067
}
10381068
existingSource.Spec.Image = catSrcImage + ":2.0.0-with-ListBundles-method"
10391069

10401070
source, err = crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Update(context.Background(), existingSource, metav1.UpdateOptions{})
1041-
if err == nil {
1042-
return true, nil
1043-
}
1044-
return false, nil
1045-
}).Should(BeTrue())
1071+
return err
1072+
}).Should(Succeed())
10461073

10471074
// Wait for the CatalogSource to be ready
10481075
_, err = fetchCatalogSourceOnStatus(crc, source.GetName(), source.GetNamespace(), catalogSourceRegistryPodSynced)
@@ -1102,7 +1129,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
11021129
},
11031130
}
11041131

1105-
source, err := crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Create(context.TODO(), source, metav1.CreateOptions{})
1132+
source, err := crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Create(context.Background(), source, metav1.CreateOptions{})
11061133
Expect(err).ToNot(HaveOccurred())
11071134

11081135
// wait for new catalog source pod to be created and report ready
@@ -1113,7 +1140,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
11131140
Expect(catalogPods).ToNot(BeNil())
11141141

11151142
Eventually(func() (bool, error) {
1116-
podList, err := c.KubernetesInterface().CoreV1().Pods(source.GetNamespace()).List(context.TODO(), metav1.ListOptions{LabelSelector: selector.String()})
1143+
podList, err := c.KubernetesInterface().CoreV1().Pods(source.GetNamespace()).List(context.Background(), metav1.ListOptions{LabelSelector: selector.String()})
11171144
if err != nil {
11181145
return false, err
11191146
}
@@ -1179,17 +1206,17 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
11791206
},
11801207
}
11811208

1182-
_, err := crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Create(context.TODO(), source, metav1.CreateOptions{})
1209+
_, err := crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Create(context.Background(), source, metav1.CreateOptions{})
11831210
Expect(err).ToNot(HaveOccurred())
11841211

11851212
})
11861213
AfterEach(func() {
1187-
err := crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Delete(context.TODO(), source.GetName(), metav1.DeleteOptions{})
1214+
err := crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Delete(context.Background(), source.GetName(), metav1.DeleteOptions{})
11881215
Expect(err).ToNot(HaveOccurred())
11891216
})
11901217
It("the catalogsource status communicates that a default interval time is being used instead", func() {
11911218
Eventually(func() bool {
1192-
catsrc, err := crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Get(context.TODO(), source.GetName(), metav1.GetOptions{})
1219+
catsrc, err := crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Get(context.Background(), source.GetName(), metav1.GetOptions{})
11931220
Expect(err).ToNot(HaveOccurred())
11941221
if catsrc.Status.Reason == v1alpha1.CatalogSourceIntervalInvalidError {
11951222
if catsrc.Status.Message == "error parsing spec.updateStrategy.registryPoll.interval. Using the default value of 15m0s instead. Error: time: unknown unit \"mError\" in duration \"45mError.code\"" {
@@ -1201,15 +1228,19 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
12011228
})
12021229
When("the catalogsource is updated with a valid polling interval", func() {
12031230
BeforeEach(func() {
1204-
catsrc, err := crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Get(context.TODO(), source.GetName(), metav1.GetOptions{})
1205-
Expect(err).ToNot(HaveOccurred())
1206-
catsrc.Spec.UpdateStrategy.RegistryPoll.RawInterval = correctInterval
1207-
_, err = crc.OperatorsV1alpha1().CatalogSources(catsrc.GetNamespace()).Update(context.TODO(), catsrc, metav1.UpdateOptions{})
1208-
Expect(err).ToNot(HaveOccurred())
1231+
Eventually(func() error {
1232+
catsrc, err := crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Get(context.Background(), source.GetName(), metav1.GetOptions{})
1233+
if err != nil {
1234+
return err
1235+
}
1236+
catsrc.Spec.UpdateStrategy.RegistryPoll.RawInterval = correctInterval
1237+
_, err = crc.OperatorsV1alpha1().CatalogSources(catsrc.GetNamespace()).Update(context.Background(), catsrc, metav1.UpdateOptions{})
1238+
return err
1239+
}).Should(Succeed())
12091240
})
12101241
It("the catalogsource spec shows the updated polling interval, and the error message in the status is cleared", func() {
12111242
Eventually(func() error {
1212-
catsrc, err := crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Get(context.TODO(), source.GetName(), metav1.GetOptions{})
1243+
catsrc, err := crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Get(context.Background(), source.GetName(), metav1.GetOptions{})
12131244
if err != nil {
12141245
return err
12151246
}

0 commit comments

Comments
 (0)