Skip to content

Commit

Permalink
Update extractMessage func
Browse files Browse the repository at this point in the history
Whe building the subscription condition message,
check if the status of the InstallPlan is available
before iterating through bundle lookup conditions.
Also update string returned to include spaces between
multiple messages.

Signed-off-by: Alexander Greene <greene.al1991@gmail.com>
  • Loading branch information
awgreene committed Jul 19, 2021
1 parent b4a2199 commit 804875c
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 14 deletions.
27 changes: 13 additions & 14 deletions pkg/controller/operators/catalog/subscription/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,23 +511,22 @@ func (i *installPlanReferencedState) CheckInstallPlanStatus(now *metav1.Time, cl
}

func extractMessage(status *v1alpha1.InstallPlanStatus) string {
str := ""
if len(status.BundleLookups) > 0 {
var b bytes.Buffer
for _, lookup := range status.BundleLookups {
if cond := lookup.GetCondition(v1alpha1.BundleLookupPending); cond.Status != corev1.ConditionUnknown {
b.WriteString(cond.Message)
b.WriteString(".")
}
}
str = b.String()
if cond := status.GetCondition(v1alpha1.InstallPlanInstalled); cond.Status != corev1.ConditionUnknown && cond.Message != "" {
return cond.Message
}
if cond := status.GetCondition(v1alpha1.InstallPlanInstalled); cond.Status != corev1.ConditionUnknown {
if cond.Message != "" {
str = cond.Message

var b bytes.Buffer
for _, lookup := range status.BundleLookups {
if cond := lookup.GetCondition(v1alpha1.BundleLookupPending); cond.Status != corev1.ConditionUnknown && cond.Message != "" {
if b.Len() != 0 {
b.WriteString(" ")
}
b.WriteString(cond.Message)
b.WriteString(".")
}
}
return str

return b.String()
}

type installPlanKnownState struct {
Expand Down
69 changes: 69 additions & 0 deletions pkg/controller/operators/catalog/subscription/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1571,6 +1571,75 @@ func TestCheckInstallPlanStatus(t *testing.T) {
}),
},
},
{
description: "InstallPlanReferencedState/NoConditions/Failed/ToInstallPlanFailedState/Update/InstallPlanReasonComponentFailed/MultipleBundleConditions",
fields: fields{
existingObjs: existingObjs{
clientObjs: []runtime.Object{
&v1alpha1.Subscription{
ObjectMeta: metav1.ObjectMeta{
Name: "sub",
Namespace: "ns",
},
},
},
},
namespace: "ns",
state: newInstallPlanReferencedState(&v1alpha1.Subscription{
ObjectMeta: metav1.ObjectMeta{
Name: "sub",
Namespace: "ns",
},
}),
},
args: args{
now: &now,
status: &v1alpha1.InstallPlanStatus{
Phase: v1alpha1.InstallPlanPhaseFailed,
Conditions: []v1alpha1.InstallPlanCondition{
{
Type: v1alpha1.InstallPlanInstalled,
Status: corev1.ConditionFalse,
Reason: v1alpha1.InstallPlanReasonComponentFailed,
},
},
BundleLookups: []v1alpha1.BundleLookup{
{
Conditions: []v1alpha1.BundleLookupCondition{
{
Type: v1alpha1.BundleLookupPending,
Status: corev1.ConditionTrue,
Message: "encountered issue foo",
},
},
},
{
Conditions: []v1alpha1.BundleLookupCondition{
{
Type: v1alpha1.BundleLookupPending,
Status: corev1.ConditionTrue,
Message: "encountered issue bar",
},
},
},
},
},
},
want: want{
transitioned: newInstallPlanFailedState(&v1alpha1.Subscription{
ObjectMeta: metav1.ObjectMeta{
Name: "sub",
Namespace: "ns",
},
Status: v1alpha1.SubscriptionStatus{
Conditions: []v1alpha1.SubscriptionCondition{
planFailedCondition(corev1.ConditionTrue, string(v1alpha1.InstallPlanReasonComponentFailed), "encountered issue foo. encountered issue bar.", &now),
},
LastUpdated: now,
},
}),
},
},
{
description: "InstallPlanReferencedState/Conditions/Failed/ToInstallPlanFailedState/NoUpdate/InstallPlanReasonComponentFailed",
fields: fields{
Expand Down

0 comments on commit 804875c

Please sign in to comment.