diff --git a/pkg/controller/operators/catalog/operator.go b/pkg/controller/operators/catalog/operator.go index a4ca7f8ff6..717f7bc05c 100644 --- a/pkg/controller/operators/catalog/operator.go +++ b/pkg/controller/operators/catalog/operator.go @@ -887,8 +887,6 @@ func (o *Operator) syncResolvingNamespace(obj interface{}) error { // get the set of sources that should be used for resolution and best-effort get their connections working logger.Debug("resolving sources") - querier := NewNamespaceSourceQuerier(o.sources.AsClients(o.namespace, namespace)) - logger.Debug("checking if subscriptions need update") subs, err := o.listSubscriptions(namespace) @@ -921,7 +919,7 @@ func (o *Operator) syncResolvingNamespace(obj interface{}) error { subscriptionUpdated = subscriptionUpdated || changedIP // record the current state of the desired corresponding CSV in the status. no-op if we don't know the csv yet. - sub, changedCSV, err := o.ensureSubscriptionCSVState(logger, sub, querier) + sub, changedCSV, err := o.ensureSubscriptionCSVState(logger, sub) if err != nil { logger.Debugf("error recording current state of CSV in status: %v", err) return err @@ -1105,7 +1103,7 @@ func (o *Operator) ensureSubscriptionInstallPlanState(logger *logrus.Entry, sub return out, true, nil } -func (o *Operator) ensureSubscriptionCSVState(logger *logrus.Entry, sub *v1alpha1.Subscription, querier SourceQuerier) (*v1alpha1.Subscription, bool, error) { +func (o *Operator) ensureSubscriptionCSVState(logger *logrus.Entry, sub *v1alpha1.Subscription) (*v1alpha1.Subscription, bool, error) { if sub.Status.CurrentCSV == "" { return sub, false, nil } @@ -1116,10 +1114,6 @@ func (o *Operator) ensureSubscriptionCSVState(logger *logrus.Entry, sub *v1alpha logger.WithError(err).WithField("currentCSV", sub.Status.CurrentCSV).Debug("error fetching csv listed in subscription status") out.Status.State = v1alpha1.SubscriptionStateUpgradePending } else { - // Check if an update is available for the current csv - if err := querier.Queryable(); err != nil { - return nil, false, err - } out.Status.State = v1alpha1.SubscriptionStateAtLatest out.Status.InstalledCSV = sub.Status.CurrentCSV } diff --git a/pkg/controller/operators/catalog/querier.go b/pkg/controller/operators/catalog/querier.go deleted file mode 100644 index 599210e257..0000000000 --- a/pkg/controller/operators/catalog/querier.go +++ /dev/null @@ -1,125 +0,0 @@ -//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 { - // Deprecated: This FindReplacement function will be deprecated soon - 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 -} - -// Deprecated: This FindReplacement function will be deprecated soon -func (q *NamespaceSourceQuerier) FindReplacement(currentVersion *semver.Version, bundleName, pkgName, channelName string, initialSource registry.CatalogKey) (*api.Bundle, *registry.CatalogKey, error) { - 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 -} diff --git a/pkg/controller/operators/catalog/querier_test.go b/pkg/controller/operators/catalog/querier_test.go deleted file mode 100644 index a907973cdd..0000000000 --- a/pkg/controller/operators/catalog/querier_test.go +++ /dev/null @@ -1,107 +0,0 @@ -package catalog - -import ( - "fmt" - "testing" - - "github.com/operator-framework/operator-registry/pkg/client" - "github.com/stretchr/testify/require" - - "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/catalog/fakes" - "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry" -) - -func TestNewNamespaceSourceQuerier(t *testing.T) { - emptySources := map[registry.CatalogKey]registry.ClientInterface{} - nonEmptySources := map[registry.CatalogKey]registry.ClientInterface{ - {Name: "test", Namespace: "ns"}: ®istry.Client{ - Client: &client.Client{ - Registry: &fakes.FakeRegistryClient{}, - }, - }, - } - - type args struct { - sources map[registry.CatalogKey]registry.ClientInterface - } - tests := []struct { - name string - args args - want *NamespaceSourceQuerier - }{ - { - name: "nil", - args: args{ - sources: nil, - }, - want: &NamespaceSourceQuerier{sources: nil}, - }, - { - name: "empty", - args: args{ - sources: emptySources, - }, - want: &NamespaceSourceQuerier{sources: emptySources}, - }, - { - name: "nonEmpty", - args: args{ - sources: nonEmptySources, - }, - want: &NamespaceSourceQuerier{sources: nonEmptySources}, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - require.Equal(t, NewNamespaceSourceQuerier(tt.args.sources), tt.want) - }) - } -} - -func TestNamespaceSourceQuerier_Queryable(t *testing.T) { - type fields struct { - sources map[registry.CatalogKey]registry.ClientInterface - } - tests := []struct { - name string - fields fields - error error - }{ - { - name: "nil", - fields: fields{ - sources: nil, - }, - error: fmt.Errorf("no catalog sources available"), - }, - { - name: "empty", - fields: fields{ - sources: map[registry.CatalogKey]registry.ClientInterface{}, - }, - error: fmt.Errorf("no catalog sources available"), - }, - { - name: "nonEmpty", - fields: fields{ - sources: map[registry.CatalogKey]registry.ClientInterface{ - {Name: "test", Namespace: "ns"}: ®istry.Client{ - Client: &client.Client{ - Registry: &fakes.FakeRegistryClient{}, - }, - }, - }, - }, - error: nil, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - q := &NamespaceSourceQuerier{ - sources: tt.fields.sources, - } - require.Equal(t, q.Queryable(), tt.error) - }) - } -}