Skip to content

Commit d2dd0b7

Browse files
committed
fix(sub): Reset ResolutionFailed cond when error is resolved
In operator-framework#2269, a new condition was introduced for Subscription to indicate any dependency resolution error in it's message. However, when the case of the error was resolved, the condition status (true) and the message was sticking around. This PR fixes the issue, and makes sure that the condition status is set to false, and the message and reason of the condition are cleared off.
1 parent e944849 commit d2dd0b7

File tree

2 files changed

+49
-17
lines changed

2 files changed

+49
-17
lines changed

pkg/controller/operators/catalog/operator.go

+17-12
Original file line numberDiff line numberDiff line change
@@ -935,22 +935,23 @@ func (o *Operator) syncResolvingNamespace(obj interface{}) error {
935935
// not-satisfiable error
936936
if _, ok := err.(solver.NotSatisfiable); ok {
937937
logger.WithError(err).Debug("resolution failed")
938-
updateErr := o.setSubsCond(subs, v1alpha1.SubscriptionResolutionFailed, "ConstraintsNotSatisfiable", err.Error(), true)
938+
_, updateErr := o.setSubsCond(subs, v1alpha1.SubscriptionResolutionFailed, "ConstraintsNotSatisfiable", err.Error(), true)
939939
if updateErr != nil {
940940
logger.WithError(updateErr).Debug("failed to update subs conditions")
941941
}
942942
return nil
943943
}
944-
updateErr := o.setSubsCond(subs, v1alpha1.SubscriptionResolutionFailed, "ErrorPreventedResolution", err.Error(), true)
944+
_, updateErr := o.setSubsCond(subs, v1alpha1.SubscriptionResolutionFailed, "ErrorPreventedResolution", err.Error(), true)
945945
if updateErr != nil {
946946
logger.WithError(updateErr).Debug("failed to update subs conditions")
947947
}
948948
return err
949949
} else {
950-
updateErr := o.setSubsCond(subs, v1alpha1.SubscriptionResolutionFailed, "", "", false)
950+
subs, updateErr := o.setSubsCond(subs, v1alpha1.SubscriptionResolutionFailed, "", "", false)
951951
if updateErr != nil {
952952
logger.WithError(updateErr).Debug("failed to update subs conditions")
953953
}
954+
updatedSubs = subs
954955
}
955956

956957
// create installplan if anything updated
@@ -1228,7 +1229,7 @@ func (o *Operator) createInstallPlan(namespace string, gen int, subs []*v1alpha1
12281229
return reference.GetReference(res)
12291230
}
12301231

1231-
func (o *Operator) setSubsCond(subs []*v1alpha1.Subscription, condType v1alpha1.SubscriptionConditionType, reason, message string, setTrue bool) error {
1232+
func (o *Operator) setSubsCond(subs []*v1alpha1.Subscription, condType v1alpha1.SubscriptionConditionType, reason, message string, setTrue bool) ([]*v1alpha1.Subscription, error) {
12321233
var (
12331234
errs []error
12341235
mu sync.Mutex
@@ -1243,38 +1244,42 @@ func (o *Operator) setSubsCond(subs []*v1alpha1.Subscription, condType v1alpha1.
12431244
cond.Reason = reason
12441245
cond.Message = message
12451246
if setTrue {
1247+
if cond.Status == corev1.ConditionTrue {
1248+
continue
1249+
}
12461250
cond.Status = corev1.ConditionTrue
12471251
} else {
1252+
if cond.Status == corev1.ConditionFalse {
1253+
continue
1254+
}
12481255
cond.Status = corev1.ConditionFalse
12491256
}
12501257
sub.Status.SetCondition(cond)
12511258

12521259
wg.Add(1)
1253-
go func(s v1alpha1.Subscription) {
1260+
go func(sub v1alpha1.Subscription) {
12541261
defer wg.Done()
12551262

12561263
update := func() error {
1264+
mu.Lock()
1265+
defer mu.Unlock()
12571266
// Update the status of the latest revision
1258-
latest, err := o.client.OperatorsV1alpha1().Subscriptions(s.GetNamespace()).Get(context.TODO(), s.GetName(), getOpts)
1267+
latest, err := o.client.OperatorsV1alpha1().Subscriptions(sub.GetNamespace()).Get(context.TODO(), sub.GetName(), getOpts)
12591268
if err != nil {
12601269
return err
12611270
}
1262-
1263-
latest.Status = s.Status
1271+
latest.Status = sub.Status
12641272
_, err = o.client.OperatorsV1alpha1().Subscriptions(sub.Namespace).UpdateStatus(context.TODO(), latest, updateOpts)
1265-
12661273
return err
12671274
}
12681275
if err := retry.RetryOnConflict(retry.DefaultRetry, update); err != nil {
1269-
mu.Lock()
1270-
defer mu.Unlock()
12711276
errs = append(errs, err)
12721277
}
12731278
}(*sub)
12741279
}
12751280
wg.Wait()
12761281

1277-
return utilerrors.NewAggregate(errs)
1282+
return subs, utilerrors.NewAggregate(errs)
12781283
}
12791284

12801285
type UnpackedBundleReference struct {

test/e2e/subscription_e2e_test.go

+32-5
Original file line numberDiff line numberDiff line change
@@ -2113,8 +2113,11 @@ var _ = Describe("Subscription", func() {
21132113
teardown func()
21142114
cleanup func()
21152115
packages []registry.PackageManifest
2116-
subName = genName("test-subscription")
2117-
catSrcName = genName("test-catalog")
2116+
crd = newCRD(genName("foo-"))
2117+
csvA operatorsv1alpha1.ClusterServiceVersion
2118+
csvB operatorsv1alpha1.ClusterServiceVersion
2119+
subName = genName("test-subscription-")
2120+
catSrcName = genName("test-catalog-")
21182121
)
21192122

21202123
BeforeEach(func() {
@@ -2130,10 +2133,9 @@ var _ = Describe("Subscription", func() {
21302133
DefaultChannelName: "alpha",
21312134
},
21322135
}
2133-
crd := newCRD(genName("foo"))
2134-
csv := newCSV("csvA", testNamespace, "", semver.MustParse("1.0.0"), nil, []apiextensions.CustomResourceDefinition{crd}, nil)
2136+
csvA = newCSV("csvA", testNamespace, "", semver.MustParse("1.0.0"), nil, []apiextensions.CustomResourceDefinition{crd}, nil)
21352137

2136-
_, teardown = createInternalCatalogSource(c, ctx.Ctx().OperatorClient(), catSrcName, testNamespace, packages, nil, []operatorsv1alpha1.ClusterServiceVersion{csv})
2138+
_, teardown = createInternalCatalogSource(c, ctx.Ctx().OperatorClient(), catSrcName, testNamespace, packages, nil, []operatorsv1alpha1.ClusterServiceVersion{csvA})
21372139

21382140
// Ensure that the catalog source is resolved before we create a subscription.
21392141
_, err := fetchCatalogSourceOnStatus(crc, catSrcName, testNamespace, catalogSourceRegistryPodSynced)
@@ -2157,6 +2159,31 @@ var _ = Describe("Subscription", func() {
21572159
}).Should(Equal(corev1.ConditionTrue))
21582160
})
21592161

2162+
When("the required API is made available", func() {
2163+
BeforeEach(func() {
2164+
newPkg := registry.PackageManifest{
2165+
PackageName: "PackageB",
2166+
Channels: []registry.PackageChannel{
2167+
{Name: "alpha", CurrentCSVName: "csvB"},
2168+
},
2169+
DefaultChannelName: "alpha",
2170+
}
2171+
packages = append(packages, newPkg)
2172+
2173+
csvB = newCSV("csvB", testNamespace, "", semver.MustParse("1.0.0"), []apiextensions.CustomResourceDefinition{crd}, nil, nil)
2174+
2175+
updateInternalCatalog(GinkgoT(), c, crc, catSrcName, testNamespace, []apiextensions.CustomResourceDefinition{crd}, []operatorsv1alpha1.ClusterServiceVersion{csvA, csvB}, packages)
2176+
})
2177+
It("the ResolutionFailed condition previously set in it's status that indicated the resolution error is cleared off", func() {
2178+
Eventually(func() (corev1.ConditionStatus, error) {
2179+
sub, err := crc.OperatorsV1alpha1().Subscriptions(testNamespace).Get(context.Background(), subName, metav1.GetOptions{})
2180+
if err != nil {
2181+
return corev1.ConditionUnknown, err
2182+
}
2183+
return sub.Status.GetCondition(operatorsv1alpha1.SubscriptionResolutionFailed).Status, nil
2184+
}).Should(Equal(corev1.ConditionFalse))
2185+
})
2186+
})
21602187
})
21612188

21622189
When("an unannotated ClusterServiceVersion exists with an associated Subscription", func() {

0 commit comments

Comments
 (0)