forked from operator-framework/operator-lifecycle-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrd_e2e_test.go
496 lines (443 loc) · 21.5 KB
/
crd_e2e_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
package e2e
import (
"context"
"fmt"
"time"
"github.com/blang/semver/v4"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry"
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
"github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx"
corev1 "k8s.io/api/core/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
var _ = Describe("CRD Versions", func() {
var (
generatedNamespace corev1.Namespace
c operatorclient.ClientInterface
crc versioned.Interface
)
BeforeEach(func() {
c = ctx.Ctx().KubeClient()
crc = ctx.Ctx().OperatorClient()
generatedNamespace = SetupGeneratedTestNamespace(genName("crd-e2e-"))
})
AfterEach(func() {
TeardownNamespace(generatedNamespace.GetName())
})
// issue: https://github.com/operator-framework/operator-lifecycle-manager/issues/2640
It("[FLAKE] creates v1 CRDs with a v1 schema successfully", func() {
By("v1 crds with a valid openapiv3 schema should be created successfully by OLM")
mainPackageName := genName("nginx-update2-")
mainPackageStable := fmt.Sprintf("%s-stable", mainPackageName)
stableChannel := "stable"
crdPlural := genName("ins-")
crdName := crdPlural + ".cluster.com"
v1crd := apiextensionsv1.CustomResourceDefinition{
ObjectMeta: metav1.ObjectMeta{
Name: crdName,
},
Spec: apiextensionsv1.CustomResourceDefinitionSpec{
Scope: apiextensionsv1.NamespaceScoped,
Group: "cluster.com",
Versions: []apiextensionsv1.CustomResourceDefinitionVersion{
{
Name: "v1alpha1",
Served: true,
Storage: true,
Schema: &apiextensionsv1.CustomResourceValidation{
OpenAPIV3Schema: &apiextensionsv1.JSONSchemaProps{
Type: "object",
Description: "my crd schema",
},
},
},
},
},
}
mainCSV := newCSV(mainPackageStable, generatedNamespace.GetName(), "", semver.MustParse("0.1.0"), nil, nil, nil)
mainCatalogName := genName("mock-ocs-main-update2-")
mainManifests := []registry.PackageManifest{
{
PackageName: mainPackageName,
Channels: []registry.PackageChannel{
{Name: stableChannel, CurrentCSVName: mainPackageStable},
},
DefaultChannelName: stableChannel,
},
}
By("Create the catalog sources")
_, cleanupMainCatalogSource := createV1CRDInternalCatalogSource(GinkgoT(), c, crc, mainCatalogName, generatedNamespace.GetName(), mainManifests, []apiextensionsv1.CustomResourceDefinition{v1crd}, []operatorsv1alpha1.ClusterServiceVersion{mainCSV})
defer cleanupMainCatalogSource()
defer func() {
_ = crc.OperatorsV1alpha1().ClusterServiceVersions(generatedNamespace.GetName()).Delete(context.TODO(), mainCSV.GetName(), metav1.DeleteOptions{})
_ = c.ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Delete(context.TODO(), v1crd.GetName(), metav1.DeleteOptions{})
}()
By("Attempt to get the catalog source before creating install plan")
_, err := fetchCatalogSourceOnStatus(crc, mainCatalogName, generatedNamespace.GetName(), catalogSourceRegistryPodSynced())
Expect(err).ToNot(HaveOccurred())
subscriptionName := genName("sub-nginx-update2-")
subscriptionCleanup := createSubscriptionForCatalog(crc, generatedNamespace.GetName(), subscriptionName, mainCatalogName, mainPackageName, stableChannel, "", operatorsv1alpha1.ApprovalAutomatic)
defer subscriptionCleanup()
subscription, err := fetchSubscription(crc, generatedNamespace.GetName(), subscriptionName, subscriptionHasInstallPlanChecker())
Expect(err).ToNot(HaveOccurred())
Expect(subscription).ToNot(Equal(nil))
Expect(subscription.Status.InstallPlanRef).ToNot(Equal(nil))
Expect(mainCSV.GetName()).To(Equal(subscription.Status.CurrentCSV))
installPlanName := subscription.Status.InstallPlanRef.Name
By("Wait for InstallPlan to be status: Complete before checking resource presence")
fetchedInstallPlan, err := fetchInstallPlan(GinkgoT(), crc, installPlanName, generatedNamespace.GetName(), buildInstallPlanPhaseCheckFunc(operatorsv1alpha1.InstallPlanPhaseComplete))
Expect(err).ToNot(HaveOccurred())
GinkgoT().Logf("Install plan %s fetched with status %s", fetchedInstallPlan.GetName(), fetchedInstallPlan.Status.Phase)
Expect(fetchedInstallPlan.Status.Phase).To(Equal(operatorsv1alpha1.InstallPlanPhaseComplete))
})
// issue:https://github.com/operator-framework/operator-lifecycle-manager/issues/2638
It("[FLAKE] blocks a CRD upgrade that could cause data loss", func() {
By("checking the storage versions in the existing CRD status and the spec of the new CRD")
mainPackageName := genName("nginx-update2-")
mainPackageStable := fmt.Sprintf("%s-stable", mainPackageName)
stableChannel := "stable"
crdPlural := genName("ins-")
crdName := crdPlural + ".cluster.com"
oldCRD := apiextensionsv1.CustomResourceDefinition{
ObjectMeta: metav1.ObjectMeta{
Name: crdName,
},
Spec: apiextensionsv1.CustomResourceDefinitionSpec{
Group: "cluster.com",
Versions: []apiextensionsv1.CustomResourceDefinitionVersion{
{
Name: "v1alpha2",
Served: true,
Storage: true,
Schema: &apiextensionsv1.CustomResourceValidation{
OpenAPIV3Schema: &apiextensionsv1.JSONSchemaProps{
Type: "object",
Description: "my crd schema",
},
},
},
{
Name: "v2alpha1",
Served: true,
Storage: false,
Schema: &apiextensionsv1.CustomResourceValidation{
OpenAPIV3Schema: &apiextensionsv1.JSONSchemaProps{
Type: "object",
Description: "my crd schema",
},
},
},
},
Names: apiextensionsv1.CustomResourceDefinitionNames{
Plural: crdPlural,
Singular: crdPlural,
Kind: crdPlural,
ListKind: "list" + crdPlural,
},
Scope: apiextensionsv1.NamespaceScoped,
},
}
alphaChannel := "alpha"
mainPackageAlpha := fmt.Sprintf("%s-alpha", mainPackageName)
newCRD := apiextensionsv1.CustomResourceDefinition{
ObjectMeta: metav1.ObjectMeta{
Name: crdName,
},
Spec: apiextensionsv1.CustomResourceDefinitionSpec{
Group: "cluster.com",
Versions: []apiextensionsv1.CustomResourceDefinitionVersion{
{
Name: "v1alpha3",
Served: true,
Storage: true,
Schema: &apiextensionsv1.CustomResourceValidation{
OpenAPIV3Schema: &apiextensionsv1.JSONSchemaProps{
Type: "object",
Description: "my crd schema",
},
},
},
{
Name: "v2alpha2",
Served: true,
Storage: false,
Schema: &apiextensionsv1.CustomResourceValidation{
OpenAPIV3Schema: &apiextensionsv1.JSONSchemaProps{
Type: "object",
Description: "my crd schema",
},
},
},
},
Names: apiextensionsv1.CustomResourceDefinitionNames{
Plural: crdPlural,
Singular: crdPlural,
Kind: crdPlural,
ListKind: "list" + crdPlural,
},
Scope: apiextensionsv1.NamespaceScoped,
},
}
oldCSV := newCSV(mainPackageStable, generatedNamespace.GetName(), "", semver.MustParse("0.1.0"), []apiextensionsv1.CustomResourceDefinition{oldCRD}, nil, nil)
newCSV := newCSV(mainPackageAlpha, generatedNamespace.GetName(), mainPackageStable, semver.MustParse("0.1.1"), []apiextensionsv1.CustomResourceDefinition{newCRD}, nil, nil)
mainCatalogName := genName("mock-ocs-main-update2-")
mainManifests := []registry.PackageManifest{
{
PackageName: mainPackageName,
Channels: []registry.PackageChannel{
{Name: stableChannel, CurrentCSVName: mainPackageStable},
{Name: alphaChannel, CurrentCSVName: mainPackageAlpha},
},
DefaultChannelName: stableChannel,
},
}
By("Create the catalog sources")
_, cleanupMainCatalogSource := createInternalCatalogSource(c, crc, mainCatalogName, generatedNamespace.GetName(), mainManifests, []apiextensionsv1.CustomResourceDefinition{oldCRD, newCRD}, []operatorsv1alpha1.ClusterServiceVersion{oldCSV, newCSV})
defer cleanupMainCatalogSource()
defer func() {
_ = crc.OperatorsV1alpha1().ClusterServiceVersions(generatedNamespace.GetName()).Delete(context.TODO(), oldCSV.GetName(), metav1.DeleteOptions{})
_ = crc.OperatorsV1alpha1().ClusterServiceVersions(generatedNamespace.GetName()).Delete(context.TODO(), newCSV.GetName(), metav1.DeleteOptions{})
_ = c.ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Delete(context.TODO(), oldCRD.GetName(), metav1.DeleteOptions{})
_ = c.ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Delete(context.TODO(), newCRD.GetName(), metav1.DeleteOptions{})
}()
By("Attempt to get the catalog source before creating install plan")
_, err := fetchCatalogSourceOnStatus(crc, mainCatalogName, generatedNamespace.GetName(), catalogSourceRegistryPodSynced())
Expect(err).ToNot(HaveOccurred())
subscriptionName := genName("sub-nginx-update2-")
subscriptionCleanup := createSubscriptionForCatalog(crc, generatedNamespace.GetName(), subscriptionName, mainCatalogName, mainPackageName, stableChannel, "", operatorsv1alpha1.ApprovalAutomatic)
defer subscriptionCleanup()
subscription, err := fetchSubscription(crc, generatedNamespace.GetName(), subscriptionName, subscriptionHasInstallPlanChecker())
Expect(err).ToNot(HaveOccurred())
Expect(subscription).ToNot(BeNil())
Expect(subscription.Status.InstallPlanRef).ToNot(Equal(nil))
Expect(oldCSV.GetName()).To(Equal(subscription.Status.CurrentCSV))
installPlanName := subscription.Status.InstallPlanRef.Name
By("Wait for InstallPlan to be status: Complete before checking resource presence")
fetchedInstallPlan, err := fetchInstallPlan(GinkgoT(), crc, installPlanName, generatedNamespace.GetName(), buildInstallPlanPhaseCheckFunc(operatorsv1alpha1.InstallPlanPhaseComplete))
Expect(err).ToNot(HaveOccurred())
GinkgoT().Logf("Install plan %s fetched with status %s", fetchedInstallPlan.GetName(), fetchedInstallPlan.Status.Phase)
Expect(fetchedInstallPlan.Status.Phase).To(Equal(operatorsv1alpha1.InstallPlanPhaseComplete))
By("old CRD has been installed onto the cluster - now upgrade the subscription to point to the channel with the new CRD")
By("installing the new CSV should fail with a warning about data loss, since a storage version is missing in the new CRD")
By("use server-side apply to apply the update to the subscription point to the alpha channel")
Eventually(Apply(subscription, func(s *operatorsv1alpha1.Subscription) error {
s.Spec.Channel = alphaChannel
return nil
})).Should(Succeed())
ctx.Ctx().Logf("updated subscription to point to alpha channel")
checker := subscriptionStateAtLatestChecker()
subscriptionAtLatestWithDifferentInstallPlan := func(v *operatorsv1alpha1.Subscription) bool {
return checker(v) && v.Status.InstallPlanRef != nil && v.Status.InstallPlanRef.Name != fetchedInstallPlan.Name
}
By("fetch new subscription")
s, err := fetchSubscription(crc, generatedNamespace.GetName(), subscriptionName, subscriptionAtLatestWithDifferentInstallPlan)
Expect(err).ToNot(HaveOccurred())
Expect(s).ToNot(BeNil())
Expect(s.Status.InstallPlanRef).ToNot(Equal(nil))
By("Check the error on the installplan - should be related to data loss and the CRD upgrade missing a stored version")
Eventually(func() (*operatorsv1alpha1.InstallPlan, error) {
return crc.OperatorsV1alpha1().InstallPlans(generatedNamespace.GetName()).Get(context.TODO(), s.Status.InstallPlanRef.Name, metav1.GetOptions{})
}).Should(And(
WithTransform(
func(v *operatorsv1alpha1.InstallPlan) operatorsv1alpha1.InstallPlanPhase {
return v.Status.Phase
},
Equal(operatorsv1alpha1.InstallPlanPhaseFailed),
),
WithTransform(
func(v *operatorsv1alpha1.InstallPlan) string {
return v.Status.Conditions[len(v.Status.Conditions)-1].Message
},
ContainSubstring("risk of data loss"),
),
))
})
It("allows a CRD upgrade that doesn't cause data loss", func() {
By(`Create a CRD on cluster with v1alpha1 (storage)`)
By(`Update that CRD with v1alpha2 (storage), v1alpha1 (served)`)
By(`Now the CRD should have two versions in status.storedVersions`)
By(`Now make a catalog with a CRD with just v1alpha2 (storage)`)
By(`That should fail because v1alpha1 is still in status.storedVersions - risk of data loss`)
By(`Update the CRD status to remove the v1alpha1`)
By(`Now the installplan should succeed`)
By("manually editing the storage versions in the existing CRD status")
crdPlural := genName("ins-v1-")
crdName := crdPlural + ".cluster.com"
crdGroup := "cluster.com"
oldCRD := &apiextensionsv1.CustomResourceDefinition{
ObjectMeta: metav1.ObjectMeta{
Name: crdName,
},
Spec: apiextensionsv1.CustomResourceDefinitionSpec{
Group: crdGroup,
Versions: []apiextensionsv1.CustomResourceDefinitionVersion{
{
Name: "v1alpha1",
Served: true,
Storage: true,
Schema: &apiextensionsv1.CustomResourceValidation{
OpenAPIV3Schema: &apiextensionsv1.JSONSchemaProps{
Type: "object",
Description: "my crd schema",
},
},
},
},
Names: apiextensionsv1.CustomResourceDefinitionNames{
Plural: crdPlural,
Singular: crdPlural,
Kind: crdPlural,
ListKind: "list" + crdPlural,
},
Scope: apiextensionsv1.NamespaceScoped,
},
}
_, err := c.ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Create(context.TODO(), oldCRD, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred(), "error creating old CRD")
By("wrap CRD update in a poll because of the object has been modified related errors")
Eventually(func() error {
oldCRD, err = c.ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Get(context.TODO(), oldCRD.GetName(), metav1.GetOptions{})
if err != nil {
return err
}
GinkgoT().Logf("old crd status stored versions: %#v", oldCRD.Status.StoredVersions)
By("set v1alpha1 to no longer stored")
oldCRD.Spec.Versions[0].Storage = false
By("update CRD on-cluster with a new version")
oldCRD.Spec.Versions = append(oldCRD.Spec.Versions, apiextensionsv1.CustomResourceDefinitionVersion{
Name: "v1alpha2",
Served: true,
Storage: true,
Schema: &apiextensionsv1.CustomResourceValidation{
OpenAPIV3Schema: &apiextensionsv1.JSONSchemaProps{
Type: "object",
},
},
})
updatedCRD, err := c.ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Update(context.TODO(), oldCRD, metav1.UpdateOptions{})
if err != nil {
return err
}
GinkgoT().Logf("updated crd status stored versions: %#v", updatedCRD.Status.StoredVersions) // both v1alpha1 and v1alpha2 should be in the status
return nil
}).Should(BeNil())
By("create CSV and catalog with just the catalog CRD")
catalogCRD := apiextensionsv1.CustomResourceDefinition{
ObjectMeta: metav1.ObjectMeta{
Name: crdName,
},
Spec: apiextensionsv1.CustomResourceDefinitionSpec{
Group: crdGroup,
Versions: []apiextensionsv1.CustomResourceDefinitionVersion{
{
Name: "v1alpha2",
Served: true,
Storage: true,
Schema: &apiextensionsv1.CustomResourceValidation{
OpenAPIV3Schema: &apiextensionsv1.JSONSchemaProps{
Type: "object",
Description: "my crd schema",
},
},
},
},
Names: apiextensionsv1.CustomResourceDefinitionNames{
Plural: crdPlural,
Singular: crdPlural,
Kind: crdPlural,
ListKind: "list" + crdPlural,
},
Scope: apiextensionsv1.NamespaceScoped,
},
}
mainPackageName := genName("nginx-update2-")
mainPackageStable := fmt.Sprintf("%s-stable", mainPackageName)
stableChannel := "stable"
catalogCSV := newCSV(mainPackageStable, generatedNamespace.GetName(), "", semver.MustParse("0.1.0"), []apiextensionsv1.CustomResourceDefinition{catalogCRD}, nil, nil)
defer func() {
_ = crc.OperatorsV1alpha1().ClusterServiceVersions(generatedNamespace.GetName()).Delete(context.TODO(), catalogCSV.GetName(), metav1.DeleteOptions{})
_ = c.ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Delete(context.TODO(), catalogCRD.GetName(), metav1.DeleteOptions{})
}()
mainCatalogName := genName("mock-ocs-main-update2-")
mainManifests := []registry.PackageManifest{
{
PackageName: mainPackageName,
Channels: []registry.PackageChannel{
{Name: stableChannel, CurrentCSVName: mainPackageStable},
},
DefaultChannelName: stableChannel,
},
}
By("Create the catalog sources")
_, cleanupMainCatalogSource := createInternalCatalogSource(c, crc, mainCatalogName, generatedNamespace.GetName(), mainManifests, []apiextensionsv1.CustomResourceDefinition{catalogCRD}, []operatorsv1alpha1.ClusterServiceVersion{catalogCSV})
defer cleanupMainCatalogSource()
By("Attempt to get the catalog source before creating install plan")
_, err = fetchCatalogSourceOnStatus(crc, mainCatalogName, generatedNamespace.GetName(), catalogSourceRegistryPodSynced())
Expect(err).ToNot(HaveOccurred())
subscriptionName := genName("sub-nginx-update2-")
_ = createSubscriptionForCatalog(crc, generatedNamespace.GetName(), subscriptionName, mainCatalogName, mainPackageName, stableChannel, "", operatorsv1alpha1.ApprovalAutomatic)
subscription, err := fetchSubscription(crc, generatedNamespace.GetName(), subscriptionName, subscriptionHasInstallPlanChecker())
Expect(err).ToNot(HaveOccurred())
Expect(subscription).ToNot(BeNil())
Expect(subscription.Status.InstallPlanRef).ToNot(Equal(nil))
Expect(catalogCSV.GetName()).To(Equal(subscription.Status.CurrentCSV))
By("Check the error on the installplan - should be related to data loss and the CRD upgrade missing a stored version (v1alpha1)")
Eventually(
func() (*operatorsv1alpha1.InstallPlan, error) {
return crc.OperatorsV1alpha1().InstallPlans(generatedNamespace.GetName()).Get(context.TODO(), subscription.Status.InstallPlanRef.Name, metav1.GetOptions{})
},
90*time.Second, // exhaust retries
).Should(WithTransform(
func(v *operatorsv1alpha1.InstallPlan) operatorsv1alpha1.InstallPlanPhase { return v.Status.Phase },
Equal(operatorsv1alpha1.InstallPlanPhaseFailed),
))
By("update CRD status to remove the v1alpha1 stored version")
newCRD, err := c.ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Get(context.TODO(), oldCRD.GetName(), metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred(), "error getting new CRD")
newCRD.Status.StoredVersions = []string{"v1alpha2"}
newCRD, err = c.ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().UpdateStatus(context.TODO(), newCRD, metav1.UpdateOptions{})
Expect(err).ToNot(HaveOccurred(), "error updating new CRD")
GinkgoT().Logf("new crd status stored versions: %#v", newCRD.Status.StoredVersions) // only v1alpha2 should be in the status now
By("install should now succeed")
oldInstallPlanRef := subscription.Status.InstallPlanRef.Name
err = crc.OperatorsV1alpha1().InstallPlans(generatedNamespace.GetName()).Delete(context.TODO(), subscription.Status.InstallPlanRef.Name, metav1.DeleteOptions{})
Expect(err).ToNot(HaveOccurred(), "error deleting failed install plan")
By("remove old subscription")
err = crc.OperatorsV1alpha1().Subscriptions(generatedNamespace.GetName()).Delete(context.TODO(), subscription.GetName(), metav1.DeleteOptions{})
Expect(err).ToNot(HaveOccurred(), "error deleting old subscription")
By("remove old csv")
crc.OperatorsV1alpha1().ClusterServiceVersions(generatedNamespace.GetName()).Delete(context.TODO(), mainPackageStable, metav1.DeleteOptions{})
Expect(err).ToNot(HaveOccurred(), "error deleting old subscription")
By("recreate subscription")
subscriptionNameNew := genName("sub-nginx-update2-new-")
_ = createSubscriptionForCatalog(crc, generatedNamespace.GetName(), subscriptionNameNew, mainCatalogName, mainPackageName, stableChannel, "", operatorsv1alpha1.ApprovalAutomatic)
subscription, err = fetchSubscription(crc, generatedNamespace.GetName(), subscriptionNameNew, subscriptionHasInstallPlanChecker())
Expect(err).ToNot(HaveOccurred())
Expect(subscription).ToNot(BeNil())
Expect(subscription.Status.InstallPlanRef).ToNot(Equal(nil))
Expect(catalogCSV.GetName()).To(Equal(subscription.Status.CurrentCSV))
By("eventually the subscription should create a new install plan")
Eventually(func() bool {
sub, _ := crc.OperatorsV1alpha1().Subscriptions(generatedNamespace.GetName()).Get(context.TODO(), subscription.GetName(), metav1.GetOptions{})
GinkgoT().Logf("waiting for subscription %s to generate a new install plan...", subscription.GetName())
return sub.Status.InstallPlanRef.Name != oldInstallPlanRef
}, 5*time.Minute, 10*time.Second).Should(BeTrue())
By("eventually the new installplan should succeed")
Eventually(func() bool {
sub, _ := crc.OperatorsV1alpha1().Subscriptions(generatedNamespace.GetName()).Get(context.TODO(), subscription.GetName(), metav1.GetOptions{})
ip, err := crc.OperatorsV1alpha1().InstallPlans(generatedNamespace.GetName()).Get(context.TODO(), sub.Status.InstallPlanRef.Name, metav1.GetOptions{})
if apierrors.IsNotFound(err) {
return false
}
GinkgoT().Logf("waiting for installplan to succeed...currently %s", ip.Status.Phase)
return ip.Status.Phase == operatorsv1alpha1.InstallPlanPhaseComplete
}).Should(BeTrue())
GinkgoT().Log("manually reconciled potentially unsafe CRD upgrade")
})
})