Skip to content

Commit

Permalink
Removes error silencing from IsFailForwardEnabled
Browse files Browse the repository at this point in the history
Signed-off-by: Mikalai Radchuk <mradchuk@redhat.com>
  • Loading branch information
m1kola committed Apr 26, 2023
1 parent cf13b77 commit c682d1a
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 7 deletions.
12 changes: 10 additions & 2 deletions pkg/controller/operators/catalog/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,12 @@ func TestSyncResolvingNamespace(t *testing.T) {
clockFake := utilclocktesting.NewFakeClock(time.Date(2018, time.January, 26, 20, 40, 0, 0, time.UTC))
now := metav1.NewTime(clockFake.Now())
testNamespace := "testNamespace"
og := &operatorsv1.OperatorGroup{
ObjectMeta: metav1.ObjectMeta{
Name: "og",
Namespace: testNamespace,
},
}

type fields struct {
clientOptions []clientfake.Option
Expand Down Expand Up @@ -1319,7 +1325,7 @@ func TestSyncResolvingNamespace(t *testing.T) {
ctx, cancel := context.WithCancel(context.TODO())
defer cancel()

o, err := NewFakeOperator(ctx, testNamespace, []string{testNamespace}, withClock(clockFake), withClientObjs(tt.fields.existingOLMObjs...), withFakeClientOptions(tt.fields.clientOptions...))
o, err := NewFakeOperator(ctx, testNamespace, []string{testNamespace}, withClock(clockFake), withClientObjs(append(tt.fields.existingOLMObjs, og)...), withFakeClientOptions(tt.fields.clientOptions...))
require.NoError(t, err)

o.reconciler = &fakes.FakeRegistryReconcilerFactory{
Expand Down Expand Up @@ -1669,12 +1675,14 @@ func NewFakeOperator(ctx context.Context, namespace string, namespaces []string,
subInformer := operatorsFactory.Operators().V1alpha1().Subscriptions()
ipInformer := operatorsFactory.Operators().V1alpha1().InstallPlans()
csvInformer := operatorsFactory.Operators().V1alpha1().ClusterServiceVersions()
sharedInformers = append(sharedInformers, catsrcInformer.Informer(), subInformer.Informer(), ipInformer.Informer(), csvInformer.Informer())
ogInformer := operatorsFactory.Operators().V1().OperatorGroups()
sharedInformers = append(sharedInformers, catsrcInformer.Informer(), subInformer.Informer(), ipInformer.Informer(), csvInformer.Informer(), ogInformer.Informer())

lister.OperatorsV1alpha1().RegisterCatalogSourceLister(metav1.NamespaceAll, catsrcInformer.Lister())
lister.OperatorsV1alpha1().RegisterSubscriptionLister(metav1.NamespaceAll, subInformer.Lister())
lister.OperatorsV1alpha1().RegisterInstallPlanLister(metav1.NamespaceAll, ipInformer.Lister())
lister.OperatorsV1alpha1().RegisterClusterServiceVersionLister(metav1.NamespaceAll, csvInformer.Lister())
lister.OperatorsV1().RegisterOperatorGroupLister(metav1.NamespaceAll, ogInformer.Lister())

factory := informers.NewSharedInformerFactoryWithOptions(opClientFake.KubernetesInterface(), wakeupInterval, informers.WithNamespace(metav1.NamespaceAll))
roleInformer := factory.Rbac().V1().Roles()
Expand Down
9 changes: 8 additions & 1 deletion pkg/controller/operators/catalog/subscriptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
utilclocktesting "k8s.io/utils/clock/testing"

operatorsv1 "github.com/operator-framework/api/pkg/operators/v1"
"github.com/operator-framework/api/pkg/operators/v1alpha1"
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/reconciler"
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver"
Expand All @@ -23,6 +24,12 @@ func TestSyncSubscriptions(t *testing.T) {
clockFake := utilclocktesting.NewFakeClock(time.Date(2018, time.January, 26, 20, 40, 0, 0, time.UTC))
now := metav1.NewTime(clockFake.Now())
testNamespace := "testNamespace"
og := &operatorsv1.OperatorGroup{
ObjectMeta: metav1.ObjectMeta{
Name: "og",
Namespace: testNamespace,
},
}

type fields struct {
clientOptions []clientfake.Option
Expand Down Expand Up @@ -1013,7 +1020,7 @@ func TestSyncSubscriptions(t *testing.T) {
ctx, cancel := context.WithCancel(context.TODO())
defer cancel()

o, err := NewFakeOperator(ctx, testNamespace, []string{testNamespace}, withClock(clockFake), withClientObjs(tt.fields.existingOLMObjs...), withFakeClientOptions(tt.fields.clientOptions...))
o, err := NewFakeOperator(ctx, testNamespace, []string{testNamespace}, withClock(clockFake), withClientObjs(append(tt.fields.existingOLMObjs, og)...), withFakeClientOptions(tt.fields.clientOptions...))
require.NoError(t, err)

o.reconciler = &fakes.FakeRegistryReconcilerFactory{
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/registry/resolver/fail_forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
// backwards compatible.
func IsFailForwardEnabled(ogLister v1listers.OperatorGroupNamespaceLister) (bool, error) {
ogs, err := ogLister.List(labels.Everything())
if err != nil || len(ogs) == 0 {
return false, nil
if err != nil {
return false, err
}
if len(ogs) != 1 {
return false, fmt.Errorf("found %d operatorGroups, expected 1", len(ogs))
Expand Down
10 changes: 9 additions & 1 deletion pkg/controller/registry/resolver/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import (
"github.com/sirupsen/logrus/hooks/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/operator-framework/api/pkg/constraints"
operatorsv1 "github.com/operator-framework/api/pkg/operators/v1"
"github.com/operator-framework/api/pkg/operators/v1alpha1"
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/cache"
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/solver"
Expand Down Expand Up @@ -1373,6 +1375,12 @@ func TestSolveOperators_TransferApiOwnership(t *testing.T) {

namespace := "olm"
catalog := cache.SourceKey{Name: "community", Namespace: namespace}
og := &operatorsv1.OperatorGroup{
ObjectMeta: metav1.ObjectMeta{
Name: "og",
Namespace: namespace,
},
}

phases := []struct {
subs []*v1alpha1.Subscription
Expand Down Expand Up @@ -1442,7 +1450,7 @@ func TestSolveOperators_TransferApiOwnership(t *testing.T) {
key: cache.NewVirtualSourceKey(namespace),
csvLister: &csvs,
subLister: fakeSubscriptionLister(p.subs),
ogLister: fakeOperatorGroupLister{},
ogLister: fakeOperatorGroupLister{og},
logger: logger,
},
}),
Expand Down
8 changes: 7 additions & 1 deletion pkg/controller/registry/resolver/source_csvs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,12 @@ func (f fakeOperatorGroupLister) Get(name string) (*operatorsv1.OperatorGroup, e
}

func TestPropertiesAnnotationHonored(t *testing.T) {
og := &operatorsv1.OperatorGroup{
ObjectMeta: metav1.ObjectMeta{
Name: "og",
Namespace: "fake-ns",
},
}
src := &csvSource{
csvLister: fakeCSVLister{
&v1alpha1.ClusterServiceVersion{
Expand All @@ -478,7 +484,7 @@ func TestPropertiesAnnotationHonored(t *testing.T) {
},
},
subLister: fakeSubscriptionLister{},
ogLister: fakeOperatorGroupLister{},
ogLister: fakeOperatorGroupLister{og},
}
ss, err := src.Snapshot(context.Background())
require.NoError(t, err)
Expand Down
Loading

0 comments on commit c682d1a

Please sign in to comment.