Skip to content

Commit

Permalink
Merge pull request #2262 from anik120/subscription-message-backup
Browse files Browse the repository at this point in the history
feat(sub): Include IP failure condition message in sub status condition
  • Loading branch information
openshift-merge-robot committed Jul 19, 2021
2 parents d76b75b + 303608d commit b4a2199
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
24 changes: 23 additions & 1 deletion pkg/controller/operators/catalog/subscription/state.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package subscription

import (
"bytes"
"context"
"fmt"

Expand Down Expand Up @@ -452,7 +453,7 @@ func (i *installPlanReferencedState) CheckInstallPlanStatus(now *metav1.Time, cl
if cond.Reason == "" {
cond.Reason = string(phase)
}

cond.Message = extractMessage(status)
cond.Type = v1alpha1.SubscriptionInstallPlanPending
cond.Status = corev1.ConditionTrue
out.Status.SetCondition(cond)
Expand All @@ -472,6 +473,7 @@ func (i *installPlanReferencedState) CheckInstallPlanStatus(now *metav1.Time, cl
}

cond.Type = v1alpha1.SubscriptionInstallPlanFailed
cond.Message = extractMessage(status)
cond.Status = corev1.ConditionTrue
out.Status.SetCondition(cond)

Expand Down Expand Up @@ -508,6 +510,26 @@ func (i *installPlanReferencedState) CheckInstallPlanStatus(now *metav1.Time, cl
return known, nil
}

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 {
if cond.Message != "" {
str = cond.Message
}
}
return str
}

type installPlanKnownState struct {
InstallPlanReferencedState
}
Expand Down
23 changes: 21 additions & 2 deletions pkg/controller/operators/catalog/subscription/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,14 @@ func TestCheckInstallPlanStatus(t *testing.T) {
now: &now,
status: &v1alpha1.InstallPlanStatus{
Phase: v1alpha1.InstallPlanPhaseInstalling,
Conditions: []v1alpha1.InstallPlanCondition{
{
Type: v1alpha1.InstallPlanInstalled,
Message: "no operatorgroup found that is managing this namespace",
Reason: v1alpha1.InstallPlanConditionReason("Installing"),
Status: corev1.ConditionFalse,
},
},
},
},
want: want{
Expand All @@ -1346,7 +1354,7 @@ func TestCheckInstallPlanStatus(t *testing.T) {
},
Status: v1alpha1.SubscriptionStatus{
Conditions: []v1alpha1.SubscriptionCondition{
planPendingCondition(corev1.ConditionTrue, string(v1alpha1.InstallPlanPhaseInstalling), "", &now),
planPendingCondition(corev1.ConditionTrue, string(v1alpha1.InstallPlanPhaseInstalling), "no operatorgroup found that is managing this namespace", &now),
},
LastUpdated: now,
},
Expand Down Expand Up @@ -1535,6 +1543,17 @@ func TestCheckInstallPlanStatus(t *testing.T) {
Reason: v1alpha1.InstallPlanReasonComponentFailed,
},
},
BundleLookups: []v1alpha1.BundleLookup{
{
Conditions: []v1alpha1.BundleLookupCondition{
{
Type: v1alpha1.BundleLookupPending,
Status: corev1.ConditionTrue,
Message: "unpack job not completed: Unpack pod(olm/c5a4) container(pull) is pending. Reason: ImagePullBackOff, Message: Back-off pulling image",
},
},
},
},
},
},
want: want{
Expand All @@ -1545,7 +1564,7 @@ func TestCheckInstallPlanStatus(t *testing.T) {
},
Status: v1alpha1.SubscriptionStatus{
Conditions: []v1alpha1.SubscriptionCondition{
planFailedCondition(corev1.ConditionTrue, string(v1alpha1.InstallPlanReasonComponentFailed), "", &now),
planFailedCondition(corev1.ConditionTrue, string(v1alpha1.InstallPlanReasonComponentFailed), "unpack job not completed: Unpack pod(olm/c5a4) container(pull) is pending. Reason: ImagePullBackOff, Message: Back-off pulling image.", &now),
},
LastUpdated: now,
},
Expand Down

0 comments on commit b4a2199

Please sign in to comment.