From 355219318fbc8685ca42ec0a5bb1bd9dcf086289 Mon Sep 17 00:00:00 2001 From: Steve Kuznetsov Date: Tue, 3 Oct 2023 09:23:06 -0600 Subject: [PATCH] olm/manager: don't use a global label selector Signed-off-by: Steve Kuznetsov --- cmd/olm/manager.go | 36 +++++++++++++++++++++++++++++- test/e2e/operator_test.go | 47 ++++++++++++++++++--------------------- 2 files changed, 57 insertions(+), 26 deletions(-) diff --git a/cmd/olm/manager.go b/cmd/olm/manager.go index 953b2ad306..dbb6d0d222 100644 --- a/cmd/olm/manager.go +++ b/cmd/olm/manager.go @@ -3,10 +3,15 @@ package main import ( "context" + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" + rbacv1 "k8s.io/api/rbac/v1" + apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/selection" + apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/cache" "sigs.k8s.io/controller-runtime/pkg/client" @@ -51,8 +56,37 @@ func Manager(ctx context.Context, debug bool) (ctrl.Manager, error) { Scheme: scheme, MetricsBindAddress: "0", // TODO(njhale): Enable metrics on non-conflicting port (not 8080) Cache: cache.Options{ - DefaultLabelSelector: labels.SelectorFromValidatedSet(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue}), ByObject: map[client.Object]cache.ByObject{ + &appsv1.Deployment{}: { + Label: labels.SelectorFromValidatedSet(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue}), + }, + &corev1.Service{}: { + Label: labels.SelectorFromValidatedSet(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue}), + }, + &apiextensionsv1.CustomResourceDefinition{}: { + Label: labels.SelectorFromValidatedSet(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue}), + }, + &apiregistrationv1.APIService{}: { + Label: labels.SelectorFromValidatedSet(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue}), + }, + &corev1.ConfigMap{}: { + Label: labels.SelectorFromValidatedSet(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue}), + }, + &corev1.ServiceAccount{}: { + Label: labels.SelectorFromValidatedSet(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue}), + }, + &rbacv1.Role{}: { + Label: labels.SelectorFromValidatedSet(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue}), + }, + &rbacv1.RoleBinding{}: { + Label: labels.SelectorFromValidatedSet(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue}), + }, + &rbacv1.ClusterRole{}: { + Label: labels.SelectorFromValidatedSet(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue}), + }, + &rbacv1.ClusterRoleBinding{}: { + Label: labels.SelectorFromValidatedSet(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue}), + }, &operatorsv1alpha1.ClusterServiceVersion{}: { Label: copiedLabelDoesNotExist, }, diff --git a/test/e2e/operator_test.go b/test/e2e/operator_test.go index 0ffa06bc10..90caea0f1f 100644 --- a/test/e2e/operator_test.go +++ b/test/e2e/operator_test.go @@ -11,6 +11,7 @@ import ( "github.com/onsi/gomega/format" gomegatypes "github.com/onsi/gomega/types" "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install" + "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -266,20 +267,22 @@ var _ = Describe("Operator API", func() { ) BeforeEach(func() { - // Subscribe to a package and await a successful install + By("Subscribe to a package and await a successful install") ns = &corev1.Namespace{} ns.SetName(genName("ns-")) Eventually(func() error { return client.Create(clientCtx, ns) }).Should(Succeed()) + By(fmt.Sprintf("created namespace %s", ns.Name)) - // Default to AllNamespaces + By("Default to AllNamespaces") og := &operatorsv1.OperatorGroup{} og.SetNamespace(ns.GetName()) og.SetName(genName("og-")) Eventually(func() error { return client.Create(clientCtx, og) }).Should(Succeed()) + By(fmt.Sprintf("created operator group %s/%s", og.Namespace, og.Name)) cs := &operatorsv1alpha1.CatalogSource{ Spec: operatorsv1alpha1.CatalogSourceSpec{ @@ -295,8 +298,9 @@ var _ = Describe("Operator API", func() { Eventually(func() error { return client.Create(clientCtx, cs) }).Should(Succeed()) + By(fmt.Sprintf("created catalog source %s/%s", cs.Namespace, cs.Name)) - // Wait for the CatalogSource to be ready + By("Wait for the CatalogSource to be ready") _, err := fetchCatalogSourceOnStatus(newCRClient(), cs.GetName(), cs.GetNamespace(), catalogSourceRegistryPodSynced()) Expect(err).ToNot(HaveOccurred()) @@ -314,38 +318,31 @@ var _ = Describe("Operator API", func() { Eventually(func() error { return client.Create(clientCtx, sub) }).Should(Succeed()) + By(fmt.Sprintf("created subscription %s/%s", sub.Namespace, sub.Name)) - Eventually(func() (operatorsv1alpha1.SubscriptionState, error) { - s := sub.DeepCopy() - if err := client.Get(clientCtx, testobj.NamespacedName(s), s); err != nil { - return operatorsv1alpha1.SubscriptionStateNone, err - } - - return s.Status.State, nil - }).Should(BeEquivalentTo(operatorsv1alpha1.SubscriptionStateAtLatest)) + _, err = fetchSubscription(newCRClient(), sub.Namespace, sub.Name, subscriptionStateAtLatestChecker()) + require.NoError(GinkgoT(), err) - var ipRef *corev1.ObjectReference - Eventually(func() (*corev1.ObjectReference, error) { - if err := client.Get(clientCtx, testobj.NamespacedName(sub), sub); err != nil { - return nil, err - } - ipRef = sub.Status.InstallPlanRef + subscriptionWithInstallPLan, err := fetchSubscription(newCRClient(), sub.Namespace, sub.Name, subscriptionHasInstallPlanChecker()) + require.NoError(GinkgoT(), err) + require.NotNil(GinkgoT(), subscriptionWithInstallPLan) + ipRef := subscriptionWithInstallPLan.Status.InstallPlanRef - return ipRef, nil - }).ShouldNot(BeNil()) - - ip = &operatorsv1alpha1.InstallPlan{} - Eventually(func() error { - return client.Get(clientCtx, types.NamespacedName{Namespace: ipRef.Namespace, Name: ipRef.Name}, ip) - }).Should(Succeed()) + ip, err = fetchInstallPlan(GinkgoT(), newCRClient(), ipRef.Name, ipRef.Namespace, buildInstallPlanPhaseCheckFunc(operatorsv1alpha1.InstallPlanPhaseComplete)) + Expect(err).To(BeNil()) operator, err := operatorFactory.NewPackageOperator(sub.Spec.Package, sub.GetNamespace()) Expect(err).ToNot(HaveOccurred()) operatorName = testobj.NamespacedName(operator) + By(fmt.Sprintf("waiting for operator %s/%s to exist", operator.Namespace, operator.Name)) }) AfterEach(func() { Eventually(func() error { + if env := os.Getenv("SKIP_CLEANUP"); env != "" { + fmt.Printf("Skipping cleanup of namespace %s...\n", ns.Name) + return nil + } err := client.Delete(clientCtx, ns) if apierrors.IsNotFound(err) { return nil @@ -386,7 +383,7 @@ var _ = Describe("Operator API", func() { var newNs *corev1.Namespace BeforeEach(func() { - // Subscribe to a package and await a successful install + By("Subscribe to a package and await a successful install") newNs = &corev1.Namespace{} newNs.SetName(genName("ns-")) Eventually(func() error {