Skip to content

Commit 3223fce

Browse files
Merge pull request #2269 from anik120/sub-resolution-error
feat(sub): Indicate resolution conflicts on Subscription statuses
2 parents c3a59fd + 4a2c5c0 commit 3223fce

File tree

6 files changed

+123
-4
lines changed

6 files changed

+123
-4
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ require (
2424
github.com/onsi/gomega v1.13.0
2525
github.com/openshift/api v0.0.0-20200331152225-585af27e34fd
2626
github.com/openshift/client-go v0.0.0-20200326155132-2a6cd50aedd0
27-
github.com/operator-framework/api v0.10.1
27+
github.com/operator-framework/api v0.10.2
2828
github.com/operator-framework/operator-registry v1.17.5
2929
github.com/otiai10/copy v1.2.0
3030
github.com/pkg/errors v0.9.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -876,8 +876,8 @@ github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJ
876876
github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
877877
github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
878878
github.com/operator-framework/api v0.7.1/go.mod h1:L7IvLd/ckxJEJg/t4oTTlnHKAJIP/p51AvEslW3wYdY=
879-
github.com/operator-framework/api v0.10.1 h1:2tBjIr4hRZ0iaJ4UuenVjocbo9xrJi1O409K/tlEddo=
880-
github.com/operator-framework/api v0.10.1/go.mod h1:tV0BUNvly7szq28ZPBXhjp1Sqg5yHCOeX19ui9K4vjI=
879+
github.com/operator-framework/api v0.10.2 h1:fo8Bhyx1v46NdJIz2rUzfzNUpe1KDNPtVpHVpuxZnk0=
880+
github.com/operator-framework/api v0.10.2/go.mod h1:tV0BUNvly7szq28ZPBXhjp1Sqg5yHCOeX19ui9K4vjI=
881881
github.com/operator-framework/operator-registry v1.17.5 h1:LR8m1rFz5Gcyje8WK6iYt+gIhtzqo52zMRALdmTYHT0=
882882
github.com/operator-framework/operator-registry v1.17.5/go.mod h1:sRQIgDMZZdUcmHltzyCnM6RUoDF+WS8Arj1BQIARDS8=
883883
github.com/otiai10/copy v1.2.0 h1:HvG945u96iNadPoG2/Ja2+AUJeW5YuFQMixq9yirC+k=

pkg/controller/operators/catalog/operator.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,9 +935,22 @@ 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)
939+
if updateErr != nil {
940+
logger.WithError(updateErr).Debug("failed to update subs conditions")
941+
}
938942
return nil
939943
}
944+
updateErr := o.setSubsCond(subs, v1alpha1.SubscriptionResolutionFailed, "ErrorPreventedResolution", err.Error(), true)
945+
if updateErr != nil {
946+
logger.WithError(updateErr).Debug("failed to update subs conditions")
947+
}
940948
return err
949+
} else {
950+
updateErr := o.setSubsCond(subs, v1alpha1.SubscriptionResolutionFailed, "", "", false)
951+
if updateErr != nil {
952+
logger.WithError(updateErr).Debug("failed to update subs conditions")
953+
}
941954
}
942955

943956
// create installplan if anything updated
@@ -1215,6 +1228,55 @@ func (o *Operator) createInstallPlan(namespace string, gen int, subs []*v1alpha1
12151228
return reference.GetReference(res)
12161229
}
12171230

1231+
func (o *Operator) setSubsCond(subs []*v1alpha1.Subscription, condType v1alpha1.SubscriptionConditionType, reason, message string, setTrue bool) error {
1232+
var (
1233+
errs []error
1234+
mu sync.Mutex
1235+
wg sync.WaitGroup
1236+
getOpts = metav1.GetOptions{}
1237+
updateOpts = metav1.UpdateOptions{}
1238+
lastUpdated = o.now()
1239+
)
1240+
for _, sub := range subs {
1241+
sub.Status.LastUpdated = lastUpdated
1242+
cond := sub.Status.GetCondition(condType)
1243+
cond.Reason = reason
1244+
cond.Message = message
1245+
if setTrue {
1246+
cond.Status = corev1.ConditionTrue
1247+
} else {
1248+
cond.Status = corev1.ConditionFalse
1249+
}
1250+
sub.Status.SetCondition(cond)
1251+
1252+
wg.Add(1)
1253+
go func(s v1alpha1.Subscription) {
1254+
defer wg.Done()
1255+
1256+
update := func() error {
1257+
// Update the status of the latest revision
1258+
latest, err := o.client.OperatorsV1alpha1().Subscriptions(s.GetNamespace()).Get(context.TODO(), s.GetName(), getOpts)
1259+
if err != nil {
1260+
return err
1261+
}
1262+
1263+
latest.Status = s.Status
1264+
_, err = o.client.OperatorsV1alpha1().Subscriptions(sub.Namespace).UpdateStatus(context.TODO(), latest, updateOpts)
1265+
1266+
return err
1267+
}
1268+
if err := retry.RetryOnConflict(retry.DefaultRetry, update); err != nil {
1269+
mu.Lock()
1270+
defer mu.Unlock()
1271+
errs = append(errs, err)
1272+
}
1273+
}(*sub)
1274+
}
1275+
wg.Wait()
1276+
1277+
return utilerrors.NewAggregate(errs)
1278+
}
1279+
12181280
type UnpackedBundleReference struct {
12191281
Kind string `json:"kind"`
12201282
Name string `json:"name"`

test/e2e/subscription_e2e_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,6 +2105,60 @@ var _ = Describe("Subscription", func() {
21052105
require.NoError(GinkgoT(), err)
21062106
})
21072107

2108+
When("A subscription is created for an operator that requires an API that is not available", func() {
2109+
2110+
var (
2111+
c operatorclient.ClientInterface
2112+
crc versioned.Interface
2113+
teardown func()
2114+
cleanup func()
2115+
packages []registry.PackageManifest
2116+
subName = genName("test-subscription")
2117+
catSrcName = genName("test-catalog")
2118+
)
2119+
2120+
BeforeEach(func() {
2121+
c = newKubeClient()
2122+
crc = newCRClient()
2123+
2124+
packages = []registry.PackageManifest{
2125+
{
2126+
PackageName: "packageA",
2127+
Channels: []registry.PackageChannel{
2128+
{Name: "alpha", CurrentCSVName: "csvA"},
2129+
},
2130+
DefaultChannelName: "alpha",
2131+
},
2132+
}
2133+
crd := newCRD(genName("foo"))
2134+
csv := newCSV("csvA", testNamespace, "", semver.MustParse("1.0.0"), nil, []apiextensions.CustomResourceDefinition{crd}, nil)
2135+
2136+
_, teardown = createInternalCatalogSource(c, ctx.Ctx().OperatorClient(), catSrcName, testNamespace, packages, nil, []operatorsv1alpha1.ClusterServiceVersion{csv})
2137+
2138+
// Ensure that the catalog source is resolved before we create a subscription.
2139+
_, err := fetchCatalogSourceOnStatus(crc, catSrcName, testNamespace, catalogSourceRegistryPodSynced)
2140+
require.NoError(GinkgoT(), err)
2141+
2142+
cleanup = createSubscriptionForCatalog(crc, testNamespace, subName, catSrcName, "packageA", "alpha", "", operatorsv1alpha1.ApprovalAutomatic)
2143+
})
2144+
2145+
AfterEach(func() {
2146+
cleanup()
2147+
teardown()
2148+
})
2149+
2150+
It("the subscription has a condition in it's status that indicates the resolution error", func() {
2151+
Eventually(func() (corev1.ConditionStatus, error) {
2152+
sub, err := crc.OperatorsV1alpha1().Subscriptions(testNamespace).Get(context.Background(), subName, metav1.GetOptions{})
2153+
if err != nil {
2154+
return corev1.ConditionUnknown, err
2155+
}
2156+
return sub.Status.GetCondition(operatorsv1alpha1.SubscriptionResolutionFailed).Status, nil
2157+
}).Should(Equal(corev1.ConditionTrue))
2158+
})
2159+
2160+
})
2161+
21082162
When("an unannotated ClusterServiceVersion exists with an associated Subscription", func() {
21092163
var (
21102164
teardown func()

vendor/github.com/operator-framework/api/pkg/operators/v1alpha1/subscription_types.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ github.com/openshift/client-go/config/informers/externalversions/config
489489
github.com/openshift/client-go/config/informers/externalversions/config/v1
490490
github.com/openshift/client-go/config/informers/externalversions/internalinterfaces
491491
github.com/openshift/client-go/config/listers/config/v1
492-
# github.com/operator-framework/api v0.10.1
492+
# github.com/operator-framework/api v0.10.2
493493
## explicit
494494
github.com/operator-framework/api/crds
495495
github.com/operator-framework/api/pkg/lib/version

0 commit comments

Comments
 (0)