diff --git a/pkg/controller/operators/catalog/og_source_provider.go b/pkg/controller/operators/catalog/og_source_provider.go deleted file mode 100644 index 4045a279ae..0000000000 --- a/pkg/controller/operators/catalog/og_source_provider.go +++ /dev/null @@ -1,82 +0,0 @@ -package catalog - -import ( - "context" - "fmt" - - v1listers "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/listers/operators/v1" - - "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/cache" - "github.com/sirupsen/logrus" - "k8s.io/apimachinery/pkg/labels" -) - -type OperatorGroupToggleSourceProvider struct { - sp cache.SourceProvider - logger *logrus.Logger - ogLister v1listers.OperatorGroupLister -} - -func NewOperatorGroupToggleSourceProvider(sp cache.SourceProvider, logger *logrus.Logger, - ogLister v1listers.OperatorGroupLister) *OperatorGroupToggleSourceProvider { - return &OperatorGroupToggleSourceProvider{ - sp: sp, - logger: logger, - ogLister: ogLister, - } -} - -const exclusionAnnotation string = "olm.operatorframework.io/exclude-global-namespace-resolution" - -func (e *OperatorGroupToggleSourceProvider) Sources(namespaces ...string) map[cache.SourceKey]cache.Source { - // Check if annotation is set first - resolutionNamespaces, err := e.CheckForExclusion(namespaces...) - if err != nil { - e.logger.Errorf("error checking namespaces %#v for global resolution exlusion: %s", namespaces, err) - // Fail early with a dummy Source that returns an error - // TODO: Update the Sources interface to return an error - m := make(map[cache.SourceKey]cache.Source) - key := cache.SourceKey{Name: "operatorgroup-unavailable", Namespace: namespaces[0]} - source := errorSource{err} - m[key] = source - return m - } - return e.sp.Sources(resolutionNamespaces...) -} - -type errorSource struct { - error -} - -func (e errorSource) Snapshot(ctx context.Context) (*cache.Snapshot, error) { - return nil, e.error -} - -func (e *OperatorGroupToggleSourceProvider) CheckForExclusion(namespaces ...string) ([]string, error) { - var defaultResult = namespaces - // The first namespace provided is always the current namespace being synced - var ownNamespace = namespaces[0] - var toggledResult = []string{ownNamespace} - - // Check the OG on the NS provided for the exclusion annotation - ogs, err := e.ogLister.OperatorGroups(ownNamespace).List(labels.Everything()) - if err != nil { - return nil, fmt.Errorf("listing operatorgroups in namespace %s: %s", ownNamespace, err) - } - - if len(ogs) != 1 { - // Problem with the operatorgroup configuration in the namespace, or the operatorgroup has not yet been persisted - // Note: a resync will be triggered if/when the operatorgroup becomes available - return nil, fmt.Errorf("found %d operatorgroups in namespace %s: expected 1", len(ogs), ownNamespace) - } - - var og = ogs[0] - if val, ok := og.Annotations[exclusionAnnotation]; ok && val == "true" { - // Exclusion specified - // Ignore the globalNamespace for the purposes of resolution in this namespace - e.logger.Printf("excluding global catalogs from resolution in namespace %s", ownNamespace) - return toggledResult, nil - } - - return defaultResult, nil -} diff --git a/pkg/controller/operators/catalog/operator.go b/pkg/controller/operators/catalog/operator.go index 1f637cbe37..b281d5f760 100644 --- a/pkg/controller/operators/catalog/operator.go +++ b/pkg/controller/operators/catalog/operator.go @@ -128,7 +128,7 @@ type Operator struct { bundleUnpackTimeout time.Duration clientFactory clients.Factory muInstallPlan sync.Mutex - sourceInvalidator *resolver.RegistrySourceProvider + resolverSourceProvider *resolver.RegistrySourceProvider } type CatalogSourceSyncFunc func(logger *logrus.Entry, in *v1alpha1.CatalogSource) (out *v1alpha1.CatalogSource, continueSync bool, syncError error) @@ -214,10 +214,9 @@ func NewOperator(ctx context.Context, kubeconfigPath string, clock utilclock.Clo clientFactory: clients.NewFactory(validatingConfig), } op.sources = grpc.NewSourceStore(logger, 10*time.Second, 10*time.Minute, op.syncSourceState) - op.sourceInvalidator = resolver.SourceProviderFromRegistryClientProvider(op.sources, lister.OperatorsV1alpha1().CatalogSourceLister(), logger) - resolverSourceProvider := NewOperatorGroupToggleSourceProvider(op.sourceInvalidator, logger, op.lister.OperatorsV1().OperatorGroupLister()) + op.resolverSourceProvider = resolver.SourceProviderFromRegistryClientProvider(op.sources, lister.OperatorsV1alpha1().CatalogSourceLister(), logger) op.reconciler = reconciler.NewRegistryReconcilerFactory(lister, opClient, configmapRegistryImage, op.now, ssaClient, workloadUserID, opmImage, utilImage) - res := resolver.NewOperatorStepResolver(lister, crClient, operatorNamespace, resolverSourceProvider, logger) + res := resolver.NewOperatorStepResolver(lister, crClient, operatorNamespace, op.resolverSourceProvider, logger) op.resolver = resolver.NewInstrumentedResolver(res, metrics.RegisterDependencyResolutionSuccess, metrics.RegisterDependencyResolutionFailure) // Wire OLM CR sharedIndexInformers @@ -346,7 +345,7 @@ func NewOperator(ctx context.Context, kubeconfigPath string, clock utilclock.Clo subscription.WithAppendedReconcilers(subscription.ReconcilerFromLegacySyncHandler(op.syncSubscriptions, nil)), subscription.WithRegistryReconcilerFactory(op.reconciler), subscription.WithGlobalCatalogNamespace(op.namespace), - subscription.WithSourceProvider(op.sourceInvalidator), + subscription.WithSourceProvider(op.resolverSourceProvider), ) if err != nil { return nil, err @@ -765,7 +764,7 @@ func (o *Operator) syncSourceState(state grpc.SourceState) { switch state.State { case connectivity.Ready: - o.sourceInvalidator.Invalidate(resolvercache.SourceKey(state.Key)) + o.resolverSourceProvider.Invalidate(resolvercache.SourceKey(state.Key)) if o.namespace == state.Key.Namespace { namespaces, err := index.CatalogSubscriberNamespaces(o.catalogSubscriberIndexer, state.Key.Name, state.Key.Namespace)