-
Notifications
You must be signed in to change notification settings - Fork 552
Prune API of the resolver package. #2330
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
Merged
openshift-merge-robot
merged 5 commits into
operator-framework:master
from
benluddy:shrink-resolver-surface
Aug 18, 2021
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
765ba9a
Remove generated FakeAPIIntersectionReconciler.
benluddy f27835d
Move OperatorGroup surface logic to the olm package.
benluddy 2f90c7d
Move API labeler from the resolver package to the olm package.
benluddy 0829a70
Remove OperatorSurface interface from resolver.
benluddy 5ef4dab
Extract SourceQuerier from the resolver package.
benluddy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -o fakes/fake_registry_client.go ../../../../vendor/github.com/operator-framework/operator-registry/pkg/api.RegistryClient | ||
//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -o fakes/fake_registry_interface.go ../../registry/registry_client.go ClientInterface | ||
package catalog | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/blang/semver/v4" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/util/errors" | ||
|
||
"github.com/operator-framework/operator-registry/pkg/api" | ||
"github.com/operator-framework/operator-registry/pkg/client" | ||
|
||
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry" | ||
) | ||
|
||
const SkipPackageAnnotationKey = "olm.skipRange" | ||
|
||
type SourceRef struct { | ||
Address string | ||
Client client.Interface | ||
LastConnect metav1.Time | ||
LastHealthy metav1.Time | ||
} | ||
|
||
type SourceQuerier interface { | ||
FindReplacement(currentVersion *semver.Version, bundleName, pkgName, channelName string, initialSource registry.CatalogKey) (*api.Bundle, *registry.CatalogKey, error) | ||
Queryable() error | ||
} | ||
|
||
type NamespaceSourceQuerier struct { | ||
sources map[registry.CatalogKey]registry.ClientInterface | ||
} | ||
|
||
var _ SourceQuerier = &NamespaceSourceQuerier{} | ||
|
||
func NewNamespaceSourceQuerier(sources map[registry.CatalogKey]registry.ClientInterface) *NamespaceSourceQuerier { | ||
return &NamespaceSourceQuerier{ | ||
sources: sources, | ||
} | ||
} | ||
|
||
func (q *NamespaceSourceQuerier) Queryable() error { | ||
if len(q.sources) == 0 { | ||
return fmt.Errorf("no catalog sources available") | ||
} | ||
return nil | ||
} | ||
|
||
func (q *NamespaceSourceQuerier) FindReplacement(currentVersion *semver.Version, bundleName, pkgName, channelName string, initialSource registry.CatalogKey) (*api.Bundle, *registry.CatalogKey, error) { | ||
dinhxuanvu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
errs := []error{} | ||
|
||
if initialSource.Name != "" && initialSource.Namespace != "" { | ||
source, ok := q.sources[initialSource] | ||
if !ok { | ||
return nil, nil, fmt.Errorf("CatalogSource %s not found", initialSource.Name) | ||
} | ||
|
||
bundle, err := q.findChannelHead(currentVersion, pkgName, channelName, source) | ||
if bundle != nil { | ||
return bundle, &initialSource, nil | ||
} | ||
if err != nil { | ||
errs = append(errs, err) | ||
} | ||
|
||
bundle, err = source.GetReplacementBundleInPackageChannel(context.TODO(), bundleName, pkgName, channelName) | ||
if bundle != nil { | ||
return bundle, &initialSource, nil | ||
} | ||
if err != nil { | ||
errs = append(errs, err) | ||
} | ||
|
||
return nil, nil, errors.NewAggregate(errs) | ||
} | ||
|
||
for key, source := range q.sources { | ||
bundle, err := q.findChannelHead(currentVersion, pkgName, channelName, source) | ||
if bundle != nil { | ||
return bundle, &initialSource, nil | ||
} | ||
if err != nil { | ||
errs = append(errs, err) | ||
} | ||
|
||
bundle, err = source.GetReplacementBundleInPackageChannel(context.TODO(), bundleName, pkgName, channelName) | ||
if bundle != nil { | ||
return bundle, &key, nil | ||
} | ||
if err != nil { | ||
errs = append(errs, err) | ||
} | ||
} | ||
return nil, nil, errors.NewAggregate(errs) | ||
} | ||
|
||
func (q *NamespaceSourceQuerier) findChannelHead(currentVersion *semver.Version, pkgName, channelName string, source client.Interface) (*api.Bundle, error) { | ||
if currentVersion == nil { | ||
return nil, nil | ||
} | ||
|
||
latest, err := source.GetBundleInPackageChannel(context.TODO(), pkgName, channelName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if latest.SkipRange == "" { | ||
return nil, nil | ||
} | ||
|
||
r, err := semver.ParseRange(latest.SkipRange) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if r(*currentVersion) { | ||
return latest, nil | ||
} | ||
return nil, nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
TIL: this wasn't (never?) actually dependency injected
even if it was, the DI should have taken a factory anyway