Skip to content

Commit c7d2b42

Browse files
tmshortPer Goncalves da Silva
authored andcommitted
Fix Condition check for Reconcile InstallPlan status (#3153)
Fix #3151 Remove non-InstallPlan related checks for this test. Also: * Clean up some looping log messages * Clean up some logging added when comments were converted These comments/logs are at the beginning of the test, and are also part of the test sequence, so they are redundant (and possibly confusing) Signed-off-by: Todd Short <[email protected]> Upstream-repository: operator-lifecycle-manager Upstream-commit: 5299830576c8e8e6cd728b08a3a2e60f212ba387
1 parent 31e7b19 commit c7d2b42

File tree

3 files changed

+77
-30
lines changed

3 files changed

+77
-30
lines changed

staging/operator-lifecycle-manager/test/e2e/crd_e2e_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,12 @@ var _ = Describe("CRD Versions", func() {
264264
return subscriptionStateAtLatestChecker(v) && v.Status.InstallPlanRef != nil && v.Status.InstallPlanRef.Name != fetchedInstallPlan.Name
265265
}
266266

267-
// fetch new subscription
268-
s, err := fetchSubscription(crc, generatedNamespace.GetName(), subscriptionName, subscriptionAtLatestWithDifferentInstallPlan)
269-
Expect(err).ToNot(HaveOccurred())
270-
Expect(s).ToNot(BeNil())
271-
Expect(s.Status.InstallPlanRef).ToNot(Equal(nil))
272-
273267
// Check the error on the installplan - should be related to data loss and the CRD upgrade missing a stored version
274268
Eventually(func() (*operatorsv1alpha1.InstallPlan, error) {
269+
s, err := fetchSubscription(crc, generatedNamespace.GetName(), subscriptionName, subscriptionAtLatestWithDifferentInstallPlan)
270+
if err != nil || s.Status.InstallPlanRef == nil {
271+
return nil, err
272+
}
275273
return crc.OperatorsV1alpha1().InstallPlans(generatedNamespace.GetName()).Get(context.TODO(), s.Status.InstallPlanRef.Name, metav1.GetOptions{})
276274
}).Should(And(
277275
WithTransform(

staging/operator-lifecycle-manager/test/e2e/csv_e2e_test.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3670,14 +3670,16 @@ var _ = Describe("ClusterServiceVersion", func() {
36703670
},
36713671
}
36723672

3673-
// Fetch the current csv
3674-
fetchedCSV, err := fetchCSV(crc, csv.Name, generatedNamespace.GetName(), csvSucceededChecker)
3675-
Expect(err).ShouldNot(HaveOccurred())
3673+
Eventually(func() error {
3674+
// Fetch the current csv
3675+
fetchedCSV, err := fetchCSV(crc, csv.Name, generatedNamespace.GetName(), csvSucceededChecker)
3676+
if err != nil {
3677+
return err
3678+
}
36763679

3677-
// Update csv with modified deployment spec
3678-
fetchedCSV.Spec.InstallStrategy.StrategySpec = strategyNew
3680+
// Update csv with modified deployment spec
3681+
fetchedCSV.Spec.InstallStrategy.StrategySpec = strategyNew
36793682

3680-
Eventually(func() error {
36813683
// Update the current csv
36823684
_, err = crc.OperatorsV1alpha1().ClusterServiceVersions(generatedNamespace.GetName()).Update(context.TODO(), fetchedCSV, metav1.UpdateOptions{})
36833685
return err
@@ -3688,10 +3690,14 @@ var _ = Describe("ClusterServiceVersion", func() {
36883690

36893691
// Should have updated existing deployment
36903692
depUpdated, err := c.GetDeployment(generatedNamespace.GetName(), strategyNew.DeploymentSpecs[0].Name)
3691-
Expect(err).ShouldNot(HaveOccurred())
3692-
Expect(depUpdated).ShouldNot(BeNil())
3693+
if err != nil || depUpdated == nil {
3694+
return false
3695+
}
3696+
36933697
// container name has been updated and differs from initial CSV spec and updated CSV spec
3694-
Expect(depUpdated.Spec.Template.Spec.Containers[0].Name).ShouldNot(Equal(strategyNew.DeploymentSpecs[0].Spec.Template.Spec.Containers[0].Name))
3698+
if depUpdated.Spec.Template.Spec.Containers[0].Name != strategyNew.DeploymentSpecs[0].Spec.Template.Spec.Containers[0].Name {
3699+
return false
3700+
}
36953701

36963702
// Check for success
36973703
return csvSucceededChecker(csv)
@@ -4394,7 +4400,7 @@ var csvFailedChecker = buildCSVConditionChecker(operatorsv1alpha1.CSVPhaseFailed
43944400
var csvAnyChecker = buildCSVConditionChecker(operatorsv1alpha1.CSVPhasePending, operatorsv1alpha1.CSVPhaseSucceeded, operatorsv1alpha1.CSVPhaseReplacing, operatorsv1alpha1.CSVPhaseDeleting, operatorsv1alpha1.CSVPhaseFailed)
43954401
var csvCopiedChecker = buildCSVReasonChecker(operatorsv1alpha1.CSVReasonCopied)
43964402

4397-
func fetchCSV(c versioned.Interface, namespace, name string, checker csvConditionChecker) (*operatorsv1alpha1.ClusterServiceVersion, error) {
4403+
func fetchCSV(c versioned.Interface, name, namespace string, checker csvConditionChecker) (*operatorsv1alpha1.ClusterServiceVersion, error) {
43984404
var lastPhase operatorsv1alpha1.ClusterServiceVersionPhase
43994405
var lastReason operatorsv1alpha1.ConditionReason
44004406
var lastMessage string

staging/operator-lifecycle-manager/test/e2e/subscription_e2e_test.go

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import (
3636
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
3737
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry"
3838
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/projection"
39-
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/comparison"
4039
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
4140
"github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx"
4241
registryapi "github.com/operator-framework/operator-registry/pkg/api"
@@ -498,14 +497,20 @@ var _ = Describe("Subscription", func() {
498497
return subscription != nil && subscription.Status.InstallPlanRef.Name != fetchedInstallPlan.GetName() && subscription.Status.State == operatorsv1alpha1.SubscriptionStateUpgradePending, err
499498
}, 5*time.Minute, 1*time.Second).Should(BeTrue(), "expected new installplan for upgraded csv")
500499

501-
upgradeInstallPlan, err := fetchInstallPlanWithNamespace(GinkgoT(), crc, subscription.Status.InstallPlanRef.Name, generatedNamespace.GetName(), requiresApprovalChecker)
502-
require.NoError(GinkgoT(), err)
503-
504-
// Approve the upgrade installplan and wait for
505-
upgradeInstallPlan.Spec.Approved = true
506-
_, err = crc.OperatorsV1alpha1().InstallPlans(generatedNamespace.GetName()).Update(context.Background(), upgradeInstallPlan, metav1.UpdateOptions{})
507-
require.NoError(GinkgoT(), err)
500+
// Approve install plan
501+
Eventually(func() (bool, error) {
502+
upgradeInstallPlan, err := fetchInstallPlanWithNamespace(GinkgoT(), crc, subscription.Status.InstallPlanRef.Name, generatedNamespace.GetName(), requiresApprovalChecker)
503+
if err != nil {
504+
return false, nil
505+
}
508506

507+
// Approve the upgrade installplan and wait for
508+
upgradeInstallPlan.Spec.Approved = true
509+
if _, err = crc.OperatorsV1alpha1().InstallPlans(generatedNamespace.GetName()).Update(context.Background(), upgradeInstallPlan, metav1.UpdateOptions{}); err != nil {
510+
return false, nil
511+
}
512+
return true, nil
513+
}, 1*time.Minute, 5*time.Second).Should(BeTrue(), "expected new installplan for upgraded csv")
509514
_, err = awaitCSV(crc, generatedNamespace.GetName(), csvB.GetName(), csvSucceededChecker)
510515
require.NoError(GinkgoT(), err)
511516

@@ -1035,6 +1040,7 @@ var _ = Describe("Subscription", func() {
10351040
// - Wait for sub to have status condition SubscriptionInstallPlanMissing true
10361041
// - Ensure original non-InstallPlan status conditions remain after InstallPlan transitions
10371042
It("can reconcile InstallPlan status", func() {
1043+
By(`TestSubscriptionInstallPlanStatus ensures that a Subscription has the appropriate status conditions for possible referenced InstallPlan states.`)
10381044
c := newKubeClient()
10391045
crc := newCRClient()
10401046

@@ -1081,6 +1087,7 @@ var _ = Describe("Subscription", func() {
10811087
ref := sub.Status.InstallPlanRef
10821088
Expect(ref).ToNot(BeNil())
10831089

1090+
By(`Get the InstallPlan`)
10841091
plan := &operatorsv1alpha1.InstallPlan{}
10851092
plan.SetNamespace(ref.Namespace)
10861093
plan.SetName(ref.Name)
@@ -1192,16 +1199,13 @@ var _ = Describe("Subscription", func() {
11921199
Expect(err).ToNot(HaveOccurred())
11931200
Expect(sub).ToNot(BeNil())
11941201

1195-
// Ensure original non-InstallPlan status conditions remain after InstallPlan transitions
1196-
hashEqual := comparison.NewHashEqualitor()
1202+
By(`Ensure InstallPlan-related status conditions match what we're expecting`)
11971203
for _, cond := range conds {
11981204
switch condType := cond.Type; condType {
11991205
case operatorsv1alpha1.SubscriptionInstallPlanPending, operatorsv1alpha1.SubscriptionInstallPlanFailed:
12001206
require.FailNowf(GinkgoT(), "failed", "subscription contains unexpected installplan condition: %v", cond)
12011207
case operatorsv1alpha1.SubscriptionInstallPlanMissing:
12021208
require.Equal(GinkgoT(), operatorsv1alpha1.ReferencedInstallPlanNotFound, cond.Reason)
1203-
default:
1204-
require.True(GinkgoT(), hashEqual(cond, sub.Status.GetCondition(condType)), "non-installplan status condition changed")
12051209
}
12061210
}
12071211
})
@@ -2825,14 +2829,53 @@ func subscriptionHasCurrentCSV(currentCSV string) subscriptionStateChecker {
28252829
}
28262830

28272831
func subscriptionHasCondition(condType operatorsv1alpha1.SubscriptionConditionType, status corev1.ConditionStatus, reason, message string) subscriptionStateChecker {
2832+
var lastCond operatorsv1alpha1.SubscriptionCondition
2833+
lastTime := time.Now()
2834+
// if status/reason/message meet expectations, then subscription state is considered met/true
2835+
// IFF this is the result of a recent change of status/reason/message
2836+
// else, cache the current status/reason/message for next loop/comparison
28282837
return func(subscription *operatorsv1alpha1.Subscription) bool {
28292838
cond := subscription.Status.GetCondition(condType)
28302839
if cond.Status == status && cond.Reason == reason && cond.Message == message {
2831-
fmt.Printf("subscription condition met %v\n", cond)
2840+
if lastCond.Status != cond.Status && lastCond.Reason != cond.Reason && lastCond.Message == cond.Message {
2841+
GinkgoT().Logf("waited %s subscription condition met %v\n", time.Since(lastTime), cond)
2842+
lastTime = time.Now()
2843+
lastCond = cond
2844+
}
2845+
return true
2846+
}
2847+
2848+
if lastCond.Status != cond.Status && lastCond.Reason != cond.Reason && lastCond.Message == cond.Message {
2849+
GinkgoT().Logf("waited %s subscription condition not met: %v\n", time.Since(lastTime), cond)
2850+
lastTime = time.Now()
2851+
lastCond = cond
2852+
}
2853+
return false
2854+
}
2855+
}
2856+
2857+
func subscriptionDoesNotHaveCondition(condType operatorsv1alpha1.SubscriptionConditionType) subscriptionStateChecker {
2858+
var lastStatus corev1.ConditionStatus
2859+
lastTime := time.Now()
2860+
// if status meets expectations, then subscription state is considered met/true
2861+
// IFF this is the result of a recent change of status
2862+
// else, cache the current status for next loop/comparison
2863+
return func(subscription *operatorsv1alpha1.Subscription) bool {
2864+
cond := subscription.Status.GetCondition(condType)
2865+
if cond.Status == corev1.ConditionUnknown {
2866+
if cond.Status != lastStatus {
2867+
GinkgoT().Logf("waited %s subscription condition not found\n", time.Since(lastTime))
2868+
lastStatus = cond.Status
2869+
lastTime = time.Now()
2870+
}
28322871
return true
28332872
}
28342873

2835-
fmt.Printf("subscription condition not met: %v\n", cond)
2874+
if cond.Status != lastStatus {
2875+
GinkgoT().Logf("waited %s subscription condition found: %v\n", time.Since(lastTime), cond)
2876+
lastStatus = cond.Status
2877+
lastTime = time.Now()
2878+
}
28362879
return false
28372880
}
28382881
}

0 commit comments

Comments
 (0)