Skip to content

Commit 5299830

Browse files
authored
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]>
1 parent f94a5ed commit 5299830

File tree

1 file changed

+39
-38
lines changed

1 file changed

+39
-38
lines changed

test/e2e/subscription_e2e_test.go

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import (
3838
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
3939
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry"
4040
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/projection"
41-
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/comparison"
4241
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
4342
"github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx"
4443
registryapi "github.com/operator-framework/operator-registry/pkg/api"
@@ -1029,29 +1028,7 @@ var _ = Describe("Subscription", func() {
10291028
})
10301029

10311030
It("can reconcile InstallPlan status", func() {
1032-
By(`TestSubscriptionInstallPlanStatus ensures that a Subscription has the appropriate status conditions for possible referenced`)
1033-
By(`InstallPlan states.`)
1034-
By(` BySteps:`)
1035-
By(`- Utilize the namespace and OG targeting that namespace created in the BeforeEach clause`)
1036-
By(`- Create CatalogSource, cs, in ns`)
1037-
By(`- Create Subscription to a package of cs in ns, sub`)
1038-
By(`- Wait for the package from sub to install successfully with no remaining InstallPlan status conditions`)
1039-
By(`- Store conditions for later comparision`)
1040-
By(`- Get the InstallPlan`)
1041-
By(`- Set the InstallPlan's approval mode to Manual`)
1042-
By(`- Set the InstallPlan's phase to None`)
1043-
By(`- Wait for sub to have status condition SubscriptionInstallPlanPending true and reason InstallPlanNotYetReconciled`)
1044-
By(`- Get the latest IntallPlan and set the phase to InstallPlanPhaseRequiresApproval`)
1045-
By(`- Wait for sub to have status condition SubscriptionInstallPlanPending true and reason RequiresApproval`)
1046-
By(`- Get the latest InstallPlan and set the phase to InstallPlanPhaseInstalling`)
1047-
By(`- Wait for sub to have status condition SubscriptionInstallPlanPending true and reason Installing`)
1048-
By(`- Get the latest InstallPlan and set the phase to InstallPlanPhaseFailed and remove all status conditions`)
1049-
By(`- Wait for sub to have status condition SubscriptionInstallPlanFailed true and reason InstallPlanFailed`)
1050-
By(`- Get the latest InstallPlan and set status condition of type Installed to false with reason InstallComponentFailed`)
1051-
By(`- Wait for sub to have status condition SubscriptionInstallPlanFailed true and reason InstallComponentFailed`)
1052-
By(`- Delete the referenced InstallPlan`)
1053-
By(`- Wait for sub to have status condition SubscriptionInstallPlanMissing true`)
1054-
By(`- Ensure original non-InstallPlan status conditions remain after InstallPlan transitions`)
1031+
By(`TestSubscriptionInstallPlanStatus ensures that a Subscription has the appropriate status conditions for possible referenced InstallPlan states.`)
10551032
c := newKubeClient()
10561033
crc := newCRClient()
10571034

@@ -1099,6 +1076,7 @@ var _ = Describe("Subscription", func() {
10991076
ref := sub.Status.InstallPlanRef
11001077
Expect(ref).ToNot(BeNil())
11011078

1079+
By(`Get the InstallPlan`)
11021080
plan := &operatorsv1alpha1.InstallPlan{}
11031081
plan.SetNamespace(ref.Namespace)
11041082
plan.SetName(ref.Name)
@@ -1151,14 +1129,14 @@ var _ = Describe("Subscription", func() {
11511129
return true
11521130
}
11531131

1154-
By(`Sometimes the transition from installing to complete can be so quick that the test does not capture`)
1155-
By(`the condition in the subscription before it is removed. To mitigate this, we check if the installplan`)
1156-
By(`has transitioned to complete and exit out the fetch subscription loop if so.`)
1157-
By(`This is a mitigation. We should probably fix this test appropriately.`)
1158-
By(`issue: https://github.com/operator-framework/operator-lifecycle-manager/issues/2667`)
1132+
// Sometimes the transition from installing to complete can be so quick that the test does not capture
1133+
// the condition in the subscription before it is removed. To mitigate this, we check if the installplan
1134+
// has transitioned to complete and exit out the fetch subscription loop if so.
1135+
// This is a mitigation. We should probably fix this test appropriately.
1136+
// issue: https://github.com/operator-framework/operator-lifecycle-manager/issues/2667
11591137
ip, err := crc.OperatorsV1alpha1().InstallPlans(generatedNamespace.GetName()).Get(context.TODO(), plan.Name, metav1.GetOptions{})
11601138
if err != nil {
1161-
By(`retry on failure`)
1139+
// retry on failure
11621140
return false
11631141
}
11641142
isInstallPlanComplete := ip.Status.Phase == operatorsv1alpha1.InstallPlanPhaseComplete
@@ -1210,16 +1188,13 @@ var _ = Describe("Subscription", func() {
12101188
Expect(err).ToNot(HaveOccurred())
12111189
Expect(sub).ToNot(BeNil())
12121190

1213-
By(`Ensure original non-InstallPlan status conditions remain after InstallPlan transitions`)
1214-
hashEqual := comparison.NewHashEqualitor()
1191+
By(`Ensure InstallPlan-related status conditions match what we're expecting`)
12151192
for _, cond := range conds {
12161193
switch condType := cond.Type; condType {
12171194
case operatorsv1alpha1.SubscriptionInstallPlanPending, operatorsv1alpha1.SubscriptionInstallPlanFailed:
12181195
require.FailNowf(GinkgoT(), "failed", "subscription contains unexpected installplan condition: %v", cond)
12191196
case operatorsv1alpha1.SubscriptionInstallPlanMissing:
12201197
require.Equal(GinkgoT(), operatorsv1alpha1.ReferencedInstallPlanNotFound, cond.Reason)
1221-
default:
1222-
require.True(GinkgoT(), hashEqual(cond, sub.Status.GetCondition(condType)), "non-installplan status condition changed")
12231198
}
12241199
}
12251200
})
@@ -3218,27 +3193,53 @@ func subscriptionHasCurrentCSV(currentCSV string) subscriptionStateChecker {
32183193
}
32193194

32203195
func subscriptionHasCondition(condType operatorsv1alpha1.SubscriptionConditionType, status corev1.ConditionStatus, reason, message string) subscriptionStateChecker {
3196+
var lastCond operatorsv1alpha1.SubscriptionCondition
3197+
lastTime := time.Now()
3198+
// if status/reason/message meet expectations, then subscription state is considered met/true
3199+
// IFF this is the result of a recent change of status/reason/message
3200+
// else, cache the current status/reason/message for next loop/comparison
32213201
return func(subscription *operatorsv1alpha1.Subscription) bool {
32223202
cond := subscription.Status.GetCondition(condType)
32233203
if cond.Status == status && cond.Reason == reason && cond.Message == message {
3224-
fmt.Printf("subscription condition met %v\n", cond)
3204+
if lastCond.Status != cond.Status && lastCond.Reason != cond.Reason && lastCond.Message == cond.Message {
3205+
GinkgoT().Logf("waited %s subscription condition met %v\n", time.Since(lastTime), cond)
3206+
lastTime = time.Now()
3207+
lastCond = cond
3208+
}
32253209
return true
32263210
}
32273211

3228-
fmt.Printf("subscription condition not met: %v\n", cond)
3212+
if lastCond.Status != cond.Status && lastCond.Reason != cond.Reason && lastCond.Message == cond.Message {
3213+
GinkgoT().Logf("waited %s subscription condition not met: %v\n", time.Since(lastTime), cond)
3214+
lastTime = time.Now()
3215+
lastCond = cond
3216+
}
32293217
return false
32303218
}
32313219
}
32323220

32333221
func subscriptionDoesNotHaveCondition(condType operatorsv1alpha1.SubscriptionConditionType) subscriptionStateChecker {
3222+
var lastStatus corev1.ConditionStatus
3223+
lastTime := time.Now()
3224+
// if status meets expectations, then subscription state is considered met/true
3225+
// IFF this is the result of a recent change of status
3226+
// else, cache the current status for next loop/comparison
32343227
return func(subscription *operatorsv1alpha1.Subscription) bool {
32353228
cond := subscription.Status.GetCondition(condType)
32363229
if cond.Status == corev1.ConditionUnknown {
3237-
fmt.Printf("subscription condition not found\n")
3230+
if cond.Status != lastStatus {
3231+
GinkgoT().Logf("waited %s subscription condition not found\n", time.Since(lastTime))
3232+
lastStatus = cond.Status
3233+
lastTime = time.Now()
3234+
}
32383235
return true
32393236
}
32403237

3241-
fmt.Printf("subscription condition found: %v\n", cond)
3238+
if cond.Status != lastStatus {
3239+
GinkgoT().Logf("waited %s subscription condition found: %v\n", time.Since(lastTime), cond)
3240+
lastStatus = cond.Status
3241+
lastTime = time.Now()
3242+
}
32423243
return false
32433244
}
32443245
}

0 commit comments

Comments
 (0)