Skip to content

Commit 0f58a2c

Browse files
committed
Fix ClusterOperator selector for excluding copied CSVs.
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 <[email protected]>
1 parent 014bd31 commit 0f58a2c

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

pkg/controller/operators/openshift/helpers.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,7 @@ func notCopiedSelector() (labels.Selector, error) {
241241
if err != nil {
242242
return nil, err
243243
}
244-
245-
selector := labels.NewSelector()
246-
selector.Add(*requirement)
247-
248-
return selector, nil
244+
return labels.NewSelector().Add(*requirement), nil
249245
}
250246

251247
func olmOperatorRelatedObjects(ctx context.Context, cli client.Client, namespace string) ([]configv1.ObjectReference, error) {

pkg/controller/operators/openshift/helpers_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
configv1 "github.com/openshift/api/config/v1"
99
"github.com/stretchr/testify/require"
1010
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11+
"k8s.io/apimachinery/pkg/labels"
1112
"k8s.io/apimachinery/pkg/runtime"
1213
"sigs.k8s.io/controller-runtime/pkg/client"
1314
"sigs.k8s.io/controller-runtime/pkg/client/fake"
@@ -602,3 +603,25 @@ func TestMaxOpenShiftVersion(t *testing.T) {
602603
})
603604
}
604605
}
606+
607+
func TestNotCopiedSelector(t *testing.T) {
608+
for _, tc := range []struct {
609+
Labels labels.Set
610+
Matches bool
611+
}{
612+
{
613+
Labels: labels.Set{operatorsv1alpha1.CopiedLabelKey: ""},
614+
Matches: false,
615+
},
616+
{
617+
Labels: labels.Set{},
618+
Matches: true,
619+
},
620+
} {
621+
t.Run(tc.Labels.String(), func(t *testing.T) {
622+
selector, err := notCopiedSelector()
623+
require.NoError(t, err)
624+
require.Equal(t, tc.Matches, selector.Matches(tc.Labels))
625+
})
626+
}
627+
}

0 commit comments

Comments
 (0)