Skip to content

Commit 303608d

Browse files
committed
feat(sub): Include IP failure condition message in sub status condition
Currently when an InstallPlan fails, due to bundle unpacking error is pending due to errors like invalid operatorgroup, or pending bundle unpacking job the reason is propagated to the Subscription that owns it. The message for the failure is however missing from the Subscription condition. eg ``` kind: Subscription status: conditions: - lastTransitionTime: "2021-07-07T17:55:20Z" reason: Installing status: "True" type: InstallPlanPending ``` This PR propagates the message assosiated with the reason in the InstallPlan condition when an InstallPlan is either pending, or has failed permanantly. eg ``` kind: Subscription status: conditions: - lastTransitionTime: "2021-07-07T17:55:20Z" message: no operator group found that is managing this namespace reason: Installing status: "True" type: InstallPlanPending ``` Signed-off-by: Anik Bhattacharjee <[email protected]>
1 parent 8f09c66 commit 303608d

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

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

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package subscription
22

33
import (
4+
"bytes"
45
"context"
56
"fmt"
67

@@ -452,7 +453,7 @@ func (i *installPlanReferencedState) CheckInstallPlanStatus(now *metav1.Time, cl
452453
if cond.Reason == "" {
453454
cond.Reason = string(phase)
454455
}
455-
456+
cond.Message = extractMessage(status)
456457
cond.Type = v1alpha1.SubscriptionInstallPlanPending
457458
cond.Status = corev1.ConditionTrue
458459
out.Status.SetCondition(cond)
@@ -472,6 +473,7 @@ func (i *installPlanReferencedState) CheckInstallPlanStatus(now *metav1.Time, cl
472473
}
473474

474475
cond.Type = v1alpha1.SubscriptionInstallPlanFailed
476+
cond.Message = extractMessage(status)
475477
cond.Status = corev1.ConditionTrue
476478
out.Status.SetCondition(cond)
477479

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

513+
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()
524+
}
525+
if cond := status.GetCondition(v1alpha1.InstallPlanInstalled); cond.Status != corev1.ConditionUnknown {
526+
if cond.Message != "" {
527+
str = cond.Message
528+
}
529+
}
530+
return str
531+
}
532+
511533
type installPlanKnownState struct {
512534
InstallPlanReferencedState
513535
}

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

+21-2
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,14 @@ func TestCheckInstallPlanStatus(t *testing.T) {
13361336
now: &now,
13371337
status: &v1alpha1.InstallPlanStatus{
13381338
Phase: v1alpha1.InstallPlanPhaseInstalling,
1339+
Conditions: []v1alpha1.InstallPlanCondition{
1340+
{
1341+
Type: v1alpha1.InstallPlanInstalled,
1342+
Message: "no operatorgroup found that is managing this namespace",
1343+
Reason: v1alpha1.InstallPlanConditionReason("Installing"),
1344+
Status: corev1.ConditionFalse,
1345+
},
1346+
},
13391347
},
13401348
},
13411349
want: want{
@@ -1346,7 +1354,7 @@ func TestCheckInstallPlanStatus(t *testing.T) {
13461354
},
13471355
Status: v1alpha1.SubscriptionStatus{
13481356
Conditions: []v1alpha1.SubscriptionCondition{
1349-
planPendingCondition(corev1.ConditionTrue, string(v1alpha1.InstallPlanPhaseInstalling), "", &now),
1357+
planPendingCondition(corev1.ConditionTrue, string(v1alpha1.InstallPlanPhaseInstalling), "no operatorgroup found that is managing this namespace", &now),
13501358
},
13511359
LastUpdated: now,
13521360
},
@@ -1535,6 +1543,17 @@ func TestCheckInstallPlanStatus(t *testing.T) {
15351543
Reason: v1alpha1.InstallPlanReasonComponentFailed,
15361544
},
15371545
},
1546+
BundleLookups: []v1alpha1.BundleLookup{
1547+
{
1548+
Conditions: []v1alpha1.BundleLookupCondition{
1549+
{
1550+
Type: v1alpha1.BundleLookupPending,
1551+
Status: corev1.ConditionTrue,
1552+
Message: "unpack job not completed: Unpack pod(olm/c5a4) container(pull) is pending. Reason: ImagePullBackOff, Message: Back-off pulling image",
1553+
},
1554+
},
1555+
},
1556+
},
15381557
},
15391558
},
15401559
want: want{
@@ -1545,7 +1564,7 @@ func TestCheckInstallPlanStatus(t *testing.T) {
15451564
},
15461565
Status: v1alpha1.SubscriptionStatus{
15471566
Conditions: []v1alpha1.SubscriptionCondition{
1548-
planFailedCondition(corev1.ConditionTrue, string(v1alpha1.InstallPlanReasonComponentFailed), "", &now),
1567+
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),
15491568
},
15501569
LastUpdated: now,
15511570
},

0 commit comments

Comments
 (0)