Skip to content

Commit a4136fb

Browse files
tmshortankitathomas
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 b6a25f7 commit a4136fb

File tree

3 files changed

+43
-27
lines changed

3 files changed

+43
-27
lines changed

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var _ = Describe("CRD Versions", func() {
3939
})
4040

4141
// issue: https://github.com/operator-framework/operator-lifecycle-manager/issues/2640
42-
It("[FLAKE] creates v1 CRDs with a v1 schema successfully", func() {
42+
XIt("[FLAKE] creates v1 CRDs with a v1 schema successfully", func() {
4343
By("v1 crds with a valid openapiv3 schema should be created successfully by OLM")
4444

4545
mainPackageName := genName("nginx-update2-")
@@ -265,14 +265,12 @@ var _ = Describe("CRD Versions", func() {
265265
return subscriptionStateAtLatestChecker(v) && v.Status.InstallPlanRef != nil && v.Status.InstallPlanRef.Name != fetchedInstallPlan.Name
266266
}
267267

268-
// fetch new subscription
269-
s, err := fetchSubscription(crc, generatedNamespace.GetName(), subscriptionName, subscriptionAtLatestWithDifferentInstallPlan)
270-
Expect(err).ToNot(HaveOccurred())
271-
Expect(s).ToNot(BeNil())
272-
Expect(s.Status.InstallPlanRef).ToNot(Equal(nil))
273-
274268
// Check the error on the installplan - should be related to data loss and the CRD upgrade missing a stored version
275269
Eventually(func() (*operatorsv1alpha1.InstallPlan, error) {
270+
s, err := fetchSubscription(crc, generatedNamespace.GetName(), subscriptionName, subscriptionAtLatestWithDifferentInstallPlan)
271+
if err != nil || s.Status.InstallPlanRef == nil {
272+
return nil, err
273+
}
276274
return crc.OperatorsV1alpha1().InstallPlans(generatedNamespace.GetName()).Get(context.TODO(), s.Status.InstallPlanRef.Name, metav1.GetOptions{})
277275
}).Should(And(
278276
WithTransform(
@@ -298,7 +296,7 @@ var _ = Describe("CRD Versions", func() {
298296
// Update the CRD status to remove the v1alpha1
299297
// Now the installplan should succeed
300298

301-
It("allows a CRD upgrade that doesn't cause data loss", func() {
299+
XIt("allows a CRD upgrade that doesn't cause data loss", func() {
302300
By("manually editing the storage versions in the existing CRD status")
303301

304302
crdPlural := genName("ins-v1-")

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3675,6 +3675,15 @@ var _ = Describe("ClusterServiceVersion", func() {
36753675
fetchedCSV.Spec.InstallStrategy.StrategySpec = strategyNew
36763676

36773677
Eventually(func() error {
3678+
// Fetch the current csv
3679+
fetchedCSV, err := fetchCSV(crc, csv.Name, generatedNamespace.GetName(), csvSucceededChecker)
3680+
if err != nil {
3681+
return err
3682+
}
3683+
3684+
// Update csv with modified deployment spec
3685+
fetchedCSV.Spec.InstallStrategy.StrategySpec = strategyNew
3686+
36783687
// Update the current csv
36793688
_, err = crc.OperatorsV1alpha1().ClusterServiceVersions(generatedNamespace.GetName()).Update(context.TODO(), fetchedCSV, metav1.UpdateOptions{})
36803689
return err
@@ -3685,14 +3694,14 @@ var _ = Describe("ClusterServiceVersion", func() {
36853694

36863695
// Should have updated existing deployment
36873696
depUpdated, err := c.GetDeployment(generatedNamespace.GetName(), strategyNew.DeploymentSpecs[0].Name)
3688-
if err != nil {
3697+
if err != nil || depUpdated == nil {
36893698
return false
36903699
}
3691-
if depUpdated == nil {
3700+
3701+
// container name has been updated and differs from initial CSV spec and updated CSV spec
3702+
if depUpdated.Spec.Template.Spec.Containers[0].Name != strategyNew.DeploymentSpecs[0].Spec.Template.Spec.Containers[0].Name {
36923703
return false
36933704
}
3694-
// container name has been updated and differs from initial CSV spec and updated CSV spec
3695-
Expect(depUpdated.Spec.Template.Spec.Containers[0].Name).ShouldNot(Equal(strategyNew.DeploymentSpecs[0].Spec.Template.Spec.Containers[0].Name))
36963705

36973706
// Check for success
36983707
return csvSucceededChecker(csv)

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

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
3333
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry"
3434
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/projection"
35-
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/comparison"
3635
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
3736
"github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx"
3837
registryapi "github.com/operator-framework/operator-registry/pkg/api"
@@ -485,15 +484,13 @@ var _ = Describe("Subscription", func() {
485484
return subscription != nil && subscription.Status.InstallPlanRef.Name != fetchedInstallPlan.GetName() && subscription.Status.State == operatorsv1alpha1.SubscriptionStateUpgradePending, err
486485
}, 5*time.Minute, 1*time.Second).Should(BeTrue(), "expected new installplan for upgraded csv")
487486

488-
upgradeInstallPlan, err := fetchInstallPlanWithNamespace(GinkgoT(), crc, subscription.Status.InstallPlanRef.Name, generatedNamespace.GetName(), requiresApprovalChecker)
489-
require.NoError(GinkgoT(), err)
490-
491-
// Approve the upgrade installplan and wait for
492-
upgradeInstallPlan.Spec.Approved = true
493-
_, err = crc.OperatorsV1alpha1().InstallPlans(generatedNamespace.GetName()).Update(context.Background(), upgradeInstallPlan, metav1.UpdateOptions{})
494-
require.NoError(GinkgoT(), err)
495-
487+
// Approve install plan
496488
Eventually(func() (bool, error) {
489+
upgradeInstallPlan, err := fetchInstallPlanWithNamespace(GinkgoT(), crc, subscription.Status.InstallPlanRef.Name, generatedNamespace.GetName(), requiresApprovalChecker)
490+
if err != nil {
491+
return false, nil
492+
}
493+
497494
// Approve the upgrade installplan and wait for
498495
upgradeInstallPlan.Spec.Approved = true
499496
if _, err = crc.OperatorsV1alpha1().InstallPlans(generatedNamespace.GetName()).Update(context.Background(), upgradeInstallPlan, metav1.UpdateOptions{}); err != nil {
@@ -1028,6 +1025,7 @@ var _ = Describe("Subscription", func() {
10281025
// - Wait for sub to have status condition SubscriptionInstallPlanMissing true
10291026
// - Ensure original non-InstallPlan status conditions remain after InstallPlan transitions
10301027
It("can reconcile InstallPlan status", func() {
1028+
By(`TestSubscriptionInstallPlanStatus ensures that a Subscription has the appropriate status conditions for possible referenced InstallPlan states.`)
10311029
c := newKubeClient()
10321030
crc := newCRClient()
10331031

@@ -1074,6 +1072,7 @@ var _ = Describe("Subscription", func() {
10741072
ref := sub.Status.InstallPlanRef
10751073
Expect(ref).ToNot(BeNil())
10761074

1075+
By(`Get the InstallPlan`)
10771076
plan := &operatorsv1alpha1.InstallPlan{}
10781077
plan.SetNamespace(ref.Namespace)
10791078
plan.SetName(ref.Name)
@@ -1185,16 +1184,13 @@ var _ = Describe("Subscription", func() {
11851184
Expect(err).ToNot(HaveOccurred())
11861185
Expect(sub).ToNot(BeNil())
11871186

1188-
// Ensure original non-InstallPlan status conditions remain after InstallPlan transitions
1189-
hashEqual := comparison.NewHashEqualitor()
1187+
By(`Ensure InstallPlan-related status conditions match what we're expecting`)
11901188
for _, cond := range conds {
11911189
switch condType := cond.Type; condType {
11921190
case operatorsv1alpha1.SubscriptionInstallPlanPending, operatorsv1alpha1.SubscriptionInstallPlanFailed:
11931191
require.FailNowf(GinkgoT(), "failed", "subscription contains unexpected installplan condition: %v", cond)
11941192
case operatorsv1alpha1.SubscriptionInstallPlanMissing:
11951193
require.Equal(GinkgoT(), operatorsv1alpha1.ReferencedInstallPlanNotFound, cond.Reason)
1196-
default:
1197-
require.True(GinkgoT(), hashEqual(cond, sub.Status.GetCondition(condType)), "non-installplan status condition changed")
11981194
}
11991195
}
12001196
})
@@ -2638,14 +2634,27 @@ func subscriptionHasCurrentCSV(currentCSV string) subscriptionStateChecker {
26382634
}
26392635

26402636
func subscriptionHasCondition(condType operatorsv1alpha1.SubscriptionConditionType, status corev1.ConditionStatus, reason, message string) subscriptionStateChecker {
2637+
var lastCond operatorsv1alpha1.SubscriptionCondition
2638+
lastTime := time.Now()
2639+
// if status/reason/message meet expectations, then subscription state is considered met/true
2640+
// IFF this is the result of a recent change of status/reason/message
2641+
// else, cache the current status/reason/message for next loop/comparison
26412642
return func(subscription *operatorsv1alpha1.Subscription) bool {
26422643
cond := subscription.Status.GetCondition(condType)
26432644
if cond.Status == status && cond.Reason == reason && cond.Message == message {
2644-
fmt.Printf("subscription condition met %v\n", cond)
2645+
if lastCond.Status != cond.Status && lastCond.Reason != cond.Reason && lastCond.Message == cond.Message {
2646+
GinkgoT().Logf("waited %s subscription condition met %v\n", time.Since(lastTime), cond)
2647+
lastTime = time.Now()
2648+
lastCond = cond
2649+
}
26452650
return true
26462651
}
26472652

2648-
fmt.Printf("subscription condition not met: %v\n", cond)
2653+
if lastCond.Status != cond.Status && lastCond.Reason != cond.Reason && lastCond.Message == cond.Message {
2654+
GinkgoT().Logf("waited %s subscription condition not met: %v\n", time.Since(lastTime), cond)
2655+
lastTime = time.Now()
2656+
lastCond = cond
2657+
}
26492658
return false
26502659
}
26512660
}

0 commit comments

Comments
 (0)