Skip to content

Commit

Permalink
Merge pull request #5151 from killianmuldoon/add-reconciler-to-logs
Browse files Browse the repository at this point in the history
🌱 Add reconciler name to loggers for context
  • Loading branch information
k8s-ci-robot authored Aug 26, 2021
2 parents 9c92a8d + fb4569a commit b0e4c8b
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 2 deletions.
2 changes: 2 additions & 0 deletions bootstrap/kubeadm/controllers/kubeadmconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ type Scope struct {

// SetupWithManager sets up the reconciler with the Manager.
func (r *KubeadmConfigReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, option controller.Options) error {
option.Log = mgr.GetLogger().WithValues("KubeadmConfig")

if r.KubeadmInitLock == nil {
r.KubeadmInitLock = locking.NewControlPlaneInitMutex(ctrl.LoggerFrom(ctx).WithName("init-locker"), mgr.GetClient())
}
Expand Down
2 changes: 2 additions & 0 deletions controllers/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ type ClusterReconciler struct {
}

func (r *ClusterReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
options.Log = mgr.GetLogger().WithValues("Cluster")

controller, err := ctrl.NewControllerManagedBy(mgr).
For(&clusterv1.Cluster{}).
Watches(
Expand Down
2 changes: 2 additions & 0 deletions controllers/machine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ type MachineReconciler struct {
}

func (r *MachineReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
options.Log = mgr.GetLogger().WithValues("Machine")

clusterToMachines, err := util.ClusterToObjectsMapper(mgr.GetClient(), &clusterv1.MachineList{}, mgr.GetScheme())
if err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions controllers/machinedeployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ type MachineDeploymentReconciler struct {
}

func (r *MachineDeploymentReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
options.Log = mgr.GetLogger().WithValues("MachineDeployment")

clusterToMachineDeployments, err := util.ClusterToObjectsMapper(mgr.GetClient(), &clusterv1.MachineDeploymentList{}, mgr.GetScheme())
if err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions controllers/machinehealthcheck_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ type MachineHealthCheckReconciler struct {
}

func (r *MachineHealthCheckReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
options.Log = mgr.GetLogger().WithValues("MachineHealthCheck")

controller, err := ctrl.NewControllerManagedBy(mgr).
For(&clusterv1.MachineHealthCheck{}).
Watches(
Expand Down
2 changes: 2 additions & 0 deletions controllers/machineset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ type MachineSetReconciler struct {
}

func (r *MachineSetReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
options.Log = mgr.GetLogger().WithValues("MachineSet")

clusterToMachineSets, err := util.ClusterToObjectsMapper(mgr.GetClient(), &clusterv1.MachineSetList{}, mgr.GetScheme())
if err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions controllers/remote/cluster_cache_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ type ClusterCacheReconciler struct {
}

func (r *ClusterCacheReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
options.Log = mgr.GetLogger().WithValues("ClusterCache")

_, err := ctrl.NewControllerManagedBy(mgr).
For(&clusterv1.Cluster{}).
WithOptions(options).
Expand Down
2 changes: 2 additions & 0 deletions controlplane/kubeadm/controllers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ type KubeadmControlPlaneReconciler struct {
}

func (r *KubeadmControlPlaneReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
options.Log = mgr.GetLogger().WithValues("KubeadmControlPlane")

c, err := ctrl.NewControllerManagedBy(mgr).
For(&controlplanev1.KubeadmControlPlane{}).
Owns(&clusterv1.Machine{}).
Expand Down
2 changes: 2 additions & 0 deletions exp/addons/controllers/clusterresourceset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ type ClusterResourceSetReconciler struct {
}

func (r *ClusterResourceSetReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
options.Log = mgr.GetLogger().WithValues("ClusterResourceSet")

err := ctrl.NewControllerManagedBy(mgr).
For(&addonsv1.ClusterResourceSet{}).
Watches(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ type ClusterResourceSetBindingReconciler struct {
}

func (r *ClusterResourceSetBindingReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
options.Log = mgr.GetLogger().WithValues("ClusterResourceSetBinding")

_, err := ctrl.NewControllerManagedBy(mgr).
For(&addonsv1.ClusterResourceSetBinding{}).
Watches(
Expand Down
2 changes: 2 additions & 0 deletions exp/controllers/machinepool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ type MachinePoolReconciler struct {
}

func (r *MachinePoolReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
options.Log = mgr.GetLogger().WithValues("MachinePool")

clusterToMachinePools, err := util.ClusterToObjectsMapper(mgr.GetClient(), &expv1.MachinePoolList{}, mgr.GetScheme())
if err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ package controllers
import (
"context"

"sigs.k8s.io/controller-runtime/pkg/controller"

"github.com/go-logr/logr"
"github.com/pkg/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -186,7 +188,8 @@ func (r *DockerClusterReconciler) reconcileDelete(ctx context.Context, dockerClu
}

// SetupWithManager will add watches for this controller.
func (r *DockerClusterReconciler) SetupWithManager(mgr ctrl.Manager) error {
func (r *DockerClusterReconciler) SetupWithManager(mgr ctrl.Manager, options controller.Options) error {
options.Log = mgr.GetLogger().WithValues("DockerCluster")
c, err := ctrl.NewControllerManagedBy(mgr).
For(&infrav1.DockerCluster{}).
WithEventFilter(predicates.ResourceNotPaused(r.Log)).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ func (r *DockerMachineReconciler) reconcileDelete(ctx context.Context, machine *

// SetupWithManager will add watches for this controller.
func (r *DockerMachineReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
options.Log = mgr.GetLogger().WithValues("DockerMachine")

clusterToDockerMachines, err := util.ClusterToObjectsMapper(mgr.GetClient(), &infrav1.DockerMachineList{}, mgr.GetScheme())
if err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ func (r *DockerMachinePoolReconciler) Reconcile(ctx context.Context, req ctrl.Re

// SetupWithManager will add watches for this controller.
func (r *DockerMachinePoolReconciler) SetupWithManager(mgr ctrl.Manager, options controller.Options) error {
options.Log = mgr.GetLogger().WithValues("DockerMachinePool")

clusterToDockerMachinePools, err := util.ClusterToObjectsMapper(mgr.GetClient(), &infrav1exp.DockerMachinePoolList{}, mgr.GetScheme())
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion test/infrastructure/docker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
if err := (&controllers.DockerClusterReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("DockerCluster"),
}).SetupWithManager(mgr); err != nil {
}).SetupWithManager(mgr, controller.Options{}); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "DockerCluster")
os.Exit(1)
}
Expand Down

0 comments on commit b0e4c8b

Please sign in to comment.