Skip to content
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

Bug 1744245: fix e2e failure #1001

Merged
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
19 changes: 17 additions & 2 deletions pkg/controller/operators/catalog/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func NewOperator(ctx context.Context, kubeconfigPath string, clock utilclock.Clo
client: crClient,
lister: lister,
namespace: operatorNamespace,
resolver: resolver.NewOperatorsV1alpha1Resolver(lister),
resolver: resolver.NewOperatorsV1alpha1Resolver(lister, crClient),
catsrcQueueSet: queueinformer.NewEmptyResourceQueueSet(),
subQueueSet: queueinformer.NewEmptyResourceQueueSet(),
csvProvidedAPIsIndexer: map[string]cache.Indexer{},
Expand Down Expand Up @@ -702,7 +702,7 @@ func (o *Operator) syncResolvingNamespace(obj interface{}) error {

logger.Debug("checking if subscriptions need update")

subs, err := o.lister.OperatorsV1alpha1().SubscriptionLister().Subscriptions(namespace).List(labels.Everything())
subs, err := o.listSubscriptions(namespace)
if err != nil {
logger.WithError(err).Debug("couldn't list subscriptions")
return err
Expand Down Expand Up @@ -1513,6 +1513,20 @@ func (o *Operator) getUpdatedOwnerReferences(refs []metav1.OwnerReference, names
return updated, nil
}

func (o *Operator) listSubscriptions(namespace string) (subs []*v1alpha1.Subscription, err error) {
list, err := o.client.OperatorsV1alpha1().Subscriptions(namespace).List(metav1.ListOptions{})
if err != nil {
return
}

subs = make([]*v1alpha1.Subscription, 0)
for i := range list.Items {
subs = append(subs, &list.Items[i])
}

return
}

// competingCRDOwnersExist returns true if there exists a CSV that owns at least one of the given CSVs owned CRDs (that's not the given CSV)
func competingCRDOwnersExist(namespace string, csv *v1alpha1.ClusterServiceVersion, existingOwners map[string][]string) (bool, error) {
// Attempt to find a pre-existing owner in the namespace for any owned crd
Expand Down Expand Up @@ -1542,3 +1556,4 @@ func getCSVNameSet(plan *v1alpha1.InstallPlan) map[string]struct{} {

return csvNameSet
}

21 changes: 19 additions & 2 deletions pkg/controller/registry/resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"k8s.io/apimachinery/pkg/labels"

"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
v1alpha1listers "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/listers/operators/v1alpha1"
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorlister"
)
Expand All @@ -24,14 +25,16 @@ type Resolver interface {
type OperatorsV1alpha1Resolver struct {
subLister v1alpha1listers.SubscriptionLister
csvLister v1alpha1listers.ClusterServiceVersionLister
client versioned.Interface
}

var _ Resolver = &OperatorsV1alpha1Resolver{}

func NewOperatorsV1alpha1Resolver(lister operatorlister.OperatorLister) *OperatorsV1alpha1Resolver {
func NewOperatorsV1alpha1Resolver(lister operatorlister.OperatorLister, client versioned.Interface) *OperatorsV1alpha1Resolver {
return &OperatorsV1alpha1Resolver{
subLister: lister.OperatorsV1alpha1().SubscriptionLister(),
csvLister: lister.OperatorsV1alpha1().ClusterServiceVersionLister(),
client: client,
}
}

Expand All @@ -55,7 +58,7 @@ func (r *OperatorsV1alpha1Resolver) ResolveSteps(namespace string, sourceQuerier
}
}

subs, err := r.subLister.Subscriptions(namespace).List(labels.Everything())
subs, err := r.listSubscriptions(namespace)
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -168,3 +171,17 @@ func (r *OperatorsV1alpha1Resolver) sourceInfoToSubscriptions(subs []*v1alpha1.S
}
return
}

func (r *OperatorsV1alpha1Resolver) listSubscriptions(namespace string) (subs []*v1alpha1.Subscription, err error) {
list, err := r.client.OperatorsV1alpha1().Subscriptions(namespace).List(metav1.ListOptions{})
if err != nil {
return
}

subs = make([]*v1alpha1.Subscription, 0)
for i := range list.Items {
subs = append(subs, &list.Items[i])
}

return
}
13 changes: 7 additions & 6 deletions pkg/controller/registry/resolver/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"k8s.io/client-go/tools/cache"

"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned/fake"
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/informers/externalversions"
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
Expand Down Expand Up @@ -375,12 +376,12 @@ func TestNamespaceResolver(t *testing.T) {
for _, steps := range tt.out.steps {
expectedSteps = append(expectedSteps, steps...)
}
informerFactory, _ := StartResolverInformers(namespace, stopc, tt.clusterState...)
clientFake, informerFactory, _ := StartResolverInformers(namespace, stopc, tt.clusterState...)
lister := operatorlister.NewLister()
lister.OperatorsV1alpha1().RegisterSubscriptionLister(namespace, informerFactory.Operators().V1alpha1().Subscriptions().Lister())
lister.OperatorsV1alpha1().RegisterClusterServiceVersionLister(namespace, informerFactory.Operators().V1alpha1().ClusterServiceVersions().Lister())

resolver := NewOperatorsV1alpha1Resolver(lister)
resolver := NewOperatorsV1alpha1Resolver(lister, clientFake)
steps, subs, err := resolver.ResolveSteps(namespace, tt.querier)
require.Equal(t, tt.out.err, err)
t.Logf("%#v", steps)
Expand Down Expand Up @@ -448,12 +449,12 @@ func TestNamespaceResolverRBAC(t *testing.T) {
for _, steps := range tt.out.steps {
expectedSteps = append(expectedSteps, steps...)
}
informerFactory, _ := StartResolverInformers(namespace, stopc, tt.clusterState...)
clientFake, informerFactory, _ := StartResolverInformers(namespace, stopc, tt.clusterState...)
lister := operatorlister.NewLister()
lister.OperatorsV1alpha1().RegisterSubscriptionLister(namespace, informerFactory.Operators().V1alpha1().Subscriptions().Lister())
lister.OperatorsV1alpha1().RegisterClusterServiceVersionLister(namespace, informerFactory.Operators().V1alpha1().ClusterServiceVersions().Lister())

resolver := NewOperatorsV1alpha1Resolver(lister)
resolver := NewOperatorsV1alpha1Resolver(lister, clientFake)
querier := NewFakeSourceQuerier(map[CatalogKey][]*opregistry.Bundle{catalog: tt.bundlesInCatalog})
steps, subs, err := resolver.ResolveSteps(namespace, querier)
require.Equal(t, tt.out.err, err)
Expand All @@ -465,7 +466,7 @@ func TestNamespaceResolverRBAC(t *testing.T) {

// Helpers for resolver tests

func StartResolverInformers(namespace string, stopCh <-chan struct{}, objs ...runtime.Object) (externalversions.SharedInformerFactory, []cache.InformerSynced) {
func StartResolverInformers(namespace string, stopCh <-chan struct{}, objs ...runtime.Object) (versioned.Interface, externalversions.SharedInformerFactory, []cache.InformerSynced) {
// Create client fakes
clientFake := fake.NewSimpleClientset(objs...)

Expand All @@ -484,7 +485,7 @@ func StartResolverInformers(namespace string, stopCh <-chan struct{}, objs ...ru
panic("failed to wait for caches to sync")
}

return nsInformerFactory, hasSyncedCheckFns
return clientFake, nsInformerFactory, hasSyncedCheckFns
}

func newSub(namespace, pkg, channel string, catalog CatalogKey) *v1alpha1.Subscription {
Expand Down