-
Notifications
You must be signed in to change notification settings - Fork 562
Bug 1834936: fix(resolver): don't pick operator from same package when resolve requiredAPI #1521
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 8 commits into
operator-framework:master
from
dinhxuanvu:required-api-package
May 27, 2020
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e899b65
fix(resolver): don't pick operator from same package when resolve req…
dinhxuanvu e4d59c3
Mockgen for registry client
dinhxuanvu 9c0353e
Edit test cases to work with new changes on NamespaceSourceQuerier
dinhxuanvu fa9064d
Update unit test cases to adapt to new changes in NamespaceSourceQuerier
dinhxuanvu 91cc16b
Add e2e test case to test multiple dependencies with same package
dinhxuanvu 2523d2c
Compose registry client & interface under a new interface
dinhxuanvu 9a1bfe3
Address feedbacks on registry client interface
dinhxuanvu 57b5881
Add more comments on e2e test case to clarify test flow
dinhxuanvu 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
This file contains hidden or 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 hidden or 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,121 @@ | ||
//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -o resolver/fakes/fake_registry_client_interface.go . ClientInterface | ||
package registry | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
|
||
"google.golang.org/grpc" | ||
|
||
registryapi "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" | ||
) | ||
|
||
// ChannelEntryStream interface | ||
type ChannelEntryStream interface { | ||
Recv() (*registryapi.ChannelEntry, error) | ||
} | ||
|
||
// ClientInterface that extends client.Interface | ||
type ClientInterface interface { | ||
client.Interface | ||
FindBundleThatProvides(ctx context.Context, group, version, kind, excludedPkgName string) (*registryapi.Bundle, error) | ||
GetLatestChannelEntriesThatProvide(ctx context.Context, group, version, kind string) (*ChannelEntryIterator, error) | ||
} | ||
|
||
// ChannelEntryIterator struct | ||
type ChannelEntryIterator struct { | ||
stream ChannelEntryStream | ||
error error | ||
} | ||
|
||
// NewChannelEntryIterator returns a new ChannelEntryIterator | ||
func NewChannelEntryIterator(stream ChannelEntryStream) *ChannelEntryIterator { | ||
return &ChannelEntryIterator{stream: stream} | ||
} | ||
|
||
// Next returns the next Channel Entry in the grpc stream | ||
func (ceit *ChannelEntryIterator) Next() *registryapi.ChannelEntry { | ||
if ceit.error != nil { | ||
return nil | ||
} | ||
next, err := ceit.stream.Recv() | ||
if err == io.EOF { | ||
return nil | ||
} | ||
if err != nil { | ||
ceit.error = err | ||
} | ||
return next | ||
} | ||
|
||
func (ceit *ChannelEntryIterator) Error() error { | ||
return ceit.error | ||
} | ||
|
||
// Client struct with a registry client embedded | ||
type Client struct { | ||
*client.Client | ||
} | ||
|
||
// NewClientFromConn returns the next Channel Entry in the grpc stream | ||
func NewClientFromConn(conn *grpc.ClientConn) *Client { | ||
return &Client{ | ||
Client: client.NewClientFromConn(conn), | ||
} | ||
} | ||
|
||
var _ ClientInterface = &Client{} | ||
|
||
// GetLatestChannelEntriesThatProvide uses registry client to get a list of | ||
// latest channel entries that provide the requested API (via an iterator) | ||
func (rc *Client) GetLatestChannelEntriesThatProvide(ctx context.Context, group, version, kind string) (*ChannelEntryIterator, error) { | ||
stream, err := rc.Client.Registry.GetLatestChannelEntriesThatProvide(ctx, ®istryapi.GetLatestProvidersRequest{Group: group, Version: version, Kind: kind}) | ||
dinhxuanvu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
return nil, err | ||
} | ||
return NewChannelEntryIterator(stream), nil | ||
} | ||
|
||
// FindBundleThatProvides returns a bundle that provides the request API and | ||
// doesn't belong to the provided package | ||
func (rc *Client) FindBundleThatProvides(ctx context.Context, group, version, kind, excludedPkgName string) (*registryapi.Bundle, error) { | ||
it, err := rc.GetLatestChannelEntriesThatProvide(ctx, group, version, kind) | ||
if err != nil { | ||
return nil, err | ||
} | ||
entry := rc.filterChannelEntries(it, excludedPkgName) | ||
if entry == nil { | ||
return nil, fmt.Errorf("Unable to find a channel entry which doesn't belong to package %s", excludedPkgName) | ||
} | ||
bundle, err := rc.Client.Registry.GetBundle(ctx, ®istryapi.GetBundleRequest{PkgName: entry.PackageName, ChannelName: entry.ChannelName, CsvName: entry.BundleName}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return bundle, nil | ||
} | ||
|
||
// FilterChannelEntries filters out a channel entries that provide the requested | ||
// API and come from the same package with original operator and returns the | ||
// first entry on the list | ||
func (rc *Client) filterChannelEntries(it *ChannelEntryIterator, excludedPkgName string) *opregistry.ChannelEntry { | ||
var entries []*opregistry.ChannelEntry | ||
for e := it.Next(); e != nil; e = it.Next() { | ||
if e.PackageName != excludedPkgName { | ||
entry := &opregistry.ChannelEntry{ | ||
PackageName: e.PackageName, | ||
ChannelName: e.ChannelName, | ||
BundleName: e.BundleName, | ||
Replaces: e.Replaces, | ||
} | ||
entries = append(entries, entry) | ||
} | ||
} | ||
|
||
if entries != nil { | ||
return entries[0] | ||
} | ||
return nil | ||
} |
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.