Skip to content

Commit 00402eb

Browse files
Merge pull request #2268 from awgreene/big-performance-improvement
Update extractMessage
2 parents 3607f66 + 804875c commit 00402eb

File tree

2 files changed

+82
-14
lines changed

2 files changed

+82
-14
lines changed

pkg/controller/operators/catalog/subscription/state.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -511,23 +511,22 @@ func (i *installPlanReferencedState) CheckInstallPlanStatus(now *metav1.Time, cl
511511
}
512512

513513
func extractMessage(status *v1alpha1.InstallPlanStatus) string {
514-
str := ""
515-
if len(status.BundleLookups) > 0 {
516-
var b bytes.Buffer
517-
for _, lookup := range status.BundleLookups {
518-
if cond := lookup.GetCondition(v1alpha1.BundleLookupPending); cond.Status != corev1.ConditionUnknown {
519-
b.WriteString(cond.Message)
520-
b.WriteString(".")
521-
}
522-
}
523-
str = b.String()
514+
if cond := status.GetCondition(v1alpha1.InstallPlanInstalled); cond.Status != corev1.ConditionUnknown && cond.Message != "" {
515+
return cond.Message
524516
}
525-
if cond := status.GetCondition(v1alpha1.InstallPlanInstalled); cond.Status != corev1.ConditionUnknown {
526-
if cond.Message != "" {
527-
str = cond.Message
517+
518+
var b bytes.Buffer
519+
for _, lookup := range status.BundleLookups {
520+
if cond := lookup.GetCondition(v1alpha1.BundleLookupPending); cond.Status != corev1.ConditionUnknown && cond.Message != "" {
521+
if b.Len() != 0 {
522+
b.WriteString(" ")
523+
}
524+
b.WriteString(cond.Message)
525+
b.WriteString(".")
528526
}
529527
}
530-
return str
528+
529+
return b.String()
531530
}
532531

533532
type installPlanKnownState struct {

pkg/controller/operators/catalog/subscription/state_test.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,6 +1571,75 @@ func TestCheckInstallPlanStatus(t *testing.T) {
15711571
}),
15721572
},
15731573
},
1574+
{
1575+
description: "InstallPlanReferencedState/NoConditions/Failed/ToInstallPlanFailedState/Update/InstallPlanReasonComponentFailed/MultipleBundleConditions",
1576+
fields: fields{
1577+
existingObjs: existingObjs{
1578+
clientObjs: []runtime.Object{
1579+
&v1alpha1.Subscription{
1580+
ObjectMeta: metav1.ObjectMeta{
1581+
Name: "sub",
1582+
Namespace: "ns",
1583+
},
1584+
},
1585+
},
1586+
},
1587+
namespace: "ns",
1588+
state: newInstallPlanReferencedState(&v1alpha1.Subscription{
1589+
ObjectMeta: metav1.ObjectMeta{
1590+
Name: "sub",
1591+
Namespace: "ns",
1592+
},
1593+
}),
1594+
},
1595+
args: args{
1596+
now: &now,
1597+
status: &v1alpha1.InstallPlanStatus{
1598+
Phase: v1alpha1.InstallPlanPhaseFailed,
1599+
Conditions: []v1alpha1.InstallPlanCondition{
1600+
{
1601+
Type: v1alpha1.InstallPlanInstalled,
1602+
Status: corev1.ConditionFalse,
1603+
Reason: v1alpha1.InstallPlanReasonComponentFailed,
1604+
},
1605+
},
1606+
BundleLookups: []v1alpha1.BundleLookup{
1607+
{
1608+
Conditions: []v1alpha1.BundleLookupCondition{
1609+
{
1610+
Type: v1alpha1.BundleLookupPending,
1611+
Status: corev1.ConditionTrue,
1612+
Message: "encountered issue foo",
1613+
},
1614+
},
1615+
},
1616+
{
1617+
Conditions: []v1alpha1.BundleLookupCondition{
1618+
{
1619+
Type: v1alpha1.BundleLookupPending,
1620+
Status: corev1.ConditionTrue,
1621+
Message: "encountered issue bar",
1622+
},
1623+
},
1624+
},
1625+
},
1626+
},
1627+
},
1628+
want: want{
1629+
transitioned: newInstallPlanFailedState(&v1alpha1.Subscription{
1630+
ObjectMeta: metav1.ObjectMeta{
1631+
Name: "sub",
1632+
Namespace: "ns",
1633+
},
1634+
Status: v1alpha1.SubscriptionStatus{
1635+
Conditions: []v1alpha1.SubscriptionCondition{
1636+
planFailedCondition(corev1.ConditionTrue, string(v1alpha1.InstallPlanReasonComponentFailed), "encountered issue foo. encountered issue bar.", &now),
1637+
},
1638+
LastUpdated: now,
1639+
},
1640+
}),
1641+
},
1642+
},
15741643
{
15751644
description: "InstallPlanReferencedState/Conditions/Failed/ToInstallPlanFailedState/NoUpdate/InstallPlanReasonComponentFailed",
15761645
fields: fields{

0 commit comments

Comments
 (0)