-
Notifications
You must be signed in to change notification settings - Fork 562
feat(catalog): Add catalog weighting to dependency resolver #1682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,12 +9,13 @@ import ( | |
"time" | ||
|
||
"github.com/blang/semver" | ||
"github.com/operator-framework/operator-registry/pkg/api" | ||
"github.com/operator-framework/operator-registry/pkg/client" | ||
opregistry "github.com/operator-framework/operator-registry/pkg/registry" | ||
"github.com/sirupsen/logrus" | ||
|
||
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/listers/operators/v1alpha1" | ||
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry" | ||
"github.com/operator-framework/operator-registry/pkg/api" | ||
"github.com/operator-framework/operator-registry/pkg/client" | ||
opregistry "github.com/operator-framework/operator-registry/pkg/registry" | ||
) | ||
|
||
type RegistryClientProvider interface { | ||
|
@@ -43,27 +44,33 @@ type OperatorCacheProvider interface { | |
} | ||
|
||
type OperatorCache struct { | ||
logger logrus.FieldLogger | ||
rcp RegistryClientProvider | ||
snapshots map[registry.CatalogKey]*CatalogSnapshot | ||
ttl time.Duration | ||
sem chan struct{} | ||
m sync.RWMutex | ||
logger logrus.FieldLogger | ||
rcp RegistryClientProvider | ||
catsrcLister v1alpha1.CatalogSourceLister | ||
snapshots map[registry.CatalogKey]*CatalogSnapshot | ||
ttl time.Duration | ||
sem chan struct{} | ||
m sync.RWMutex | ||
} | ||
|
||
const defaultCatalogSourcePriority int = 0 | ||
|
||
type catalogSourcePriority int | ||
|
||
var _ OperatorCacheProvider = &OperatorCache{} | ||
|
||
func NewOperatorCache(rcp RegistryClientProvider, log logrus.FieldLogger) *OperatorCache { | ||
func NewOperatorCache(rcp RegistryClientProvider, log logrus.FieldLogger, catsrcLister v1alpha1.CatalogSourceLister) *OperatorCache { | ||
const ( | ||
MaxConcurrentSnapshotUpdates = 4 | ||
) | ||
|
||
return &OperatorCache{ | ||
logger: log, | ||
rcp: rcp, | ||
snapshots: make(map[registry.CatalogKey]*CatalogSnapshot), | ||
ttl: 5 * time.Minute, | ||
sem: make(chan struct{}, MaxConcurrentSnapshotUpdates), | ||
logger: log, | ||
rcp: rcp, | ||
catsrcLister: catsrcLister, | ||
snapshots: make(map[registry.CatalogKey]*CatalogSnapshot), | ||
ttl: 5 * time.Minute, | ||
sem: make(chan struct{}, MaxConcurrentSnapshotUpdates), | ||
} | ||
} | ||
|
||
|
@@ -151,11 +158,20 @@ func (c *OperatorCache) Namespaced(namespaces ...string) MultiCatalogOperatorFin | |
|
||
for _, miss := range misses { | ||
ctx, cancel := context.WithTimeout(context.Background(), CachePopulateTimeout) | ||
|
||
catsrcPriority := defaultCatalogSourcePriority | ||
// Ignoring error and treat catsrc priority as 0 if not found. | ||
catsrc, err := c.catsrcLister.CatalogSources(miss.Namespace).Get(miss.Name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if anything can be done about this in this PR, but really not a fan of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know, "miss" has a very specific meaning in a cache implementation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is that really helpful in a file named |
||
if err == nil { | ||
catsrcPriority = catsrc.Spec.Priority | ||
} | ||
|
||
s := CatalogSnapshot{ | ||
logger: c.logger.WithField("catalog", miss), | ||
key: miss, | ||
expiry: now.Add(c.ttl), | ||
pop: cancel, | ||
logger: c.logger.WithField("catalog", miss), | ||
key: miss, | ||
expiry: now.Add(c.ttl), | ||
pop: cancel, | ||
priority: catalogSourcePriority(catsrcPriority), | ||
} | ||
s.m.Lock() | ||
c.snapshots[miss] = &s | ||
|
@@ -222,13 +238,13 @@ func ensurePackageProperty(o *Operator, name, version string) { | |
PackageName: name, | ||
Version: version, | ||
} | ||
byte, err := json.Marshal(prop) | ||
bytes, err := json.Marshal(prop) | ||
if err != nil { | ||
return | ||
} | ||
o.properties = append(o.properties, &api.Property{ | ||
Type: opregistry.PackageType, | ||
Value: string(byte), | ||
Value: string(bytes), | ||
}) | ||
} | ||
|
||
|
@@ -277,6 +293,7 @@ type CatalogSnapshot struct { | |
operators []*Operator | ||
m sync.RWMutex | ||
pop context.CancelFunc | ||
priority catalogSourcePriority | ||
} | ||
|
||
func (s *CatalogSnapshot) Cancel() { | ||
|
@@ -354,10 +371,14 @@ func (s SortableSnapshots) Less(i, j int) bool { | |
return false | ||
} | ||
|
||
// the rest are sorted first in namespace preference order, then by name | ||
// the rest are sorted first on priority, namespace and then by name | ||
Bowenislandsong marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this comment necessary here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe could be substitued for more structured comment for the entire There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 to that. "The proper use of comments is to compensate our failure to express ourself in code" "Code changes and evolves. Chunks of it move from here to there. Those chunks bifurcate and reproduce and come together again to form chimeras. Unfortunately the comments don't always follow them, can't always follow them." Further reading on comments: https://blog.usejournal.com/stop-writing-code-comments-28fef5272752 |
||
if s.snapshots[i].priority != s.snapshots[j].priority { | ||
return s.snapshots[i].priority > s.snapshots[j].priority | ||
} | ||
if s.snapshots[i].key.Namespace != s.snapshots[j].key.Namespace { | ||
return s.namespaces[s.snapshots[i].key.Namespace] < s.namespaces[s.snapshots[j].key.Namespace] | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. noise |
||
return s.snapshots[i].key.Name < s.snapshots[j].key.Name | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,6 @@ import ( | |
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorlister" | ||
) | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. noise. Similar in other places. |
||
|
||
func TestResolverLegacy(t *testing.T) { | ||
namespace := "catsrc-namespace" | ||
for _, tt := range SharedResolverSpecs() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -258,7 +258,7 @@ func NewOperatorFromBundle(bundle *api.Bundle, startingCSV string, sourceKey reg | |
|
||
// legacy support - if the api doesn't contain properties/dependencies, build them from required/provided apis | ||
properties := bundle.Properties | ||
if properties == nil || len(properties) == 0{ | ||
if properties == nil || len(properties) == 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
properties, err = apisToProperties(provided) | ||
if err != nil { | ||
return nil, err | ||
|
@@ -297,8 +297,6 @@ func NewOperatorFromBundle(bundle *api.Bundle, startingCSV string, sourceKey reg | |
return op, nil | ||
} | ||
|
||
|
||
|
||
return &Operator{ | ||
name: bundle.CsvName, | ||
replaces: bundle.Replaces, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you get rid of this noise? Clutters the PR a bit.