Skip to content

Commit 5a64b6a

Browse files
committed
Add catalog priority for dependency resolution
Signed-off-by: Harish <[email protected]>
1 parent 7b35209 commit 5a64b6a

28 files changed

+512
-59
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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t
409409
github.com/grpc-ecosystem/grpc-health-probe v0.3.2 h1:daShAySXI1DnGc8U9B1E4Qm6o7qzmFR4aRIJ4vY/TUo=
410410
github.com/grpc-ecosystem/grpc-health-probe v0.3.2/go.mod h1:izVOQ4RWbjUR6lm4nn+VLJyQ+FyaiGmprEYgI04Gs7U=
411411
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4=
412+
github.com/harishsurf/api v0.3.8-0.20200727161005-2f00961f221d h1:Q9Z/l6BmNar+eqGPRwWFRxnC0F0lFyb/n3x14JTKryM=
413+
github.com/harishsurf/api v0.3.8-0.20200727161005-2f00961f221d/go.mod h1:Xbje9x0SHmh0nihE21kpesB38vk3cyxnE6JdDS8Jo1Q=
412414
github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
413415
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
414416
github.com/hashicorp/go-multierror v0.0.0-20161216184304-ed905158d874/go.mod h1:JMRHfdO9jKNzS/+BTlxCjKNQHg/jZAft8U7LloJvN7I=
@@ -585,8 +587,8 @@ github.com/openshift/client-go v0.0.0-20200326155132-2a6cd50aedd0 h1:kMiuiZXH1Gd
585587
github.com/openshift/client-go v0.0.0-20200326155132-2a6cd50aedd0/go.mod h1:uUQ4LClRO+fg5MF/P6QxjMCb1C9f7Oh4RKepftDnEJE=
586588
github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw=
587589
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=
590+
github.com/operator-framework/api v0.3.9 h1:ggRW5C/7MLmA4cOJ2mjEZ5RqDMsIeMknd6vx15S7Xo4=
591+
github.com/operator-framework/api v0.3.9/go.mod h1:Xbje9x0SHmh0nihE21kpesB38vk3cyxnE6JdDS8Jo1Q=
590592
github.com/operator-framework/operator-registry v1.13.3 h1:SaZ1IKLKGizVgTtT8AlDgaMXFYOiIPxRf8KLve0/DXM=
591593
github.com/operator-framework/operator-registry v1.13.3/go.mod h1:YhnIzOVjRU2ZwZtzt+fjcjW8ujJaSFynBEu7QVKaSdU=
592594
github.com/otiai10/copy v1.2.0 h1:HvG945u96iNadPoG2/Ja2+AUJeW5YuFQMixq9yirC+k=

pkg/controller/registry/resolver/cache.go

Lines changed: 30 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,28 @@ 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 Priority struct {
57+
catsrcPriority int
58+
}
59+
5460
var _ OperatorCacheProvider = &OperatorCache{}
5561

56-
func NewOperatorCache(rcp RegistryClientProvider, log logrus.FieldLogger) *OperatorCache {
62+
func NewOperatorCache(rcp RegistryClientProvider, log logrus.FieldLogger, client versioned.Interface) *OperatorCache {
5763
const (
5864
MaxConcurrentSnapshotUpdates = 4
5965
)
6066

6167
return &OperatorCache{
6268
logger: log,
6369
rcp: rcp,
70+
crClient: client,
6471
snapshots: make(map[registry.CatalogKey]*CatalogSnapshot),
6572
ttl: 5 * time.Minute,
6673
sem: make(chan struct{}, MaxConcurrentSnapshotUpdates),
@@ -151,11 +158,20 @@ func (c *OperatorCache) Namespaced(namespaces ...string) MultiCatalogOperatorFin
151158

152159
for _, miss := range misses {
153160
ctx, cancel := context.WithTimeout(context.Background(), CachePopulateTimeout)
161+
162+
catsrcPriority := 0
163+
// Ignoring error and treating catalog source priority as 0 if not found
164+
catsrc, err := c.crClient.OperatorsV1alpha1().CatalogSources(miss.Namespace).Get(ctx, miss.Name, v1.GetOptions{})
165+
if err == nil {
166+
catsrcPriority = catsrc.Spec.Priority
167+
}
168+
154169
s := CatalogSnapshot{
155-
logger: c.logger.WithField("catalog", miss),
156-
key: miss,
157-
expiry: now.Add(c.ttl),
158-
pop: cancel,
170+
logger: c.logger.WithField("catalog", miss),
171+
key: miss,
172+
expiry: now.Add(c.ttl),
173+
pop: cancel,
174+
priority: Priority{catsrcPriority},
159175
}
160176
s.m.Lock()
161177
c.snapshots[miss] = &s
@@ -277,6 +293,7 @@ type CatalogSnapshot struct {
277293
operators []*Operator
278294
m sync.RWMutex
279295
pop context.CancelFunc
296+
priority Priority
280297
}
281298

282299
func (s *CatalogSnapshot) Cancel() {
@@ -354,10 +371,15 @@ func (s SortableSnapshots) Less(i, j int) bool {
354371
return false
355372
}
356373

357-
// the rest are sorted first in namespace preference order, then by name
374+
// the rest are sorted first in namespace preference order, priority, then by name
358375
if s.snapshots[i].key.Namespace != s.snapshots[j].key.Namespace {
359376
return s.namespaces[s.snapshots[i].key.Namespace] < s.namespaces[s.snapshots[j].key.Namespace]
360377
}
378+
379+
if s.snapshots[i].priority != s.snapshots[j].priority {
380+
return s.snapshots[i].priority.catsrcPriority > s.snapshots[j].priority.catsrcPriority
381+
}
382+
361383
return s.snapshots[i].key.Name < s.snapshots[j].key.Name
362384
}
363385

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)