Skip to content

Bug 1859594: fix(resolver): Exclude all installed packages in dependency search #1666

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/controller/operators/catalog/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,7 @@ func (o *Operator) validateCustomResourceDefinition(oldCRD *v1beta1ext.CustomRes
return err
}
for _, version := range oldCRD.Spec.Versions {
if !version.Served {
if version.Served {
gvr := schema.GroupVersionResource{Group: oldCRD.Spec.Group, Version: version.Name, Resource: oldCRD.Spec.Names.Plural}
err := o.validateExistingCRs(gvr, convertedCRD)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions pkg/controller/registry/registry_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type ChannelEntryStream interface {
// ClientInterface that extends client.Interface
type ClientInterface interface {
client.Interface
FindBundleThatProvides(ctx context.Context, group, version, kind, excludedPkgName string) (*registryapi.Bundle, error)
FindBundleThatProvides(ctx context.Context, group, version, kind string, excludedPackages map[string]struct{}) (*registryapi.Bundle, error)
GetLatestChannelEntriesThatProvide(ctx context.Context, group, version, kind string) (*ChannelEntryIterator, error)
}

Expand Down Expand Up @@ -81,14 +81,14 @@ func (rc *Client) GetLatestChannelEntriesThatProvide(ctx context.Context, group,

// 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) {
func (rc *Client) FindBundleThatProvides(ctx context.Context, group, version, kind string, excludedPackages map[string]struct{}) (*registryapi.Bundle, error) {
it, err := rc.GetLatestChannelEntriesThatProvide(ctx, group, version, kind)
if err != nil {
return nil, err
}
entry := rc.filterChannelEntries(ctx, it, excludedPkgName)
entry := rc.filterChannelEntries(ctx, it, excludedPackages)
if entry == nil {
return nil, fmt.Errorf("Unable to find a channel entry which doesn't belong to package %s's default channel", excludedPkgName)
return nil, fmt.Errorf("Unable to find a channel entry that satisfies the requirements")
}
bundle, err := rc.Client.Registry.GetBundle(ctx, &registryapi.GetBundleRequest{PkgName: entry.PackageName, ChannelName: entry.ChannelName, CsvName: entry.BundleName})
if err != nil {
Expand All @@ -100,12 +100,12 @@ func (rc *Client) FindBundleThatProvides(ctx context.Context, group, version, ki
// FilterChannelEntries filters out channel entries that provide the requested
// API and come from the same package with original operator and returns the
// first entry on the list from the default channel of that package
func (rc *Client) filterChannelEntries(ctx context.Context, it *ChannelEntryIterator, excludedPkgName string) *opregistry.ChannelEntry {
func (rc *Client) filterChannelEntries(ctx context.Context, it *ChannelEntryIterator, excludedPackages map[string]struct{}) *opregistry.ChannelEntry {
defChannels := make(map[string]string, 0)

var entries []*opregistry.ChannelEntry
for e := it.Next(); e != nil; e = it.Next() {
if e.PackageName != excludedPkgName {
if _, ok := excludedPackages[e.PackageName]; !ok {
// keep track of the default channel for each package
if _, ok := defChannels[e.PackageName]; !ok {
defChannel, err := rc.getDefaultPackageChannel(ctx, e.PackageName)
Expand Down
7 changes: 6 additions & 1 deletion pkg/controller/registry/resolver/evolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,14 @@ func (e *NamespaceGenerationEvolver) queryForRequiredAPIs() error {
initialSource = operator.SourceInfo()
break
}
// Get the list of installed operators in the namespace
opList := make(map[string]struct{})
for _, operator := range e.gen.Operators() {
opList[operator.SourceInfo().Package] = struct{}{}
}

// attempt to find a bundle that provides that api
if bundle, key, err := e.querier.FindProvider(*api, initialSource.Catalog, initialSource.Package); err == nil {
if bundle, key, err := e.querier.FindProvider(*api, initialSource.Catalog, opList); err == nil {
// add a bundle that provides the api to the generation
o, err := NewOperatorFromBundle(bundle, "", *key)
if err != nil {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions pkg/controller/registry/resolver/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type SourceRef struct {
}

type SourceQuerier interface {
FindProvider(api opregistry.APIKey, initialSource CatalogKey, excludedPkgName string) (*api.Bundle, *CatalogKey, error)
FindProvider(api opregistry.APIKey, initialSource CatalogKey, excludedPackages map[string]struct{}) (*api.Bundle, *CatalogKey, error)
FindBundle(pkgName, channelName, bundleName string, initialSource CatalogKey) (*api.Bundle, *CatalogKey, error)
FindLatestBundle(pkgName, channelName string, initialSource CatalogKey) (*api.Bundle, *CatalogKey, error)
FindReplacement(currentVersion *semver.Version, bundleName, pkgName, channelName string, initialSource CatalogKey) (*api.Bundle, *CatalogKey, error)
Expand All @@ -54,23 +54,23 @@ func (q *NamespaceSourceQuerier) Queryable() error {
return nil
}

func (q *NamespaceSourceQuerier) FindProvider(api opregistry.APIKey, initialSource CatalogKey, excludedPkgName string) (*registryapi.Bundle, *CatalogKey, error) {
func (q *NamespaceSourceQuerier) FindProvider(api opregistry.APIKey, initialSource CatalogKey, excludedPackages map[string]struct{}) (*registryapi.Bundle, *CatalogKey, error) {
if initialSource.Name != "" && initialSource.Namespace != "" {
source, ok := q.sources[initialSource]
if ok {
if bundle, err := source.FindBundleThatProvides(context.TODO(), api.Group, api.Version, api.Kind, excludedPkgName); err == nil {
if bundle, err := source.FindBundleThatProvides(context.TODO(), api.Group, api.Version, api.Kind, excludedPackages); err == nil {
return bundle, &initialSource, nil
}
if bundle, err := source.FindBundleThatProvides(context.TODO(), api.Plural+"."+api.Group, api.Version, api.Kind, excludedPkgName); err == nil {
if bundle, err := source.FindBundleThatProvides(context.TODO(), api.Plural+"."+api.Group, api.Version, api.Kind, excludedPackages); err == nil {
return bundle, &initialSource, nil
}
}
}
for key, source := range q.sources {
if bundle, err := source.FindBundleThatProvides(context.TODO(), api.Group, api.Version, api.Kind, excludedPkgName); err == nil {
if bundle, err := source.FindBundleThatProvides(context.TODO(), api.Group, api.Version, api.Kind, excludedPackages); err == nil {
return bundle, &key, nil
}
if bundle, err := source.FindBundleThatProvides(context.TODO(), api.Plural+"."+api.Group, api.Version, api.Kind, excludedPkgName); err == nil {
if bundle, err := source.FindBundleThatProvides(context.TODO(), api.Plural+"."+api.Group, api.Version, api.Kind, excludedPackages); err == nil {
return bundle, &key, nil
}
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/controller/registry/resolver/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func TestNamespaceSourceQuerier_FindProvider(t *testing.T) {
CatalogKey{"test", "ns"}: &fakeSource,
CatalogKey{"test2", "ns"}: &fakeSource2,
}
excludedPkgs := make(map[string]struct{})
bundle := &api.Bundle{CsvName: "test", PackageName: "testPkg", ChannelName: "testChannel"}
bundle2 := &api.Bundle{CsvName: "test2", PackageName: "testPkg2", ChannelName: "testChannel2"}
fakeSource.GetBundleThatProvidesStub = func(ctx context.Context, group, version, kind string) (*api.Bundle, error) {
Expand All @@ -135,13 +136,13 @@ func TestNamespaceSourceQuerier_FindProvider(t *testing.T) {
}
return bundle2, nil
}
fakeSource.FindBundleThatProvidesStub = func(ctx context.Context, group, version, kind, pkgName string) (*api.Bundle, error) {
fakeSource.FindBundleThatProvidesStub = func(ctx context.Context, group, version, kind string, excludedPkgs map[string]struct{}) (*api.Bundle, error) {
if group != "group" || version != "version" || kind != "kind" {
return nil, fmt.Errorf("Not Found")
}
return bundle, nil
}
fakeSource2.FindBundleThatProvidesStub = func(ctx context.Context, group, version, kind, pkgName string) (*api.Bundle, error) {
fakeSource2.FindBundleThatProvidesStub = func(ctx context.Context, group, version, kind string, excludedPkgs map[string]struct{}) (*api.Bundle, error) {
if group != "group2" || version != "version2" || kind != "kind2" {
return nil, fmt.Errorf("Not Found")
}
Expand Down Expand Up @@ -228,7 +229,7 @@ func TestNamespaceSourceQuerier_FindProvider(t *testing.T) {
q := &NamespaceSourceQuerier{
sources: tt.fields.sources,
}
bundle, key, err := q.FindProvider(tt.args.api, tt.args.catalogKey, "")
bundle, key, err := q.FindProvider(tt.args.api, tt.args.catalogKey, excludedPkgs)
require.Equal(t, tt.out.err, err)
require.Equal(t, tt.out.bundle, bundle)
require.Equal(t, tt.out.key, key)
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/registry/resolver/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,15 +360,15 @@ func NewFakeSourceQuerier(bundlesByCatalog map[CatalogKey][]*api.Bundle) *Namesp
return nil, fmt.Errorf("no bundle found")
}

source.FindBundleThatProvidesStub = func(ctx context.Context, groupOrName, version, kind, pkgName string) (*api.Bundle, error) {
source.FindBundleThatProvidesStub = func(ctx context.Context, groupOrName, version, kind string, excludedPkgs map[string]struct{}) (*api.Bundle, error) {
bundles, ok := bundlesByCatalog[catKey]
if !ok {
return nil, fmt.Errorf("API (%s/%s/%s) not provided by a package in %s CatalogSource", groupOrName, version, kind, catKey)
}
sortedBundles := SortBundleInPackageChannel(bundles)
for k, v := range sortedBundles {
pkgname := getPkgName(k)
if pkgname == pkgName {
if _, ok := excludedPkgs[pkgname]; ok {
continue
}

Expand Down
Loading