Skip to content

Commit

Permalink
Fix ClusterOperator selector for excluding copied CSVs.
Browse files Browse the repository at this point in the history
The function that generated the selector had been returning a selector
that matches everything. There was no functional impact because
there's an additional client-side filter that discards objects based
on CSV.IsCopied().

Signed-off-by: Ben Luddy <bluddy@redhat.com>
  • Loading branch information
benluddy committed Jul 16, 2021
1 parent 014bd31 commit 0f58a2c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
6 changes: 1 addition & 5 deletions pkg/controller/operators/openshift/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,7 @@ func notCopiedSelector() (labels.Selector, error) {
if err != nil {
return nil, err
}

selector := labels.NewSelector()
selector.Add(*requirement)

return selector, nil
return labels.NewSelector().Add(*requirement), nil
}

func olmOperatorRelatedObjects(ctx context.Context, cli client.Client, namespace string) ([]configv1.ObjectReference, error) {
Expand Down
23 changes: 23 additions & 0 deletions pkg/controller/operators/openshift/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
configv1 "github.com/openshift/api/config/v1"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
Expand Down Expand Up @@ -602,3 +603,25 @@ func TestMaxOpenShiftVersion(t *testing.T) {
})
}
}

func TestNotCopiedSelector(t *testing.T) {
for _, tc := range []struct {
Labels labels.Set
Matches bool
}{
{
Labels: labels.Set{operatorsv1alpha1.CopiedLabelKey: ""},
Matches: false,
},
{
Labels: labels.Set{},
Matches: true,
},
} {
t.Run(tc.Labels.String(), func(t *testing.T) {
selector, err := notCopiedSelector()
require.NoError(t, err)
require.Equal(t, tc.Matches, selector.Matches(tc.Labels))
})
}
}

0 comments on commit 0f58a2c

Please sign in to comment.