Skip to content

Commit 54da66a

Browse files
authored
Clear (existing) error cond from Subscription, once error resolved (#3166)
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](#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 #3162 Signed-off-by: Anik Bhattacharjee <[email protected]>
1 parent 1e0324c commit 54da66a

File tree

3 files changed

+62
-21
lines changed

3 files changed

+62
-21
lines changed

pkg/controller/operators/catalog/operator.go

+5-13
Original file line numberDiff line numberDiff line change
@@ -1436,16 +1436,14 @@ func (o *Operator) syncResolvingNamespace(obj interface{}) error {
14361436
}
14371437

14381438
// Make sure that we no longer indicate unpacking progress
1439-
subs = o.setSubsCond(subs, v1alpha1.SubscriptionCondition{
1440-
Type: v1alpha1.SubscriptionBundleUnpacking,
1441-
Status: corev1.ConditionFalse,
1442-
})
1439+
o.removeSubsCond(subs, v1alpha1.SubscriptionBundleUnpacking)
14431440

14441441
// Remove BundleUnpackFailed condition from subscriptions
14451442
o.removeSubsCond(subs, v1alpha1.SubscriptionBundleUnpackFailed)
14461443

14471444
// Remove resolutionfailed condition from subscriptions
14481445
o.removeSubsCond(subs, v1alpha1.SubscriptionResolutionFailed)
1446+
14491447
newSub := true
14501448
for _, updatedSub := range updatedSubs {
14511449
updatedSub.Status.RemoveConditions(v1alpha1.SubscriptionResolutionFailed)
@@ -1722,13 +1720,9 @@ func (o *Operator) setSubsCond(subs []*v1alpha1.Subscription, cond v1alpha1.Subs
17221720
return subList
17231721
}
17241722

1725-
// removeSubsCond will remove the condition to the subscription if it exists
1726-
// Only return the list of updated subscriptions
1727-
func (o *Operator) removeSubsCond(subs []*v1alpha1.Subscription, condType v1alpha1.SubscriptionConditionType) []*v1alpha1.Subscription {
1728-
var (
1729-
lastUpdated = o.now()
1730-
)
1731-
var subList []*v1alpha1.Subscription
1723+
// removeSubsCond removes the given condition from all of the subscriptions in the input
1724+
func (o *Operator) removeSubsCond(subs []*v1alpha1.Subscription, condType v1alpha1.SubscriptionConditionType) {
1725+
lastUpdated := o.now()
17321726
for _, sub := range subs {
17331727
cond := sub.Status.GetCondition(condType)
17341728
// if status is ConditionUnknown, the condition doesn't exist. Just skip
@@ -1737,9 +1731,7 @@ func (o *Operator) removeSubsCond(subs []*v1alpha1.Subscription, condType v1alph
17371731
}
17381732
sub.Status.LastUpdated = lastUpdated
17391733
sub.Status.RemoveConditions(condType)
1740-
subList = append(subList, sub)
17411734
}
1742-
return subList
17431735
}
17441736

17451737
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) {

test/e2e/subscription_e2e_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2445,7 +2445,7 @@ var _ = Describe("Subscription", func() {
24452445
},
24462446
5*time.Minute,
24472447
interval,
2448-
).Should(Equal(corev1.ConditionFalse))
2448+
).Should(Equal(corev1.ConditionUnknown))
24492449

24502450
By("verifying that the subscription is not reporting unpacking errors")
24512451
Eventually(

0 commit comments

Comments
 (0)