Skip to content

Commit 3227583

Browse files
committed
Clear (existing) error cond from Subscription, once error resolved
The func `removeSubsCond` takes in a list of pointers to Subscription objects, modifies the objects that the pointers point to, but return a new list of those pointers. A [PR](operator-framework#2942) included in the v0.25.0 release [changed the way the output of that function was being used](https://github.com/operator-framework/operator-lifecycle-manager/pull/2942/files#diff-a1760d9b7ac1e93734eea675d8d8938c96a50e995434b163c6f77c91bace9990R1146-R1155) leading to a regression. This PR fixes the `removeSubsCond` function, fixing the regression as a result. Closes operator-framework#3162 Signed-off-by: Anik Bhattacharjee <[email protected]>
1 parent 1bb6009 commit 3227583

File tree

2 files changed

+60
-18
lines changed

2 files changed

+60
-18
lines changed

pkg/controller/operators/catalog/operator.go

+4-11
Original file line numberDiff line numberDiff line change
@@ -1393,16 +1393,14 @@ func (o *Operator) syncResolvingNamespace(obj interface{}) error {
13931393
}
13941394

13951395
// Make sure that we no longer indicate unpacking progress
1396-
subs = o.setSubsCond(subs, v1alpha1.SubscriptionCondition{
1397-
Type: v1alpha1.SubscriptionBundleUnpacking,
1398-
Status: corev1.ConditionFalse,
1399-
})
1396+
o.removeSubsCond(subs, v1alpha1.SubscriptionBundleUnpacking)
14001397

14011398
// Remove BundleUnpackFailed condition from subscriptions
14021399
o.removeSubsCond(subs, v1alpha1.SubscriptionBundleUnpackFailed)
14031400

14041401
// Remove resolutionfailed condition from subscriptions
14051402
o.removeSubsCond(subs, v1alpha1.SubscriptionResolutionFailed)
1403+
14061404
newSub := true
14071405
for _, updatedSub := range updatedSubs {
14081406
updatedSub.Status.RemoveConditions(v1alpha1.SubscriptionResolutionFailed)
@@ -1681,11 +1679,8 @@ func (o *Operator) setSubsCond(subs []*v1alpha1.Subscription, cond v1alpha1.Subs
16811679

16821680
// removeSubsCond will remove the condition to the subscription if it exists
16831681
// Only return the list of updated subscriptions
1684-
func (o *Operator) removeSubsCond(subs []*v1alpha1.Subscription, condType v1alpha1.SubscriptionConditionType) []*v1alpha1.Subscription {
1685-
var (
1686-
lastUpdated = o.now()
1687-
)
1688-
var subList []*v1alpha1.Subscription
1682+
func (o *Operator) removeSubsCond(subs []*v1alpha1.Subscription, condType v1alpha1.SubscriptionConditionType) {
1683+
lastUpdated := o.now()
16891684
for _, sub := range subs {
16901685
cond := sub.Status.GetCondition(condType)
16911686
// if status is ConditionUnknown, the condition doesn't exist. Just skip
@@ -1694,9 +1689,7 @@ func (o *Operator) removeSubsCond(subs []*v1alpha1.Subscription, condType v1alph
16941689
}
16951690
sub.Status.LastUpdated = lastUpdated
16961691
sub.Status.RemoveConditions(condType)
1697-
subList = append(subList, sub)
16981692
}
1699-
return subList
17001693
}
17011694

17021695
func (o *Operator) updateSubscriptionStatuses(subs []*v1alpha1.Subscription) ([]*v1alpha1.Subscription, error) {

pkg/controller/operators/catalog/operator_test.go

+56-7
Original file line numberDiff line numberDiff line change
@@ -1261,13 +1261,6 @@ func TestSyncResolvingNamespace(t *testing.T) {
12611261
Status: v1alpha1.SubscriptionStatus{
12621262
CurrentCSV: "",
12631263
State: "",
1264-
Conditions: []v1alpha1.SubscriptionCondition{
1265-
{
1266-
Type: v1alpha1.SubscriptionBundleUnpacking,
1267-
Status: corev1.ConditionFalse,
1268-
},
1269-
},
1270-
LastUpdated: now,
12711264
},
12721265
},
12731266
},
@@ -1399,6 +1392,62 @@ func TestSyncResolvingNamespace(t *testing.T) {
13991392
},
14001393
wantErr: fmt.Errorf("some error"),
14011394
},
1395+
{
1396+
name: "HadErrorShouldClearError",
1397+
fields: fields{
1398+
clientOptions: []clientfake.Option{clientfake.WithSelfLinks(t)},
1399+
existingOLMObjs: []runtime.Object{
1400+
&v1alpha1.Subscription{
1401+
TypeMeta: metav1.TypeMeta{
1402+
Kind: v1alpha1.SubscriptionKind,
1403+
APIVersion: v1alpha1.SchemeGroupVersion.String(),
1404+
},
1405+
ObjectMeta: metav1.ObjectMeta{
1406+
Name: "sub",
1407+
Namespace: testNamespace,
1408+
},
1409+
Spec: &v1alpha1.SubscriptionSpec{
1410+
CatalogSource: "src",
1411+
CatalogSourceNamespace: testNamespace,
1412+
},
1413+
Status: v1alpha1.SubscriptionStatus{
1414+
InstalledCSV: "sub-csv",
1415+
State: "AtLatestKnown",
1416+
Conditions: []v1alpha1.SubscriptionCondition{
1417+
{
1418+
Type: v1alpha1.SubscriptionResolutionFailed,
1419+
Reason: "ConstraintsNotSatisfiable",
1420+
Message: "constraints not satisfiable: no operators found from catalog src in namespace testNamespace referenced by subscrition sub, subscription sub exists",
1421+
Status: corev1.ConditionTrue,
1422+
},
1423+
},
1424+
},
1425+
},
1426+
},
1427+
resolveErr: nil,
1428+
},
1429+
wantSubscriptions: []*v1alpha1.Subscription{
1430+
{
1431+
TypeMeta: metav1.TypeMeta{
1432+
Kind: v1alpha1.SubscriptionKind,
1433+
APIVersion: v1alpha1.SchemeGroupVersion.String(),
1434+
},
1435+
ObjectMeta: metav1.ObjectMeta{
1436+
Name: "sub",
1437+
Namespace: testNamespace,
1438+
},
1439+
Spec: &v1alpha1.SubscriptionSpec{
1440+
CatalogSource: "src",
1441+
CatalogSourceNamespace: testNamespace,
1442+
},
1443+
Status: v1alpha1.SubscriptionStatus{
1444+
InstalledCSV: "sub-csv",
1445+
State: "AtLatestKnown",
1446+
LastUpdated: now,
1447+
},
1448+
},
1449+
},
1450+
},
14021451
}
14031452
for _, tt := range tests {
14041453
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)