Skip to content

Commit 3e10bd5

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

29 files changed

+675
-60
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/registry/resolver/cache.go

Lines changed: 28 additions & 8 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-lifecycle-manager/pkg/api/client/clientset/versioned"
13+
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry"
1214
"github.com/operator-framework/operator-registry/pkg/api"
1315
"github.com/operator-framework/operator-registry/pkg/client"
1416
opregistry "github.com/operator-framework/operator-registry/pkg/registry"
1517
"github.com/sirupsen/logrus"
16-
17-
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry"
18+
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1819
)
1920

2021
type RegistryClientProvider interface {
@@ -45,22 +46,26 @@ type OperatorCacheProvider interface {
4546
type OperatorCache struct {
4647
logger logrus.FieldLogger
4748
rcp RegistryClientProvider
49+
crClient versioned.Interface
4850
snapshots map[registry.CatalogKey]*CatalogSnapshot
4951
ttl time.Duration
5052
sem chan struct{}
5153
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, client versioned.Interface) *OperatorCache {
5761
const (
5862
MaxConcurrentSnapshotUpdates = 4
5963
)
6064

6165
return &OperatorCache{
6266
logger: log,
6367
rcp: rcp,
68+
crClient: client,
6469
snapshots: make(map[registry.CatalogKey]*CatalogSnapshot),
6570
ttl: 5 * time.Minute,
6671
sem: make(chan struct{}, MaxConcurrentSnapshotUpdates),
@@ -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 treating catalog source priority as 0 if not found
162+
catsrc, err := c.crClient.OperatorsV1alpha1().CatalogSources(miss.Namespace).Get(ctx, miss.Name, v1.GetOptions{})
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
@@ -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,11 +369,16 @@ 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 in namespace preference 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
381+
362382
}
363383

364384
// Swap swaps the elements with indexes i and j.

pkg/controller/registry/resolver/cache_test.go

Lines changed: 10 additions & 6 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/api/client/clientset/versioned"
17+
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry"
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 {
@@ -85,6 +85,7 @@ func TestOperatorCacheConcurrency(t *testing.T) {
8585
)
8686

8787
rcp := RegistryClientProviderStub{}
88+
var crClient versioned.Interface
8889
var keys []registry.CatalogKey
8990
for i := 0; i < 128; i++ {
9091
for j := 0; j < 8; j++ {
@@ -106,7 +107,7 @@ func TestOperatorCacheConcurrency(t *testing.T) {
106107
}
107108
}
108109

109-
c := NewOperatorCache(rcp, logrus.New())
110+
c := NewOperatorCache(rcp, logrus.New(), crClient)
110111

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

141142
func TestOperatorCacheExpiration(t *testing.T) {
142143
rcp := RegistryClientProviderStub{}
144+
var crClient versioned.Interface
143145
key := registry.CatalogKey{Namespace: "dummynamespace", Name: "dummyname"}
144146
rcp[key] = &RegistryClientStub{
145147
BundleIterator: client.NewBundleIterator(&BundleStreamStub{
@@ -155,14 +157,15 @@ func TestOperatorCacheExpiration(t *testing.T) {
155157
}),
156158
}
157159

158-
c := NewOperatorCache(rcp, logrus.New())
160+
c := NewOperatorCache(rcp, logrus.New(), crClient)
159161
c.ttl = 0 // instantly stale
160162

161163
require.Len(t, c.Namespaced("dummynamespace").Catalog(key).Find(WithCSVName("csvname")), 1)
162164
}
163165

164166
func TestOperatorCacheReuse(t *testing.T) {
165167
rcp := RegistryClientProviderStub{}
168+
var crClient versioned.Interface
166169
key := registry.CatalogKey{Namespace: "dummynamespace", Name: "dummyname"}
167170
rcp[key] = &RegistryClientStub{
168171
BundleIterator: client.NewBundleIterator(&BundleStreamStub{
@@ -178,7 +181,7 @@ func TestOperatorCacheReuse(t *testing.T) {
178181
}),
179182
}
180183

181-
c := NewOperatorCache(rcp, logrus.New())
184+
c := NewOperatorCache(rcp, logrus.New(), crClient)
182185

183186
require.Len(t, c.Namespaced("dummynamespace").Catalog(key).Find(WithCSVName("csvname")), 1)
184187
}
@@ -290,6 +293,7 @@ func TestCatalogSnapshotFind(t *testing.T) {
290293

291294
func TestStripPluralRequiredAndProvidedAPIKeys(t *testing.T) {
292295
rcp := RegistryClientProviderStub{}
296+
var crClient versioned.Interface
293297
key := registry.CatalogKey{Namespace: "testnamespace", Name: "testname"}
294298
rcp[key] = &RegistryClientStub{
295299
BundleIterator: client.NewBundleIterator(&BundleStreamStub{
@@ -327,7 +331,7 @@ func TestStripPluralRequiredAndProvidedAPIKeys(t *testing.T) {
327331
}),
328332
}
329333

330-
c := NewOperatorCache(rcp, logrus.New())
334+
c := NewOperatorCache(rcp, logrus.New(), crClient)
331335

332336
nc := c.Namespaced("testnamespace")
333337
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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7+
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
78
"sort"
89

910
"github.com/operator-framework/api/pkg/operators/v1alpha1"
@@ -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, log logrus.FieldLogger, client versioned.Interface) *SatResolver {
2829
return &SatResolver{
29-
cache: NewOperatorCache(rcp, log),
30+
cache: NewOperatorCache(rcp, log, client),
3031
log: log,
3132
}
3233
}

0 commit comments

Comments
 (0)