Skip to content

Commit

Permalink
Improve log k/v pairs, consistent event recorder names
Browse files Browse the repository at this point in the history
  • Loading branch information
sbueringer committed Dec 6, 2023
1 parent f330c6e commit bd2a6e1
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,6 @@ func (r *KubeadmConfigReconciler) Reconcile(ctx context.Context, req ctrl.Reques
return ctrl.Result{}, err
}

// AddOwners adds the owners of KubeadmConfig as k/v pairs to the logger.
// Specifically, it will add KubeadmControlPlane, MachineSet and MachineDeployment.
ctx, log, err := clog.AddOwners(ctx, r.Client, config)
if err != nil {
return ctrl.Result{}, err
}

// Look up the owner of this kubeadm config if there is one
configOwner, err := bsutil.GetTypedConfigOwner(ctx, r.Client, config)
if apierrors.IsNotFound(err) {
Expand All @@ -173,6 +166,15 @@ func (r *KubeadmConfigReconciler) Reconcile(ctx context.Context, req ctrl.Reques
}
log = log.WithValues(configOwner.GetKind(), klog.KRef(configOwner.GetNamespace(), configOwner.GetName()), "resourceVersion", configOwner.GetResourceVersion())

if configOwner.GetKind() == "Machine" {
// AddOwners adds the owners of Machine as k/v pairs to the logger.
// Specifically, it will add KubeadmControlPlane, MachineSet and MachineDeployment.
ctx, log, err = clog.AddOwners(ctx, r.Client, configOwner)
if err != nil {
return ctrl.Result{}, err
}
}

log = log.WithValues("Cluster", klog.KRef(configOwner.GetNamespace(), configOwner.ClusterName()))
ctx = ctrl.LoggerInto(ctx, log)

Expand Down
2 changes: 1 addition & 1 deletion bootstrap/kubeadm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {

// Set up a ClusterCacheTracker and ClusterCacheReconciler to provide to controllers
// requiring a connection to a remote cluster
log := ctrl.Log.WithName("remote").WithName("ClusterCacheTracker")
log := ctrl.Log.WithValues("component", "remote/clustercachetracker")
tracker, err := remote.NewClusterCacheTracker(
mgr,
remote.ClusterCacheTrackerOptions{
Expand Down
2 changes: 1 addition & 1 deletion controlplane/kubeadm/internal/controllers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (r *KubeadmControlPlaneReconciler) SetupWithManager(ctx context.Context, mg
}

r.controller = c
r.recorder = mgr.GetEventRecorderFor("kubeadm-control-plane-controller")
r.recorder = mgr.GetEventRecorderFor("kubeadmcontrolplane-controller")
r.ssaCache = ssa.NewCache()

if r.managementCluster == nil {
Expand Down
2 changes: 1 addition & 1 deletion controlplane/kubeadm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {

// Set up a ClusterCacheTracker to provide to controllers
// requiring a connection to a remote cluster
log := ctrl.Log.WithName("remote").WithName("ClusterCacheTracker")
log := ctrl.Log.WithValues("component", "remote/clustercachetracker")
tracker, err := remote.NewClusterCacheTracker(mgr, remote.ClusterCacheTrackerOptions{
SecretCachingClient: secretCachingClient,
ControllerName: controllerName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func InitFlags(fs *pflag.FlagSet) {

func main() {
// Creates a logger to be used during the main func.
setupLog := ctrl.Log.WithName("main")
setupLog := ctrl.Log.WithName("setup")

// Initialize and parse command line flags.
InitFlags(pflag.CommandLine)
Expand Down
2 changes: 1 addition & 1 deletion internal/controllers/cluster/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestMain(m *testing.M) {
setupReconcilers := func(ctx context.Context, mgr ctrl.Manager) {
// Set up a ClusterCacheTracker and ClusterCacheReconciler to provide to controllers
// requiring a connection to a remote cluster
log := ctrl.Log.WithName("remote").WithName("ClusterCacheTracker")
log := ctrl.Log.WithValues("component", "remote/clustercachetracker")
tracker, err := remote.NewClusterCacheTracker(
mgr,
remote.ClusterCacheTrackerOptions{
Expand Down
2 changes: 1 addition & 1 deletion internal/controllers/machine/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestMain(m *testing.M) {
setupReconcilers := func(ctx context.Context, mgr ctrl.Manager) {
// Set up a ClusterCacheTracker and ClusterCacheReconciler to provide to controllers
// requiring a connection to a remote cluster
log := ctrl.Log.WithName("remote").WithName("ClusterCacheTracker")
log := ctrl.Log.WithValues("component", "remote/clustercachetracker")
tracker, err := remote.NewClusterCacheTracker(
mgr,
remote.ClusterCacheTrackerOptions{
Expand Down
2 changes: 1 addition & 1 deletion internal/controllers/machinedeployment/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestMain(m *testing.M) {
setupReconcilers := func(ctx context.Context, mgr ctrl.Manager) {
// Set up a ClusterCacheTracker and ClusterCacheReconciler to provide to controllers
// requiring a connection to a remote cluster
log := ctrl.Log.WithName("remote").WithName("ClusterCacheTracker")
log := ctrl.Log.WithValues("component", "remote/clustercachetracker")
tracker, err := remote.NewClusterCacheTracker(
mgr,
remote.ClusterCacheTrackerOptions{
Expand Down
2 changes: 1 addition & 1 deletion internal/controllers/machinehealthcheck/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestMain(m *testing.M) {
setupReconcilers := func(ctx context.Context, mgr ctrl.Manager) {
// Set up a ClusterCacheTracker and ClusterCacheReconciler to provide to controllers
// requiring a connection to a remote cluster
log := ctrl.Log.WithName("remote").WithName("ClusterCacheTracker")
log := ctrl.Log.WithValues("component", "remote/clustercachetracker")
tracker, err := remote.NewClusterCacheTracker(
mgr,
remote.ClusterCacheTrackerOptions{
Expand Down
2 changes: 1 addition & 1 deletion internal/controllers/machineset/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestMain(m *testing.M) {
setupReconcilers := func(ctx context.Context, mgr ctrl.Manager) {
// Set up a ClusterCacheTracker and ClusterCacheReconciler to provide to controllers
// requiring a connection to a remote cluster
log := ctrl.Log.WithName("remote").WithName("ClusterCacheTracker")
log := ctrl.Log.WithValues("component", "remote/clustercachetracker")
tracker, err := remote.NewClusterCacheTracker(
mgr,
remote.ClusterCacheTrackerOptions{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
Cache: mgr.GetCache(),
}
r.patchEngine = patches.NewEngine(r.RuntimeClient)
r.recorder = mgr.GetEventRecorderFor("topology/cluster")
r.recorder = mgr.GetEventRecorderFor("topology/cluster-controller")
if r.patchHelperFactory == nil {
r.patchHelperFactory = serverSideApplyPatchHelperFactory(r.Client, ssa.NewCache())
}
Expand Down
2 changes: 1 addition & 1 deletion internal/controllers/topology/cluster/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestMain(m *testing.M) {
}
// Set up a ClusterCacheTracker and ClusterCacheReconciler to provide to controllers
// requiring a connection to a remote cluster
log := ctrl.Log.WithName("remote").WithName("ClusterCacheTracker")
log := ctrl.Log.WithValues("component", "remote/clustercachetracker")
secretCachingClient, err := client.New(mgr.GetConfig(), client.Options{
HTTPClient: mgr.GetHTTPClient(),
Cache: &client.CacheOptions{
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {

// Set up a ClusterCacheTracker and ClusterCacheReconciler to provide to controllers
// requiring a connection to a remote cluster
log := ctrl.Log.WithName("remote").WithName("ClusterCacheTracker")
log := ctrl.Log.WithValues("component", "remote/clustercachetracker")
tracker, err := remote.NewClusterCacheTracker(
mgr,
remote.ClusterCacheTrackerOptions{
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 @@ -303,7 +303,7 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
os.Exit(1)
}

log := ctrl.Log.WithName("remote").WithName("ClusterCacheTracker")
log := ctrl.Log.WithValues("component", "remote/clustercachetracker")
tracker, err := remote.NewClusterCacheTracker(
mgr,
remote.ClusterCacheTrackerOptions{
Expand Down

0 comments on commit bd2a6e1

Please sign in to comment.