Skip to content

Commit 5a081f0

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 807dac9 commit 5a081f0

File tree

3 files changed

+47
-10
lines changed

3 files changed

+47
-10
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
10921092
Expect(subscription).ShouldNot(BeNil())
10931093

10941094
By("waiting for busybox v2 csv to succeed and check the replaces field")
1095-
csv, err := fetchCSV(crc, subscription.Status.CurrentCSV, subscription.GetNamespace(), csvSucceededChecker)
1095+
csv, err := fetchCSV(crc, subscription.GetNamespace(), subscription.Status.CurrentCSV, csvSucceededChecker)
10961096
Expect(err).ShouldNot(HaveOccurred())
10971097
Expect(csv.Spec.Replaces).To(Equal("busybox.v1.0.0"))
10981098

@@ -1105,7 +1105,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
11051105
Expect(subscription).ShouldNot(BeNil())
11061106

11071107
By("waiting for busybox-dependency v2 csv to succeed and check the replaces field")
1108-
csv, err = fetchCSV(crc, subscription.Status.CurrentCSV, subscription.GetNamespace(), csvSucceededChecker)
1108+
csv, err = fetchCSV(crc, subscription.GetNamespace(), subscription.Status.CurrentCSV, csvSucceededChecker)
11091109
Expect(err).ShouldNot(HaveOccurred())
11101110
Expect(csv.Spec.Replaces).To(Equal("busybox-dependency.v1.0.0"))
11111111
})

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4427,7 +4427,7 @@ var csvFailedChecker = buildCSVConditionChecker(operatorsv1alpha1.CSVPhaseFailed
44274427
var csvAnyChecker = buildCSVConditionChecker(operatorsv1alpha1.CSVPhasePending, operatorsv1alpha1.CSVPhaseSucceeded, operatorsv1alpha1.CSVPhaseReplacing, operatorsv1alpha1.CSVPhaseDeleting, operatorsv1alpha1.CSVPhaseFailed)
44284428
var csvCopiedChecker = buildCSVReasonChecker(operatorsv1alpha1.CSVReasonCopied)
44294429

4430-
func fetchCSV(c versioned.Interface, namespace, name string, checker csvConditionChecker) (*operatorsv1alpha1.ClusterServiceVersion, error) {
4430+
func fetchCSV(c versioned.Interface, name, namespace string, checker csvConditionChecker) (*operatorsv1alpha1.ClusterServiceVersion, error) {
44314431
var lastPhase operatorsv1alpha1.ClusterServiceVersionPhase
44324432
var lastReason operatorsv1alpha1.ConditionReason
44334433
var lastMessage string

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

Lines changed: 44 additions & 7 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"
@@ -1035,6 +1034,7 @@ var _ = Describe("Subscription", func() {
10351034
// - Wait for sub to have status condition SubscriptionInstallPlanMissing true
10361035
// - Ensure original non-InstallPlan status conditions remain after InstallPlan transitions
10371036
It("can reconcile InstallPlan status", func() {
1037+
By(`TestSubscriptionInstallPlanStatus ensures that a Subscription has the appropriate status conditions for possible referenced InstallPlan states.`)
10381038
c := newKubeClient()
10391039
crc := newCRClient()
10401040

@@ -1081,6 +1081,7 @@ var _ = Describe("Subscription", func() {
10811081
ref := sub.Status.InstallPlanRef
10821082
Expect(ref).ToNot(BeNil())
10831083

1084+
By(`Get the InstallPlan`)
10841085
plan := &operatorsv1alpha1.InstallPlan{}
10851086
plan.SetNamespace(ref.Namespace)
10861087
plan.SetName(ref.Name)
@@ -1192,16 +1193,13 @@ var _ = Describe("Subscription", func() {
11921193
Expect(err).ToNot(HaveOccurred())
11931194
Expect(sub).ToNot(BeNil())
11941195

1195-
// Ensure original non-InstallPlan status conditions remain after InstallPlan transitions
1196-
hashEqual := comparison.NewHashEqualitor()
1196+
By(`Ensure InstallPlan-related status conditions match what we're expecting`)
11971197
for _, cond := range conds {
11981198
switch condType := cond.Type; condType {
11991199
case operatorsv1alpha1.SubscriptionInstallPlanPending, operatorsv1alpha1.SubscriptionInstallPlanFailed:
12001200
require.FailNowf(GinkgoT(), "failed", "subscription contains unexpected installplan condition: %v", cond)
12011201
case operatorsv1alpha1.SubscriptionInstallPlanMissing:
12021202
require.Equal(GinkgoT(), operatorsv1alpha1.ReferencedInstallPlanNotFound, cond.Reason)
1203-
default:
1204-
require.True(GinkgoT(), hashEqual(cond, sub.Status.GetCondition(condType)), "non-installplan status condition changed")
12051203
}
12061204
}
12071205
})
@@ -2825,14 +2823,53 @@ func subscriptionHasCurrentCSV(currentCSV string) subscriptionStateChecker {
28252823
}
28262824

28272825
func subscriptionHasCondition(condType operatorsv1alpha1.SubscriptionConditionType, status corev1.ConditionStatus, reason, message string) subscriptionStateChecker {
2826+
var lastCond operatorsv1alpha1.SubscriptionCondition
2827+
lastTime := time.Now()
2828+
// if status/reason/message meet expectations, then subscription state is considered met/true
2829+
// IFF this is the result of a recent change of status/reason/message
2830+
// else, cache the current status/reason/message for next loop/comparison
28282831
return func(subscription *operatorsv1alpha1.Subscription) bool {
28292832
cond := subscription.Status.GetCondition(condType)
28302833
if cond.Status == status && cond.Reason == reason && cond.Message == message {
2831-
fmt.Printf("subscription condition met %v\n", cond)
2834+
if lastCond.Status != cond.Status && lastCond.Reason != cond.Reason && lastCond.Message == cond.Message {
2835+
GinkgoT().Logf("waited %s subscription condition met %v\n", time.Since(lastTime), cond)
2836+
lastTime = time.Now()
2837+
lastCond = cond
2838+
}
2839+
return true
2840+
}
2841+
2842+
if lastCond.Status != cond.Status && lastCond.Reason != cond.Reason && lastCond.Message == cond.Message {
2843+
GinkgoT().Logf("waited %s subscription condition not met: %v\n", time.Since(lastTime), cond)
2844+
lastTime = time.Now()
2845+
lastCond = cond
2846+
}
2847+
return false
2848+
}
2849+
}
2850+
2851+
func subscriptionDoesNotHaveCondition(condType operatorsv1alpha1.SubscriptionConditionType) subscriptionStateChecker {
2852+
var lastStatus corev1.ConditionStatus
2853+
lastTime := time.Now()
2854+
// if status meets expectations, then subscription state is considered met/true
2855+
// IFF this is the result of a recent change of status
2856+
// else, cache the current status for next loop/comparison
2857+
return func(subscription *operatorsv1alpha1.Subscription) bool {
2858+
cond := subscription.Status.GetCondition(condType)
2859+
if cond.Status == corev1.ConditionUnknown {
2860+
if cond.Status != lastStatus {
2861+
GinkgoT().Logf("waited %s subscription condition not found\n", time.Since(lastTime))
2862+
lastStatus = cond.Status
2863+
lastTime = time.Now()
2864+
}
28322865
return true
28332866
}
28342867

2835-
fmt.Printf("subscription condition not met: %v\n", cond)
2868+
if cond.Status != lastStatus {
2869+
GinkgoT().Logf("waited %s subscription condition found: %v\n", time.Since(lastTime), cond)
2870+
lastStatus = cond.Status
2871+
lastTime = time.Now()
2872+
}
28362873
return false
28372874
}
28382875
}

0 commit comments

Comments
 (0)