Skip to content

Commit 9ed3d83

Browse files
author
Mikalai Radchuk
committed
Updates E2E tests
Changes required to account for a new flow where we prevent `InstallPlan` from being created when unpack job fails Signed-off-by: Mikalai Radchuk <[email protected]>
1 parent 41d17f6 commit 9ed3d83

File tree

5 files changed

+329
-372
lines changed

5 files changed

+329
-372
lines changed

test/e2e/catalog_e2e_test.go

+20-27
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
10101010

10111011
catSrcImage := "quay.io/olmtest/busybox-dependencies-index"
10121012

1013-
// Create gRPC CatalogSource
1013+
By("creating gRPC CatalogSource")
10141014
source := &v1alpha1.CatalogSource{
10151015
TypeMeta: metav1.TypeMeta{
10161016
Kind: v1alpha1.CatalogSourceKind,
@@ -1028,30 +1028,29 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
10281028
},
10291029
},
10301030
}
1031-
10321031
source, err := crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Create(context.Background(), source, metav1.CreateOptions{})
10331032
Expect(err).ShouldNot(HaveOccurred())
10341033
defer func() {
10351034
err := crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Delete(context.Background(), source.GetName(), metav1.DeleteOptions{})
10361035
Expect(err).ShouldNot(HaveOccurred())
10371036
}()
10381037

1039-
// Wait for the CatalogSource to be ready
1038+
By("waiting for the CatalogSource to be ready")
10401039
_, err = fetchCatalogSourceOnStatus(crc, source.GetName(), source.GetNamespace(), catalogSourceRegistryPodSynced)
10411040
Expect(err).ToNot(HaveOccurred(), "catalog source did not become ready")
10421041

1043-
// Create a Subscription for busybox
1042+
By("creating a Subscription for busybox")
10441043
subscriptionName := genName("sub-")
10451044
cleanupSubscription := createSubscriptionForCatalog(crc, source.GetNamespace(), subscriptionName, source.GetName(), packageName, channelName, "", v1alpha1.ApprovalAutomatic)
10461045
defer cleanupSubscription()
10471046

1048-
// Wait for the Subscription to succeed
1047+
By("waiting for the Subscription to succeed")
10491048
subscription, err := fetchSubscription(crc, ns.GetName(), subscriptionName, subscriptionStateAtLatestChecker)
10501049
Expect(err).ShouldNot(HaveOccurred())
10511050
Expect(subscription).ShouldNot(BeNil())
10521051
Expect(subscription.Status.InstalledCSV).To(Equal("busybox.v1.0.0"))
10531052

1054-
// Confirm that a subscription was created for busybox-dependency
1053+
By("confirming that a subscription was created for busybox-dependency")
10551054
subscriptionList, err := crc.OperatorsV1alpha1().Subscriptions(source.GetNamespace()).List(context.Background(), metav1.ListOptions{})
10561055
Expect(err).ShouldNot(HaveOccurred())
10571056
dependencySubscriptionName := ""
@@ -1062,13 +1061,13 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
10621061
}
10631062
Expect(dependencySubscriptionName).ToNot(BeEmpty())
10641063

1065-
// Wait for the Subscription to succeed
1064+
By("waiting for the Subscription to succeed")
10661065
subscription, err = fetchSubscription(crc, ns.GetName(), dependencySubscriptionName, subscriptionStateAtLatestChecker)
10671066
Expect(err).ShouldNot(HaveOccurred())
10681067
Expect(subscription).ShouldNot(BeNil())
10691068
Expect(subscription.Status.InstalledCSV).To(Equal("busybox-dependency.v1.0.0"))
10701069

1071-
// Update the catalog image
1070+
By("updating the catalog image")
10721071
Eventually(func() error {
10731072
existingSource, err := crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Get(context.Background(), sourceName, metav1.GetOptions{})
10741073
if err != nil {
@@ -1080,32 +1079,32 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
10801079
return err
10811080
}).Should(Succeed())
10821081

1083-
// Wait for the CatalogSource to be ready
1082+
By("waiting for the CatalogSource to be ready")
10841083
_, err = fetchCatalogSourceOnStatus(crc, source.GetName(), source.GetNamespace(), catalogSourceRegistryPodSynced)
10851084
Expect(err).ToNot(HaveOccurred(), "catalog source did not become ready")
10861085

1087-
// Wait for the busybox v2 Subscription to succeed
1086+
By("waiting for the busybox v2 Subscription to succeed")
10881087
subChecker := func(sub *v1alpha1.Subscription) bool {
10891088
return sub.Status.InstalledCSV == "busybox.v2.0.0"
10901089
}
10911090
subscription, err = fetchSubscription(crc, ns.GetName(), subscriptionName, subChecker)
10921091
Expect(err).ShouldNot(HaveOccurred())
10931092
Expect(subscription).ShouldNot(BeNil())
10941093

1095-
// Wait for busybox v2 csv to succeed and check the replaces field
1094+
By("waiting for busybox v2 csv to succeed and check the replaces field")
10961095
csv, err := fetchCSV(crc, subscription.Status.CurrentCSV, subscription.GetNamespace(), csvSucceededChecker)
10971096
Expect(err).ShouldNot(HaveOccurred())
10981097
Expect(csv.Spec.Replaces).To(Equal("busybox.v1.0.0"))
10991098

1100-
// Wait for the busybox-dependency v2 Subscription to succeed
1099+
By("waiting for the busybox-dependency v2 Subscription to succeed")
11011100
subChecker = func(sub *v1alpha1.Subscription) bool {
11021101
return sub.Status.InstalledCSV == "busybox-dependency.v2.0.0"
11031102
}
11041103
subscription, err = fetchSubscription(crc, ns.GetName(), dependencySubscriptionName, subChecker)
11051104
Expect(err).ShouldNot(HaveOccurred())
11061105
Expect(subscription).ShouldNot(BeNil())
11071106

1108-
// Wait for busybox-dependency v2 csv to succeed and check the replaces field
1107+
By("waiting for busybox-dependency v2 csv to succeed and check the replaces field")
11091108
csv, err = fetchCSV(crc, subscription.Status.CurrentCSV, subscription.GetNamespace(), csvSucceededChecker)
11101109
Expect(err).ShouldNot(HaveOccurred())
11111110
Expect(csv.Spec.Replaces).To(Equal("busybox-dependency.v1.0.0"))
@@ -1403,21 +1402,15 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
14031402
Expect(c.Create(context.Background(), subscription)).To(BeNil())
14041403
})
14051404

1406-
It("fails with a ResolutionFailed error condition, and a message that highlights the missing field in the CSV", func() {
1407-
1408-
subscription, err := fetchSubscription(crc, subscription.GetNamespace(), subscription.GetName(), subscriptionHasInstallPlanChecker)
1409-
Expect(err).Should(BeNil())
1410-
installPlanName := subscription.Status.Install.Name
1411-
1412-
// ensure we wait for the installPlan to fail before moving forward then fetch the subscription again
1413-
_, err = fetchInstallPlan(GinkgoT(), crc, installPlanName, subscription.GetNamespace(), buildInstallPlanPhaseCheckFunc(operatorsv1alpha1.InstallPlanPhaseFailed))
1414-
Expect(err).To(BeNil())
1415-
subscription, err = fetchSubscription(crc, subscription.GetNamespace(), subscription.GetName(), subscriptionHasInstallPlanChecker)
1416-
Expect(err).To(BeNil())
1405+
It("fails with a BundleUnpackFailed error condition, and a message that highlights the missing field in the CSV", func() {
1406+
Eventually(func(g Gomega) string {
1407+
fetchedSubscription, err := crc.OperatorsV1alpha1().Subscriptions(ns.GetName()).Get(context.Background(), subscription.GetName(), metav1.GetOptions{})
1408+
g.Expect(err).NotTo(HaveOccurred())
14171409

1418-
// expect the message that API missing
1419-
failingCondition := subscription.Status.GetCondition(operatorsv1alpha1.SubscriptionInstallPlanFailed)
1420-
Expect(failingCondition.Message).To(ContainSubstring("missing APIVersion"))
1410+
// expect the message that API missing
1411+
failingCondition := fetchedSubscription.Status.GetCondition(v1alpha1.SubscriptionBundleUnpackFailed)
1412+
return failingCondition.Message
1413+
}).Should(ContainSubstring("missing APIVersion"))
14211414
})
14221415
})
14231416
})

test/e2e/fail_forward_e2e_test.go

+67-47
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,18 @@ var _ = Describe("Fail Forward Upgrades", func() {
5858
When("an InstallPlan is reporting a failed state", func() {
5959

6060
var (
61-
magicCatalog *MagicCatalog
62-
catalogSourceName string
63-
subscription *operatorsv1alpha1.Subscription
61+
magicCatalog *MagicCatalog
62+
catalogSourceName string
63+
subscription *operatorsv1alpha1.Subscription
64+
originalInstallPlanRef *corev1.ObjectReference
65+
failedInstallPlanRef *corev1.ObjectReference
6466
)
6567

6668
BeforeEach(func() {
69+
By("creating a service account with no permission")
70+
saNameWithNoPerms := genName("scoped-sa-")
71+
newServiceAccount(ctx.Ctx().KubeClient(), ns.GetName(), saNameWithNoPerms)
72+
6773
By("deploying the testing catalog")
6874
provider, err := NewFileBasedFiledBasedCatalogProvider(filepath.Join(testdataDir, failForwardTestDataBaseDir, "example-operator.v0.1.0.yaml"))
6975
Expect(err).To(BeNil())
@@ -90,19 +96,18 @@ var _ = Describe("Fail Forward Upgrades", func() {
9096
subscription, err := fetchSubscription(crclient, subscription.GetNamespace(), subscription.GetName(), subscriptionHasInstallPlanChecker)
9197
Expect(err).Should(BeNil())
9298

93-
originalInstallPlanRef := subscription.Status.InstallPlanRef
99+
originalInstallPlanRef = subscription.Status.InstallPlanRef
94100

95101
By("waiting for the v0.1.0 CSV to report a succeeded phase")
96102
_, err = fetchCSV(crclient, subscription.Status.CurrentCSV, ns.GetName(), buildCSVConditionChecker(operatorsv1alpha1.CSVPhaseSucceeded))
97103
Expect(err).ShouldNot(HaveOccurred())
98104

99-
By("patching the OperatorGroup to reduce the bundle unpacking timeout")
100-
addBundleUnpackTimeoutOGAnnotation(context.Background(), c, types.NamespacedName{Name: ogName, Namespace: ns.GetName()}, "1s")
105+
By("updating the operator group to use the service account without required permissions to simulate InstallPlan failure")
106+
Eventually(operatorGroupServiceAccountNameSetter(crclient, ns.GetName(), ogName, saNameWithNoPerms)).Should(Succeed())
101107

102-
By("updating the catalog with a broken v0.2.0 bundle image")
103-
brokenProvider, err := NewFileBasedFiledBasedCatalogProvider(filepath.Join(testdataDir, failForwardTestDataBaseDir, "example-operator.v0.2.0-non-existent-tag.yaml"))
108+
By("updating the catalog with v0.2.0 bundle image")
109+
brokenProvider, err := NewFileBasedFiledBasedCatalogProvider(filepath.Join(testdataDir, failForwardTestDataBaseDir, "example-operator.v0.2.0.yaml"))
104110
Expect(err).To(BeNil())
105-
106111
err = magicCatalog.UpdateCatalog(context.Background(), brokenProvider)
107112
Expect(err).To(BeNil())
108113

@@ -111,31 +116,29 @@ var _ = Describe("Fail Forward Upgrades", func() {
111116
Expect(err).Should(BeNil())
112117

113118
By("waiting for the bad InstallPlan to report a failed installation state")
114-
ref := subscription.Status.InstallPlanRef
115-
_, err = fetchInstallPlan(GinkgoT(), crclient, ref.Name, ref.Namespace, buildInstallPlanPhaseCheckFunc(operatorsv1alpha1.InstallPlanPhaseFailed))
119+
failedInstallPlanRef = subscription.Status.InstallPlanRef
120+
_, err = fetchInstallPlan(GinkgoT(), crclient, failedInstallPlanRef.Name, failedInstallPlanRef.Namespace, buildInstallPlanPhaseCheckFunc(operatorsv1alpha1.InstallPlanPhaseFailed))
116121
Expect(err).To(BeNil())
117122

123+
By("updating the operator group remove service account without permissions")
124+
Eventually(operatorGroupServiceAccountNameSetter(crclient, ns.GetName(), ogName, "")).Should(Succeed())
118125
})
119126
AfterEach(func() {
120127
By("removing the testing catalog resources")
121128
Expect(magicCatalog.UndeployCatalog(context.Background())).To(BeNil())
122129
})
123130
It("eventually reports a successful state when multiple bad versions are rolled forward", func() {
124-
By("patching the catalog with another bad bundle version")
131+
By("patching the OperatorGroup to reduce the bundle unpacking timeout")
132+
addBundleUnpackTimeoutOGAnnotation(context.Background(), c, types.NamespacedName{Name: ogName, Namespace: ns.GetName()}, "1s")
133+
134+
By("patching the catalog with a bad bundle version")
125135
badProvider, err := NewFileBasedFiledBasedCatalogProvider(filepath.Join(testdataDir, "fail-forward/multiple-bad-versions", "example-operator.v0.2.1-non-existent-tag.yaml"))
126136
Expect(err).To(BeNil())
127-
128137
err = magicCatalog.UpdateCatalog(context.Background(), badProvider)
129138
Expect(err).To(BeNil())
130139

131-
By("waiting for the subscription to have the example-operator.v0.2.1 status.updatedCSV")
132-
subscription, err = fetchSubscription(crclient, subscription.GetNamespace(), subscription.GetName(), subscriptionHasCurrentCSV("example-operator.v0.2.1"))
133-
Expect(err).Should(BeNil())
134-
135-
By("waiting for the bad v0.2.1 InstallPlan to report a failed installation state")
136-
ref := subscription.Status.InstallPlanRef
137-
_, err = fetchInstallPlan(GinkgoT(), crclient, ref.Name, ref.Namespace, buildInstallPlanPhaseCheckFunc(operatorsv1alpha1.InstallPlanPhaseFailed))
138-
Expect(err).To(BeNil())
140+
By("waiting for the subscription to maintain the example-operator.v0.2.0 status.currentCSV")
141+
Consistently(subscriptionCurrentCSVGetter(crclient, subscription.GetNamespace(), subscription.GetName())).Should(Equal("example-operator.v0.2.0"))
139142

140143
By("patching the OperatorGroup to increase the bundle unpacking timeout")
141144
addBundleUnpackTimeoutOGAnnotation(context.Background(), c, types.NamespacedName{Name: ogName, Namespace: ns.GetName()}, "5m")
@@ -146,57 +149,74 @@ var _ = Describe("Fail Forward Upgrades", func() {
146149
err = magicCatalog.UpdateCatalog(context.Background(), fixedProvider)
147150
Expect(err).To(BeNil())
148151

149-
By("waiting for the subscription to have the example-operator.v0.3.0 status.updatedCSV")
150-
subscription, err = fetchSubscription(crclient, subscription.GetNamespace(), subscription.GetName(), subscriptionHasCurrentCSV("example-operator.v0.3.0"))
152+
By("waiting for the subscription to have the example-operator.v0.3.0 status.currentCSV")
153+
_, err = fetchSubscription(crclient, subscription.GetNamespace(), subscription.GetName(), subscriptionHasCurrentCSV("example-operator.v0.3.0"))
154+
Expect(err).Should(BeNil())
155+
156+
By("verifying the subscription is referencing a new InstallPlan")
157+
subscription, err = fetchSubscription(crclient, subscription.GetNamespace(), subscription.GetName(), subscriptionHasInstallPlanDifferentChecker(originalInstallPlanRef.Name))
151158
Expect(err).Should(BeNil())
159+
160+
By("waiting for the fixed v0.3.0 InstallPlan to report a successful state")
161+
ref := subscription.Status.InstallPlanRef
162+
_, err = fetchInstallPlan(GinkgoT(), crclient, ref.Name, ref.Namespace, buildInstallPlanPhaseCheckFunc(operatorsv1alpha1.InstallPlanPhaseComplete))
163+
Expect(err).To(BeNil())
152164
})
153165

154166
It("eventually reports a successful state when using skip ranges", func() {
155-
By("patching the OperatorGroup to increase the bundle unpacking timeout")
156-
addBundleUnpackTimeoutOGAnnotation(context.Background(), c, types.NamespacedName{Name: ogName, Namespace: ns.GetName()}, "5m")
157-
158167
By("patching the catalog with a fixed version")
159168
fixedProvider, err := NewFileBasedFiledBasedCatalogProvider(filepath.Join(testdataDir, "fail-forward/skip-range", "example-operator.v0.3.0.yaml"))
160169
Expect(err).To(BeNil())
161170
err = magicCatalog.UpdateCatalog(context.Background(), fixedProvider)
162171
Expect(err).To(BeNil())
163172

164-
By("waiting for the subscription to have the example-operator.v0.3.0 status.updatedCSV")
165-
subscription, err = fetchSubscription(crclient, subscription.GetNamespace(), subscription.GetName(), subscriptionHasCurrentCSV("example-operator.v0.3.0"))
173+
By("waiting for the subscription to have the example-operator.v0.3.0 status.currentCSV")
174+
_, err = fetchSubscription(crclient, subscription.GetNamespace(), subscription.GetName(), subscriptionHasCurrentCSV("example-operator.v0.3.0"))
175+
Expect(err).Should(BeNil())
176+
177+
By("verifying the subscription is referencing a new InstallPlan")
178+
subscription, err = fetchSubscription(crclient, subscription.GetNamespace(), subscription.GetName(), subscriptionHasInstallPlanDifferentChecker(originalInstallPlanRef.Name))
166179
Expect(err).Should(BeNil())
180+
181+
By("waiting for the fixed v0.3.0 InstallPlan to report a successful state")
182+
ref := subscription.Status.InstallPlanRef
183+
_, err = fetchInstallPlan(GinkgoT(), crclient, ref.Name, ref.Namespace, buildInstallPlanPhaseCheckFunc(operatorsv1alpha1.InstallPlanPhaseComplete))
184+
Expect(err).To(BeNil())
167185
})
168186
It("eventually reports a successful state when using skips", func() {
169-
By("patching the OperatorGroup to increase the bundle unpacking timeout")
170-
addBundleUnpackTimeoutOGAnnotation(context.Background(), c, types.NamespacedName{Name: ogName, Namespace: ns.GetName()}, "5m")
171-
172187
By("patching the catalog with a fixed version")
173188
fixedProvider, err := NewFileBasedFiledBasedCatalogProvider(filepath.Join(testdataDir, "fail-forward/skips", "example-operator.v0.3.0.yaml"))
174189
Expect(err).To(BeNil())
175190
err = magicCatalog.UpdateCatalog(context.Background(), fixedProvider)
176191
Expect(err).To(BeNil())
177192

178-
By("waiting for the subscription to have the example-operator.v0.3.0 status.updatedCSV")
179-
subscription, err = fetchSubscription(crclient, subscription.GetNamespace(), subscription.GetName(), subscriptionHasCurrentCSV("example-operator.v0.3.0"))
193+
By("waiting for the subscription to have the example-operator.v0.3.0 status.currentCSV")
194+
_, err = fetchSubscription(crclient, subscription.GetNamespace(), subscription.GetName(), subscriptionHasCurrentCSV("example-operator.v0.3.0"))
195+
Expect(err).Should(BeNil())
196+
197+
By("verifying the subscription is referencing a new InstallPlan")
198+
subscription, err = fetchSubscription(crclient, subscription.GetNamespace(), subscription.GetName(), subscriptionHasInstallPlanDifferentChecker(originalInstallPlanRef.Name))
180199
Expect(err).Should(BeNil())
200+
201+
By("waiting for the fixed v0.3.0 InstallPlan to report a successful state")
202+
ref := subscription.Status.InstallPlanRef
203+
_, err = fetchInstallPlan(GinkgoT(), crclient, ref.Name, ref.Namespace, buildInstallPlanPhaseCheckFunc(operatorsv1alpha1.InstallPlanPhaseComplete))
204+
Expect(err).To(BeNil())
181205
})
182206
It("eventually reports a failed state when using replaces", func() {
183-
By("patching the OperatorGroup to increase the bundle unpacking timeout")
184-
addBundleUnpackTimeoutOGAnnotation(context.Background(), c, types.NamespacedName{Name: ogName, Namespace: ns.GetName()}, "5m")
185-
186207
By("patching the catalog with a fixed version")
187208
fixedProvider, err := NewFileBasedFiledBasedCatalogProvider(filepath.Join(testdataDir, "fail-forward/replaces", "example-operator.v0.3.0.yaml"))
188209
Expect(err).To(BeNil())
189210
err = magicCatalog.UpdateCatalog(context.Background(), fixedProvider)
190211
Expect(err).To(BeNil())
191212

192-
By("waiting for the subscription to maintain the example-operator.v0.2.0 status.updatedCSV")
193-
Consistently(func() string {
194-
subscription, err := crclient.OperatorsV1alpha1().Subscriptions(subscription.GetNamespace()).Get(context.Background(), subscription.GetName(), metav1.GetOptions{})
195-
if err != nil || subscription == nil {
196-
return ""
197-
}
198-
return subscription.Status.CurrentCSV
199-
}).Should(Equal("example-operator.v0.2.0"))
213+
By("waiting for the subscription to maintain the example-operator.v0.2.0 status.currentCSV")
214+
Consistently(subscriptionCurrentCSVGetter(crclient, subscription.GetNamespace(), subscription.GetName())).Should(Equal("example-operator.v0.2.0"))
215+
216+
By("verifying the subscription is referencing the same InstallPlan")
217+
subscription, err = fetchSubscription(crclient, subscription.GetNamespace(), subscription.GetName(), subscriptionHasInstallPlanChecker)
218+
Expect(err).Should(BeNil())
219+
Expect(subscription.Status.InstallPlanRef.Name).To(Equal(failedInstallPlanRef.Name))
200220
})
201221
})
202222
When("a CSV resource is in a failed state", func() {
@@ -269,7 +289,7 @@ var _ = Describe("Fail Forward Upgrades", func() {
269289
err = magicCatalog.UpdateCatalog(context.Background(), fixedProvider)
270290
Expect(err).To(BeNil())
271291

272-
By("waiting for the subscription to have the example-operator.v0.3.0 status.updatedCSV")
292+
By("waiting for the subscription to have the example-operator.v0.3.0 status.currentCSV")
273293
subscription, err = fetchSubscription(crclient, subscription.GetNamespace(), subscription.GetName(), subscriptionHasCurrentCSV("example-operator.v0.3.0"))
274294
Expect(err).Should(BeNil())
275295
})
@@ -282,7 +302,7 @@ var _ = Describe("Fail Forward Upgrades", func() {
282302
err = magicCatalog.UpdateCatalog(context.Background(), fixedProvider)
283303
Expect(err).To(BeNil())
284304

285-
By("waiting for the subscription to have the example-operator.v0.3.0 status.updatedCSV")
305+
By("waiting for the subscription to have the example-operator.v0.3.0 status.currentCSV")
286306
subscription, err = fetchSubscription(crclient, subscription.GetNamespace(), subscription.GetName(), subscriptionHasCurrentCSV("example-operator.v0.3.0"))
287307
Expect(err).Should(BeNil())
288308
})
@@ -295,7 +315,7 @@ var _ = Describe("Fail Forward Upgrades", func() {
295315
err = magicCatalog.UpdateCatalog(context.Background(), fixedProvider)
296316
Expect(err).To(BeNil())
297317

298-
By("waiting for the subscription to have the example-operator.v0.3.0 status.updatedCSV")
318+
By("waiting for the subscription to have the example-operator.v0.3.0 status.currentCSV")
299319
subscription, err = fetchSubscription(crclient, subscription.GetNamespace(), subscription.GetName(), subscriptionHasCurrentCSV("example-operator.v0.3.0"))
300320
Expect(err).Should(BeNil())
301321
})

0 commit comments

Comments
 (0)