From 14d7f44ab6c7cd6d9af1d9aaa7f42e5660cb0978 Mon Sep 17 00:00:00 2001 From: Mario Manno Date: Wed, 17 Jul 2024 18:24:06 +0200 Subject: [PATCH] fixup! Replace logrus with logger when querying targets --- .../controller/reconciler/bundle_controller.go | 5 ++--- .../controller/reconciler/cluster_controller.go | 2 +- internal/cmd/controller/target/query.go | 17 ++++++++++------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/internal/cmd/controller/reconciler/bundle_controller.go b/internal/cmd/controller/reconciler/bundle_controller.go index 1459cf3740..7429be9ea2 100644 --- a/internal/cmd/controller/reconciler/bundle_controller.go +++ b/internal/cmd/controller/reconciler/bundle_controller.go @@ -36,7 +36,7 @@ const bundleFinalizer = "fleet.cattle.io/bundle-finalizer" type BundleQuery interface { // BundlesForCluster is used to map from a cluster to bundles - BundlesForCluster(context.Context, logr.Logger, *fleet.Cluster) ([]*fleet.Bundle, []*fleet.Bundle, error) + BundlesForCluster(context.Context, *fleet.Cluster) ([]*fleet.Bundle, []*fleet.Bundle, error) } type Store interface { @@ -94,8 +94,7 @@ func (r *BundleReconciler) SetupWithManager(mgr ctrl.Manager) error { &fleet.Cluster{}, handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, a client.Object) []ctrl.Request { cluster := a.(*fleet.Cluster) - logger := log.FromContext(ctx).WithName("bundle enqueuer") - bundlesToRefresh, _, err := r.Query.BundlesForCluster(ctx, logger, cluster) + bundlesToRefresh, _, err := r.Query.BundlesForCluster(ctx, cluster) if err != nil { return nil } diff --git a/internal/cmd/controller/reconciler/cluster_controller.go b/internal/cmd/controller/reconciler/cluster_controller.go index 8ce17b92f3..e62d1e0ef4 100644 --- a/internal/cmd/controller/reconciler/cluster_controller.go +++ b/internal/cmd/controller/reconciler/cluster_controller.go @@ -135,7 +135,7 @@ func (r *ClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct } // Clean up old bundledeployments - _, cleanup, err := r.Query.BundlesForCluster(ctx, logger, cluster) + _, cleanup, err := r.Query.BundlesForCluster(ctx, cluster) if err != nil { return ctrl.Result{}, r.updateErrorStatus(ctx, req.NamespacedName, cluster.Status, err) } diff --git a/internal/cmd/controller/target/query.go b/internal/cmd/controller/target/query.go index e748e81d7d..3a32c0a17e 100644 --- a/internal/cmd/controller/target/query.go +++ b/internal/cmd/controller/target/query.go @@ -3,22 +3,23 @@ package target import ( "context" - "github.com/go-logr/logr" "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/log" + "github.com/rancher/fleet/internal/cmd/controller/target/matcher" fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1" - "github.com/rancher/fleet/internal/cmd/controller/target/matcher" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" ) -func (m *Manager) BundlesForCluster(ctx context.Context, logger logr.Logger, cluster *fleet.Cluster) (bundlesToRefresh, bundlesToCleanup []*fleet.Bundle, err error) { - bundles, err := m.getBundlesInScopeForCluster(ctx, logger, cluster) +func (m *Manager) BundlesForCluster(ctx context.Context, cluster *fleet.Cluster) (bundlesToRefresh, bundlesToCleanup []*fleet.Bundle, err error) { + bundles, err := m.getBundlesInScopeForCluster(ctx, cluster) if err != nil { return nil, nil, err } + logger := log.FromContext(ctx).WithName("target") for _, bundle := range bundles { bm, err := matcher.New(bundle) if err != nil { @@ -26,7 +27,7 @@ func (m *Manager) BundlesForCluster(ctx context.Context, logger logr.Logger, clu continue } - cgs, err := m.clusterGroupsForCluster(ctx, logger, cluster) + cgs, err := m.clusterGroupsForCluster(ctx, cluster) if err != nil { return nil, nil, err } @@ -42,7 +43,7 @@ func (m *Manager) BundlesForCluster(ctx context.Context, logger logr.Logger, clu return } -func (m *Manager) getBundlesInScopeForCluster(ctx context.Context, logger logr.Logger, cluster *fleet.Cluster) ([]*fleet.Bundle, error) { +func (m *Manager) getBundlesInScopeForCluster(ctx context.Context, cluster *fleet.Cluster) ([]*fleet.Bundle, error) { bundleSet := newBundleSet() // all bundles in the cluster namespace are in scope @@ -68,6 +69,7 @@ func (m *Manager) getBundlesInScopeForCluster(ctx context.Context, logger logr.L return nil, err } + logger := log.FromContext(ctx).WithName("target") for _, mapping := range mappings.Items { mapping := mapping matcher, err := newBundleMapping(&mapping) @@ -86,13 +88,14 @@ func (m *Manager) getBundlesInScopeForCluster(ctx context.Context, logger logr.L return bundleSet.bundles(), nil } -func (m *Manager) clusterGroupsForCluster(ctx context.Context, logger logr.Logger, cluster *fleet.Cluster) (result []*fleet.ClusterGroup, _ error) { +func (m *Manager) clusterGroupsForCluster(ctx context.Context, cluster *fleet.Cluster) (result []*fleet.ClusterGroup, _ error) { cgs := &fleet.ClusterGroupList{} err := m.client.List(ctx, cgs, client.InNamespace(cluster.Namespace)) if err != nil { return nil, err } + logger := log.FromContext(ctx).WithName("target") for _, cg := range cgs.Items { cg := cg if cg.Spec.Selector == nil {