diff --git a/internal/cmd/controller/reconciler/bundle_controller.go b/internal/cmd/controller/reconciler/bundle_controller.go index 7429be9ea2..1459cf3740 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, *fleet.Cluster) ([]*fleet.Bundle, []*fleet.Bundle, error) + BundlesForCluster(context.Context, logr.Logger, *fleet.Cluster) ([]*fleet.Bundle, []*fleet.Bundle, error) } type Store interface { @@ -94,7 +94,8 @@ 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) - bundlesToRefresh, _, err := r.Query.BundlesForCluster(ctx, cluster) + logger := log.FromContext(ctx).WithName("bundle enqueuer") + bundlesToRefresh, _, err := r.Query.BundlesForCluster(ctx, logger, 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 e62d1e0ef4..8ce17b92f3 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, cluster) + _, cleanup, err := r.Query.BundlesForCluster(ctx, logger, 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 497a6254cf..e748e81d7d 100644 --- a/internal/cmd/controller/target/query.go +++ b/internal/cmd/controller/target/query.go @@ -3,7 +3,7 @@ package target import ( "context" - "github.com/sirupsen/logrus" + "github.com/go-logr/logr" "sigs.k8s.io/controller-runtime/pkg/client" fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1" @@ -13,8 +13,8 @@ import ( "k8s.io/apimachinery/pkg/labels" ) -func (m *Manager) BundlesForCluster(ctx context.Context, cluster *fleet.Cluster) (bundlesToRefresh, bundlesToCleanup []*fleet.Bundle, err error) { - bundles, err := m.getBundlesInScopeForCluster(ctx, cluster) +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) if err != nil { return nil, nil, err } @@ -22,11 +22,11 @@ func (m *Manager) BundlesForCluster(ctx context.Context, cluster *fleet.Cluster) for _, bundle := range bundles { bm, err := matcher.New(bundle) if err != nil { - logrus.Errorf("ignore bad app %s/%s: %v", bundle.Namespace, bundle.Name, err) + logger.Error(err, "ignore bad app bundle", "namespace", bundle.Namespace, "name", bundle.Name) continue } - cgs, err := m.clusterGroupsForCluster(ctx, cluster) + cgs, err := m.clusterGroupsForCluster(ctx, logger, cluster) if err != nil { return nil, nil, err } @@ -42,7 +42,7 @@ func (m *Manager) BundlesForCluster(ctx context.Context, cluster *fleet.Cluster) return } -func (m *Manager) getBundlesInScopeForCluster(ctx context.Context, cluster *fleet.Cluster) ([]*fleet.Bundle, error) { +func (m *Manager) getBundlesInScopeForCluster(ctx context.Context, logger logr.Logger, cluster *fleet.Cluster) ([]*fleet.Bundle, error) { bundleSet := newBundleSet() // all bundles in the cluster namespace are in scope @@ -72,7 +72,7 @@ func (m *Manager) getBundlesInScopeForCluster(ctx context.Context, cluster *flee mapping := mapping matcher, err := newBundleMapping(&mapping) if err != nil { - logrus.Errorf("invalid BundleNamespaceMapping %s/%s skipping: %v", mapping.Namespace, mapping.Name, err) + logger.Error(err, "invalid BundleNamespaceMapping, skipping", "namespace", mapping.Namespace, "name", mapping.Name) continue } if !matcher.MatchesNamespace(ctx, m.client, cluster.Namespace) { @@ -86,7 +86,7 @@ func (m *Manager) getBundlesInScopeForCluster(ctx context.Context, cluster *flee return bundleSet.bundles(), nil } -func (m *Manager) clusterGroupsForCluster(ctx context.Context, cluster *fleet.Cluster) (result []*fleet.ClusterGroup, _ error) { +func (m *Manager) clusterGroupsForCluster(ctx context.Context, logger logr.Logger, cluster *fleet.Cluster) (result []*fleet.ClusterGroup, _ error) { cgs := &fleet.ClusterGroupList{} err := m.client.List(ctx, cgs, client.InNamespace(cluster.Namespace)) if err != nil { @@ -100,8 +100,8 @@ func (m *Manager) clusterGroupsForCluster(ctx context.Context, cluster *fleet.Cl } sel, err := metav1.LabelSelectorAsSelector(cg.Spec.Selector) if err != nil { - logrus.Errorf("invalid selector on clusterGroup %s/%s [%v]: %v", cg.Namespace, cg.Name, - cg.Spec.Selector, err) + logger.Error(err, "invalid selector on clusterGroup", "namespace", cg.Namespace, "name", cg.Name, + "selector", cg.Spec.Selector) continue } if sel.Matches(labels.Set(cluster.Labels)) {