@@ -3,6 +3,8 @@ package e2e
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "time"
7
+
6
8
"github.com/blang/semver"
7
9
. "github.com/onsi/ginkgo"
8
10
. "github.com/onsi/gomega"
@@ -13,7 +15,6 @@ import (
13
15
apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
14
16
k8serrors "k8s.io/apimachinery/pkg/api/errors"
15
17
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
16
- "time"
17
18
)
18
19
19
20
var _ = Describe ("CRD Versions" , func () {
@@ -306,21 +307,33 @@ var _ = Describe("CRD Versions", func() {
306
307
_ , err = crc .OperatorsV1alpha1 ().Subscriptions (testNamespace ).Update (context .TODO (), sub , metav1.UpdateOptions {})
307
308
Expect (err ).ToNot (HaveOccurred (), "could not update subscription" )
308
309
310
+ subscriptionAtLatestWithDifferentInstallPlan := func (v * operatorsv1alpha1.Subscription ) bool {
311
+ return subscriptionStateAtLatestChecker (v ) && v .Status .InstallPlanRef != nil && v .Status .InstallPlanRef .Name != fetchedInstallPlan .Name
312
+ }
313
+
309
314
// fetch new subscription
310
- s , err := fetchSubscription (crc , testNamespace , subscriptionName , subscriptionStateAtLatestChecker )
315
+ s , err := fetchSubscription (crc , testNamespace , subscriptionName , subscriptionAtLatestWithDifferentInstallPlan )
311
316
Expect (err ).ToNot (HaveOccurred ())
312
317
Expect (s ).ToNot (BeNil ())
313
318
Expect (s .Status .InstallPlanRef ).ToNot (Equal (nil ))
314
319
315
320
// Check the error on the installplan - should be related to data loss and the CRD upgrade missing a stored version
316
- Eventually (func () bool {
317
- ip , err := crc .OperatorsV1alpha1 ().InstallPlans (testNamespace ).Get (context .TODO (), s .Status .InstallPlanRef .Name , metav1.GetOptions {})
318
- Expect (err ).ToNot (HaveOccurred (), "could not get installplan" )
319
-
320
- Expect (ip .Status .Phase ).To (Equal (operatorsv1alpha1 .InstallPlanPhaseFailed ))
321
- Expect (ip .Status .Conditions [len (ip .Status .Conditions )- 1 ].Message ).To (ContainSubstring ("risk of data loss" ))
322
- return true
323
- }).Should (BeTrue ())
321
+ Eventually (func () (* operatorsv1alpha1.InstallPlan , error ) {
322
+ return crc .OperatorsV1alpha1 ().InstallPlans (testNamespace ).Get (context .TODO (), s .Status .InstallPlanRef .Name , metav1.GetOptions {})
323
+ }).Should (And (
324
+ WithTransform (
325
+ func (v * operatorsv1alpha1.InstallPlan ) operatorsv1alpha1.InstallPlanPhase {
326
+ return v .Status .Phase
327
+ },
328
+ Equal (operatorsv1alpha1 .InstallPlanPhaseFailed ),
329
+ ),
330
+ WithTransform (
331
+ func (v * operatorsv1alpha1.InstallPlan ) string {
332
+ return v .Status .Conditions [len (v .Status .Conditions )- 1 ].Message
333
+ },
334
+ ContainSubstring ("risk of data loss" ),
335
+ ),
336
+ ))
324
337
})
325
338
326
339
// Create a CRD on cluster with v1alpha1 (storage)
@@ -369,7 +382,9 @@ var _ = Describe("CRD Versions", func() {
369
382
// wrap CRD update in a poll because of the object has been modified related errors
370
383
Eventually (func () error {
371
384
oldCRD , err = c .ApiextensionsInterface ().ApiextensionsV1beta1 ().CustomResourceDefinitions ().Get (context .TODO (), oldCRD .GetName (), metav1.GetOptions {})
372
- Expect (err ).ToNot (HaveOccurred (), "error getting old CRD" )
385
+ if err != nil {
386
+ return err
387
+ }
373
388
GinkgoT ().Logf ("old crd status stored versions: %#v" , oldCRD .Status .StoredVersions )
374
389
375
390
// set v1alpha1 to no longer served
@@ -448,12 +463,12 @@ var _ = Describe("CRD Versions", func() {
448
463
Expect (catalogCSV .GetName ()).To (Equal (subscription .Status .CurrentCSV ))
449
464
450
465
// Check the error on the installplan - should be related to data loss and the CRD upgrade missing a stored version (v1alpha1)
451
- Eventually (func () bool {
452
- ip , err := crc .OperatorsV1alpha1 ().InstallPlans (testNamespace ).Get (context .TODO (), subscription .Status .InstallPlanRef .Name , metav1.GetOptions {})
453
- Expect ( err ). ToNot ( HaveOccurred (), "could not get installplan" )
454
-
455
- return ip . Status . Phase == operatorsv1alpha1 .InstallPlanPhaseFailed
456
- }). Should ( BeTrue ( ))
466
+ Eventually (func () ( * operatorsv1alpha1. InstallPlan , error ) {
467
+ return crc .OperatorsV1alpha1 ().InstallPlans (testNamespace ).Get (context .TODO (), subscription .Status .InstallPlanRef .Name , metav1.GetOptions {})
468
+ }). Should ( WithTransform (
469
+ func ( v * operatorsv1alpha1. InstallPlan ) operatorsv1alpha1. InstallPlanPhase { return v . Status . Phase },
470
+ Equal ( operatorsv1alpha1 .InstallPlanPhaseFailed ),
471
+ ))
457
472
458
473
// update CRD status to remove the v1alpha1 stored version
459
474
newCRD , err := c .ApiextensionsInterface ().ApiextensionsV1beta1 ().CustomResourceDefinitions ().Get (context .TODO (), oldCRD .GetName (), metav1.GetOptions {})
0 commit comments