Skip to content

Commit 07d14dd

Browse files
committed
Add Catalog Source priority for dependency resolution
Signed-off-by: Harish <[email protected]>
1 parent 7b35209 commit 07d14dd

30 files changed

+692
-81
lines changed

deploy/chart/crds/0000_50_olm_00-catalogsources.crd.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,17 @@ spec:
9090
a registry-server with. Only used when SourceType = SourceTypeGrpc.
9191
If present, the address field is ignored.
9292
type: string
93+
priority:
94+
description: 'Priority field assigns a weight to the catalog source
95+
to prioritize them so that it can be consumed by the dependency
96+
resolver. Usage: Higher weight indicates that this catalog source
97+
is preferred over lower weighted catalog sources during dependency
98+
resolution. The range of the priority value can go from positive
99+
to negative in the range of int32. The default value to a catalog
100+
source with unassigned priority would be 0. The catalog source with
101+
the same priority values will be ranked lexicographically based
102+
on its name.'
103+
type: integer
93104
publisher:
94105
type: string
95106
secrets:

deploy/chart/crds/0000_50_olm_00-clusterserviceversions.crd.yaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,13 +662,19 @@ spec:
662662
deployments:
663663
type: array
664664
items:
665-
description: StrategyDeploymentSpec contains the name and
666-
spec for the deployment ALM should create
665+
description: StrategyDeploymentSpec contains the name, spec
666+
and labels for the deployment ALM should create
667667
type: object
668668
required:
669669
- name
670670
- spec
671671
properties:
672+
label:
673+
description: Set is a map of label:value. It implements
674+
Labels.
675+
type: object
676+
additionalProperties:
677+
type: string
672678
name:
673679
type: string
674680
spec:
@@ -8698,6 +8704,10 @@ spec:
86988704
containerPort:
86998705
type: integer
87008706
format: int32
8707+
conversionCRDs:
8708+
type: array
8709+
items:
8710+
type: string
87018711
deploymentName:
87028712
type: string
87038713
failurePolicy:

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ require (
2222
github.com/onsi/gomega v1.9.0
2323
github.com/openshift/api v0.0.0-20200331152225-585af27e34fd
2424
github.com/openshift/client-go v0.0.0-20200326155132-2a6cd50aedd0
25-
github.com/operator-framework/api v0.3.7
25+
github.com/operator-framework/api v0.3.9
2626
github.com/operator-framework/operator-registry v1.13.3
2727
github.com/otiai10/copy v1.2.0
2828
github.com/pkg/errors v0.9.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,8 @@ github.com/openshift/client-go v0.0.0-20200326155132-2a6cd50aedd0 h1:kMiuiZXH1Gd
585585
github.com/openshift/client-go v0.0.0-20200326155132-2a6cd50aedd0/go.mod h1:uUQ4LClRO+fg5MF/P6QxjMCb1C9f7Oh4RKepftDnEJE=
586586
github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw=
587587
github.com/operator-framework/api v0.3.7-0.20200602203552-431198de9fc2/go.mod h1:Xbje9x0SHmh0nihE21kpesB38vk3cyxnE6JdDS8Jo1Q=
588-
github.com/operator-framework/api v0.3.7 h1:gTER+WQdjRAegxKdcoylNqHVGGnBRAAgC2zS3CZL78g=
589-
github.com/operator-framework/api v0.3.7/go.mod h1:Xbje9x0SHmh0nihE21kpesB38vk3cyxnE6JdDS8Jo1Q=
588+
github.com/operator-framework/api v0.3.9 h1:ggRW5C/7MLmA4cOJ2mjEZ5RqDMsIeMknd6vx15S7Xo4=
589+
github.com/operator-framework/api v0.3.9/go.mod h1:Xbje9x0SHmh0nihE21kpesB38vk3cyxnE6JdDS8Jo1Q=
590590
github.com/operator-framework/operator-registry v1.13.3 h1:SaZ1IKLKGizVgTtT8AlDgaMXFYOiIPxRf8KLve0/DXM=
591591
github.com/operator-framework/operator-registry v1.13.3/go.mod h1:YhnIzOVjRU2ZwZtzt+fjcjW8ujJaSFynBEu7QVKaSdU=
592592
github.com/otiai10/copy v1.2.0 h1:HvG945u96iNadPoG2/Ja2+AUJeW5YuFQMixq9yirC+k=

pkg/controller/operators/catalog/operator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ func (o *Operator) syncResolvingNamespace(obj interface{}) error {
865865
// resolve a set of steps to apply to a cluster, a set of subscriptions to create/update, and any errors
866866
steps, bundleLookups, updatedSubs, err := o.resolver.ResolveSteps(namespace, querier)
867867
if err != nil {
868-
go o.recorder.Event(ns, corev1.EventTypeWarning,"ResolutionFailed", err.Error())
868+
go o.recorder.Event(ns, corev1.EventTypeWarning, "ResolutionFailed", err.Error())
869869
return err
870870
}
871871

pkg/controller/registry/resolver/cache.go

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ import (
99
"time"
1010

1111
"github.com/blang/semver"
12-
"github.com/operator-framework/operator-registry/pkg/api"
13-
"github.com/operator-framework/operator-registry/pkg/client"
14-
opregistry "github.com/operator-framework/operator-registry/pkg/registry"
1512
"github.com/sirupsen/logrus"
1613

14+
v1alpha1listers "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/listers/operators/v1alpha1"
1715
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry"
16+
"github.com/operator-framework/operator-registry/pkg/api"
17+
"github.com/operator-framework/operator-registry/pkg/client"
18+
opregistry "github.com/operator-framework/operator-registry/pkg/registry"
1819
)
1920

2021
type RegistryClientProvider interface {
@@ -43,27 +44,31 @@ type OperatorCacheProvider interface {
4344
}
4445

4546
type OperatorCache struct {
46-
logger logrus.FieldLogger
47-
rcp RegistryClientProvider
48-
snapshots map[registry.CatalogKey]*CatalogSnapshot
49-
ttl time.Duration
50-
sem chan struct{}
51-
m sync.RWMutex
47+
logger logrus.FieldLogger
48+
rcp RegistryClientProvider
49+
catsrcLister v1alpha1listers.CatalogSourceLister
50+
snapshots map[registry.CatalogKey]*CatalogSnapshot
51+
ttl time.Duration
52+
sem chan struct{}
53+
m sync.RWMutex
5254
}
5355

56+
type catalogPriority int
57+
5458
var _ OperatorCacheProvider = &OperatorCache{}
5559

56-
func NewOperatorCache(rcp RegistryClientProvider, log logrus.FieldLogger) *OperatorCache {
60+
func NewOperatorCache(rcp RegistryClientProvider, log logrus.FieldLogger, catsrcLister v1alpha1listers.CatalogSourceLister) *OperatorCache {
5761
const (
5862
MaxConcurrentSnapshotUpdates = 4
5963
)
6064

6165
return &OperatorCache{
62-
logger: log,
63-
rcp: rcp,
64-
snapshots: make(map[registry.CatalogKey]*CatalogSnapshot),
65-
ttl: 5 * time.Minute,
66-
sem: make(chan struct{}, MaxConcurrentSnapshotUpdates),
66+
logger: log,
67+
rcp: rcp,
68+
catsrcLister: catsrcLister,
69+
snapshots: make(map[registry.CatalogKey]*CatalogSnapshot),
70+
ttl: 5 * time.Minute,
71+
sem: make(chan struct{}, MaxConcurrentSnapshotUpdates),
6772
}
6873
}
6974

@@ -151,11 +156,20 @@ func (c *OperatorCache) Namespaced(namespaces ...string) MultiCatalogOperatorFin
151156

152157
for _, miss := range misses {
153158
ctx, cancel := context.WithTimeout(context.Background(), CachePopulateTimeout)
159+
160+
catsrcPriority := 0
161+
// Ignoring error and treat catsrc priority as 0 if not found.
162+
catsrc, err := c.catsrcLister.CatalogSources(miss.Namespace).Get(miss.Name)
163+
if err == nil {
164+
catsrcPriority = catsrc.Spec.Priority
165+
}
166+
154167
s := CatalogSnapshot{
155-
logger: c.logger.WithField("catalog", miss),
156-
key: miss,
157-
expiry: now.Add(c.ttl),
158-
pop: cancel,
168+
logger: c.logger.WithField("catalog", miss),
169+
key: miss,
170+
expiry: now.Add(c.ttl),
171+
pop: cancel,
172+
priority: catalogPriority(catsrcPriority),
159173
}
160174
s.m.Lock()
161175
c.snapshots[miss] = &s
@@ -222,13 +236,13 @@ func ensurePackageProperty(o *Operator, name, version string) {
222236
PackageName: name,
223237
Version: version,
224238
}
225-
byte, err := json.Marshal(prop)
239+
bytes, err := json.Marshal(prop)
226240
if err != nil {
227241
return
228242
}
229243
o.properties = append(o.properties, &api.Property{
230244
Type: opregistry.PackageType,
231-
Value: string(byte),
245+
Value: string(bytes),
232246
})
233247
}
234248

@@ -277,6 +291,7 @@ type CatalogSnapshot struct {
277291
operators []*Operator
278292
m sync.RWMutex
279293
pop context.CancelFunc
294+
priority catalogPriority
280295
}
281296

282297
func (s *CatalogSnapshot) Cancel() {
@@ -354,10 +369,14 @@ func (s SortableSnapshots) Less(i, j int) bool {
354369
return false
355370
}
356371

357-
// the rest are sorted first in namespace preference order, then by name
372+
// the rest are sorted first on priority, namespace and then by name
373+
if s.snapshots[i].priority != s.snapshots[j].priority {
374+
return s.snapshots[i].priority > s.snapshots[j].priority
375+
}
358376
if s.snapshots[i].key.Namespace != s.snapshots[j].key.Namespace {
359377
return s.namespaces[s.snapshots[i].key.Namespace] < s.namespaces[s.snapshots[j].key.Namespace]
360378
}
379+
361380
return s.snapshots[i].key.Name < s.snapshots[j].key.Name
362381
}
363382

pkg/controller/registry/resolver/cache_test.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import (
1313
"github.com/stretchr/testify/assert"
1414
"github.com/stretchr/testify/require"
1515

16+
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry"
17+
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorlister"
1618
"github.com/operator-framework/operator-registry/pkg/api"
1719
"github.com/operator-framework/operator-registry/pkg/client"
1820
opregistry "github.com/operator-framework/operator-registry/pkg/registry"
19-
20-
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry"
2121
)
2222

2323
type BundleStreamStub struct {
@@ -83,8 +83,8 @@ func TestOperatorCacheConcurrency(t *testing.T) {
8383
const (
8484
NWorkers = 64
8585
)
86-
8786
rcp := RegistryClientProviderStub{}
87+
catsrcLister := operatorlister.NewLister().OperatorsV1alpha1().CatalogSourceLister()
8888
var keys []registry.CatalogKey
8989
for i := 0; i < 128; i++ {
9090
for j := 0; j < 8; j++ {
@@ -106,7 +106,7 @@ func TestOperatorCacheConcurrency(t *testing.T) {
106106
}
107107
}
108108

109-
c := NewOperatorCache(rcp, logrus.New())
109+
c := NewOperatorCache(rcp, logrus.New(), catsrcLister)
110110

111111
errs := make(chan error)
112112
for w := 0; w < NWorkers; w++ {
@@ -140,6 +140,7 @@ func TestOperatorCacheConcurrency(t *testing.T) {
140140

141141
func TestOperatorCacheExpiration(t *testing.T) {
142142
rcp := RegistryClientProviderStub{}
143+
catsrcLister := operatorlister.NewLister().OperatorsV1alpha1().CatalogSourceLister()
143144
key := registry.CatalogKey{Namespace: "dummynamespace", Name: "dummyname"}
144145
rcp[key] = &RegistryClientStub{
145146
BundleIterator: client.NewBundleIterator(&BundleStreamStub{
@@ -155,14 +156,15 @@ func TestOperatorCacheExpiration(t *testing.T) {
155156
}),
156157
}
157158

158-
c := NewOperatorCache(rcp, logrus.New())
159+
c := NewOperatorCache(rcp, logrus.New(), catsrcLister)
159160
c.ttl = 0 // instantly stale
160161

161162
require.Len(t, c.Namespaced("dummynamespace").Catalog(key).Find(WithCSVName("csvname")), 1)
162163
}
163164

164165
func TestOperatorCacheReuse(t *testing.T) {
165166
rcp := RegistryClientProviderStub{}
167+
catsrcLister := operatorlister.NewLister().OperatorsV1alpha1().CatalogSourceLister()
166168
key := registry.CatalogKey{Namespace: "dummynamespace", Name: "dummyname"}
167169
rcp[key] = &RegistryClientStub{
168170
BundleIterator: client.NewBundleIterator(&BundleStreamStub{
@@ -178,7 +180,7 @@ func TestOperatorCacheReuse(t *testing.T) {
178180
}),
179181
}
180182

181-
c := NewOperatorCache(rcp, logrus.New())
183+
c := NewOperatorCache(rcp, logrus.New(), catsrcLister)
182184

183185
require.Len(t, c.Namespaced("dummynamespace").Catalog(key).Find(WithCSVName("csvname")), 1)
184186
}
@@ -290,6 +292,7 @@ func TestCatalogSnapshotFind(t *testing.T) {
290292

291293
func TestStripPluralRequiredAndProvidedAPIKeys(t *testing.T) {
292294
rcp := RegistryClientProviderStub{}
295+
catsrcLister := operatorlister.NewLister().OperatorsV1alpha1().CatalogSourceLister()
293296
key := registry.CatalogKey{Namespace: "testnamespace", Name: "testname"}
294297
rcp[key] = &RegistryClientStub{
295298
BundleIterator: client.NewBundleIterator(&BundleStreamStub{
@@ -327,7 +330,7 @@ func TestStripPluralRequiredAndProvidedAPIKeys(t *testing.T) {
327330
}),
328331
}
329332

330-
c := NewOperatorCache(rcp, logrus.New())
333+
c := NewOperatorCache(rcp, logrus.New(), catsrcLister)
331334

332335
nc := c.Namespaced("testnamespace")
333336
result, err := AtLeast(1, nc.Find(ProvidingAPI(opregistry.APIKey{Group: "g", Version: "v1", Kind: "K"})))

pkg/controller/registry/resolver/generation_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
opregistry "github.com/operator-framework/operator-registry/pkg/registry"
1010
"github.com/stretchr/testify/require"
1111
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
12-
1312
)
1413

1514
var NoVersion = semver.MustParse("0.0.0")

pkg/controller/registry/resolver/legacy_resolver.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ func (r *LegacyResolver) ResolveSteps(namespace string, sourceQuerier SourceQuer
7979
return nil, nil, nil, err
8080
}
8181

82-
8382
// if there's no error, we were able to satisfy all constraints in the subscription set, so we calculate what
8483
// changes to persist to the cluster and write them out as `steps`
8584
steps := []*v1alpha1.Step{}

pkg/controller/registry/resolver/legacy_resolver_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import (
1010
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorlister"
1111
)
1212

13-
14-
1513
func TestResolverLegacy(t *testing.T) {
1614
namespace := "catsrc-namespace"
1715
for _, tt := range SharedResolverSpecs() {

pkg/controller/registry/resolver/operators.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ func NewOperatorFromBundle(bundle *api.Bundle, startingCSV string, sourceKey reg
258258

259259
// legacy support - if the api doesn't contain properties/dependencies, build them from required/provided apis
260260
properties := bundle.Properties
261-
if properties == nil || len(properties) == 0{
261+
if properties == nil || len(properties) == 0 {
262262
properties, err = apisToProperties(provided)
263263
if err != nil {
264264
return nil, err
@@ -297,8 +297,6 @@ func NewOperatorFromBundle(bundle *api.Bundle, startingCSV string, sourceKey reg
297297
return op, nil
298298
}
299299

300-
301-
302300
return &Operator{
303301
name: bundle.CsvName,
304302
replaces: bundle.Replaces,

pkg/controller/registry/resolver/resolver.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ import (
66
"fmt"
77
"sort"
88

9-
"github.com/operator-framework/api/pkg/operators/v1alpha1"
10-
opregistry "github.com/operator-framework/operator-registry/pkg/registry"
119
"github.com/sirupsen/logrus"
1210
utilerrors "k8s.io/apimachinery/pkg/util/errors"
1311

12+
"github.com/operator-framework/api/pkg/operators/v1alpha1"
13+
v1alpha1listers "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/listers/operators/v1alpha1"
1414
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry"
1515
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/solver"
16+
opregistry "github.com/operator-framework/operator-registry/pkg/registry"
1617
)
1718

1819
type OperatorResolver interface {
@@ -24,9 +25,9 @@ type SatResolver struct {
2425
log logrus.FieldLogger
2526
}
2627

27-
func NewDefaultSatResolver(rcp RegistryClientProvider, log logrus.FieldLogger) *SatResolver {
28+
func NewDefaultSatResolver(rcp RegistryClientProvider, catsrcLister v1alpha1listers.CatalogSourceLister, log logrus.FieldLogger) *SatResolver {
2829
return &SatResolver{
29-
cache: NewOperatorCache(rcp, log),
30+
cache: NewOperatorCache(rcp, log, catsrcLister),
3031
log: log,
3132
}
3233
}

0 commit comments

Comments
 (0)