Skip to content

Commit 03302ff

Browse files
olm/manager: don't use a global label selector
Signed-off-by: Steve Kuznetsov <[email protected]>
1 parent 30f2150 commit 03302ff

File tree

2 files changed

+57
-26
lines changed

2 files changed

+57
-26
lines changed

cmd/olm/manager.go

+35-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@ package main
33
import (
44
"context"
55

6+
appsv1 "k8s.io/api/apps/v1"
7+
corev1 "k8s.io/api/core/v1"
8+
rbacv1 "k8s.io/api/rbac/v1"
9+
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
610
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
711
"k8s.io/apimachinery/pkg/labels"
812
"k8s.io/apimachinery/pkg/runtime"
913
"k8s.io/apimachinery/pkg/selection"
14+
apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"
1015
ctrl "sigs.k8s.io/controller-runtime"
1116
"sigs.k8s.io/controller-runtime/pkg/cache"
1217
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -51,8 +56,37 @@ func Manager(ctx context.Context, debug bool) (ctrl.Manager, error) {
5156
Scheme: scheme,
5257
MetricsBindAddress: "0", // TODO(njhale): Enable metrics on non-conflicting port (not 8080)
5358
Cache: cache.Options{
54-
DefaultLabelSelector: labels.SelectorFromValidatedSet(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue}),
5559
ByObject: map[client.Object]cache.ByObject{
60+
&appsv1.Deployment{}: {
61+
Label: labels.SelectorFromValidatedSet(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue}),
62+
},
63+
&corev1.Service{}: {
64+
Label: labels.SelectorFromValidatedSet(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue}),
65+
},
66+
&apiextensionsv1.CustomResourceDefinition{}: {
67+
Label: labels.SelectorFromValidatedSet(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue}),
68+
},
69+
&apiregistrationv1.APIService{}: {
70+
Label: labels.SelectorFromValidatedSet(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue}),
71+
},
72+
&corev1.ConfigMap{}: {
73+
Label: labels.SelectorFromValidatedSet(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue}),
74+
},
75+
&corev1.ServiceAccount{}: {
76+
Label: labels.SelectorFromValidatedSet(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue}),
77+
},
78+
&rbacv1.Role{}: {
79+
Label: labels.SelectorFromValidatedSet(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue}),
80+
},
81+
&rbacv1.RoleBinding{}: {
82+
Label: labels.SelectorFromValidatedSet(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue}),
83+
},
84+
&rbacv1.ClusterRole{}: {
85+
Label: labels.SelectorFromValidatedSet(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue}),
86+
},
87+
&rbacv1.ClusterRoleBinding{}: {
88+
Label: labels.SelectorFromValidatedSet(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue}),
89+
},
5690
&operatorsv1alpha1.ClusterServiceVersion{}: {
5791
Label: copiedLabelDoesNotExist,
5892
},

test/e2e/operator_test.go

+22-25
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/onsi/gomega/format"
1212
gomegatypes "github.com/onsi/gomega/types"
1313
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
14+
"github.com/stretchr/testify/require"
1415
corev1 "k8s.io/api/core/v1"
1516
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1617
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -266,20 +267,22 @@ var _ = Describe("Operator API", func() {
266267
)
267268

268269
BeforeEach(func() {
269-
// Subscribe to a package and await a successful install
270+
By("Subscribe to a package and await a successful install")
270271
ns = &corev1.Namespace{}
271272
ns.SetName(genName("ns-"))
272273
Eventually(func() error {
273274
return client.Create(clientCtx, ns)
274275
}).Should(Succeed())
276+
By(fmt.Sprintf("created namespace %s", ns.Name))
275277

276-
// Default to AllNamespaces
278+
By("Default to AllNamespaces")
277279
og := &operatorsv1.OperatorGroup{}
278280
og.SetNamespace(ns.GetName())
279281
og.SetName(genName("og-"))
280282
Eventually(func() error {
281283
return client.Create(clientCtx, og)
282284
}).Should(Succeed())
285+
By(fmt.Sprintf("created operator group %s/%s", og.Namespace, og.Name))
283286

284287
cs := &operatorsv1alpha1.CatalogSource{
285288
Spec: operatorsv1alpha1.CatalogSourceSpec{
@@ -295,8 +298,9 @@ var _ = Describe("Operator API", func() {
295298
Eventually(func() error {
296299
return client.Create(clientCtx, cs)
297300
}).Should(Succeed())
301+
By(fmt.Sprintf("created catalog source %s/%s", cs.Namespace, cs.Name))
298302

299-
// Wait for the CatalogSource to be ready
303+
By("Wait for the CatalogSource to be ready")
300304
_, err := fetchCatalogSourceOnStatus(newCRClient(), cs.GetName(), cs.GetNamespace(), catalogSourceRegistryPodSynced())
301305
Expect(err).ToNot(HaveOccurred())
302306

@@ -314,38 +318,31 @@ var _ = Describe("Operator API", func() {
314318
Eventually(func() error {
315319
return client.Create(clientCtx, sub)
316320
}).Should(Succeed())
321+
By(fmt.Sprintf("created subscription %s/%s", sub.Namespace, sub.Name))
317322

318-
Eventually(func() (operatorsv1alpha1.SubscriptionState, error) {
319-
s := sub.DeepCopy()
320-
if err := client.Get(clientCtx, testobj.NamespacedName(s), s); err != nil {
321-
return operatorsv1alpha1.SubscriptionStateNone, err
322-
}
323-
324-
return s.Status.State, nil
325-
}).Should(BeEquivalentTo(operatorsv1alpha1.SubscriptionStateAtLatest))
323+
_, err = fetchSubscription(newCRClient(), sub.Namespace, sub.Name, subscriptionStateAtLatestChecker())
324+
require.NoError(GinkgoT(), err)
326325

327-
var ipRef *corev1.ObjectReference
328-
Eventually(func() (*corev1.ObjectReference, error) {
329-
if err := client.Get(clientCtx, testobj.NamespacedName(sub), sub); err != nil {
330-
return nil, err
331-
}
332-
ipRef = sub.Status.InstallPlanRef
326+
subscriptionWithInstallPLan, err := fetchSubscription(newCRClient(), sub.Namespace, sub.Name, subscriptionHasInstallPlanChecker())
327+
require.NoError(GinkgoT(), err)
328+
require.NotNil(GinkgoT(), subscriptionWithInstallPLan)
329+
ipRef := subscriptionWithInstallPLan.Status.InstallPlanRef
333330

334-
return ipRef, nil
335-
}).ShouldNot(BeNil())
336-
337-
ip = &operatorsv1alpha1.InstallPlan{}
338-
Eventually(func() error {
339-
return client.Get(clientCtx, types.NamespacedName{Namespace: ipRef.Namespace, Name: ipRef.Name}, ip)
340-
}).Should(Succeed())
331+
ip, err = fetchInstallPlan(GinkgoT(), newCRClient(), ipRef.Name, ipRef.Namespace, buildInstallPlanPhaseCheckFunc(operatorsv1alpha1.InstallPlanPhaseComplete))
332+
Expect(err).To(BeNil())
341333

342334
operator, err := operatorFactory.NewPackageOperator(sub.Spec.Package, sub.GetNamespace())
343335
Expect(err).ToNot(HaveOccurred())
344336
operatorName = testobj.NamespacedName(operator)
337+
By(fmt.Sprintf("waiting for operator %s/%s to exist", operator.Namespace, operator.Name))
345338
})
346339

347340
AfterEach(func() {
348341
Eventually(func() error {
342+
if env := os.Getenv("SKIP_CLEANUP"); env != "" {
343+
fmt.Printf("Skipping cleanup of namespace %s...\n", ns.Name)
344+
return nil
345+
}
349346
err := client.Delete(clientCtx, ns)
350347
if apierrors.IsNotFound(err) {
351348
return nil
@@ -386,7 +383,7 @@ var _ = Describe("Operator API", func() {
386383
var newNs *corev1.Namespace
387384

388385
BeforeEach(func() {
389-
// Subscribe to a package and await a successful install
386+
By("Subscribe to a package and await a successful install")
390387
newNs = &corev1.Namespace{}
391388
newNs.SetName(genName("ns-"))
392389
Eventually(func() error {

0 commit comments

Comments
 (0)