Skip to content

Commit

Permalink
Improve log k/v pairs and a improve/drop a few log lines
Browse files Browse the repository at this point in the history
  • Loading branch information
sbueringer committed Dec 13, 2023
1 parent 2575fa5 commit 87e940d
Show file tree
Hide file tree
Showing 15 changed files with 27 additions and 34 deletions.
23 changes: 12 additions & 11 deletions bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,6 @@ func (r *KubeadmConfigReconciler) Reconcile(ctx context.Context, req ctrl.Reques
if apierrors.IsNotFound(err) {
return ctrl.Result{}, nil
}
log.Error(err, "Failed to get config")
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
}

Expand All @@ -165,13 +157,22 @@ func (r *KubeadmConfigReconciler) Reconcile(ctx context.Context, req ctrl.Reques
return ctrl.Result{}, nil
}
if err != nil {
log.Error(err, "Failed to get owner")
return ctrl.Result{}, err
return ctrl.Result{}, errors.Wrapf(err, "failed to get owner")
}
if configOwner == nil {
return ctrl.Result{}, nil
}
log = log.WithValues(configOwner.GetKind(), klog.KRef(configOwner.GetNamespace(), configOwner.GetName()), "resourceVersion", configOwner.GetResourceVersion())
ctx = ctrl.LoggerInto(ctx, log)

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 Expand Up @@ -1043,7 +1044,7 @@ func (r *KubeadmConfigReconciler) storeBootstrapData(ctx context.Context, scope
if !apierrors.IsAlreadyExists(err) {
return errors.Wrapf(err, "failed to create bootstrap data secret for KubeadmConfig %s/%s", scope.Config.Namespace, scope.Config.Name)
}
log.Info("bootstrap data secret for KubeadmConfig already exists, updating", "Secret", klog.KObj(secret))
log.Info("Bootstrap data secret for KubeadmConfig already exists, updating", "Secret", klog.KObj(secret))
if err := r.Client.Update(ctx, secret); err != nil {
return errors.Wrapf(err, "failed to update bootstrap data secret for KubeadmConfig %s/%s", scope.Config.Namespace, scope.Config.Name)
}
Expand Down
3 changes: 1 addition & 2 deletions bootstrap/kubeadm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,12 @@ 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")
tracker, err := remote.NewClusterCacheTracker(
mgr,
remote.ClusterCacheTrackerOptions{
SecretCachingClient: secretCachingClient,
ControllerName: controllerName,
Log: &log,
Log: &ctrl.Log,
},
)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions controllers/remote/cluster_cache_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ func setDefaultOptions(opts *ClusterCacheTrackerOptions) {
opts.Log = &l
}

l := opts.Log.WithValues("component", "remote/clustercachetracker")
opts.Log = &l

if len(opts.ClientUncachedObjects) == 0 {
opts.ClientUncachedObjects = []client.Object{
&corev1.ConfigMap{},
Expand Down
3 changes: 1 addition & 2 deletions controlplane/kubeadm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,10 @@ 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")
tracker, err := remote.NewClusterCacheTracker(mgr, remote.ClusterCacheTrackerOptions{
SecretCachingClient: secretCachingClient,
ControllerName: controllerName,
Log: &log,
Log: &ctrl.Log,
ClientUncachedObjects: []client.Object{
&corev1.ConfigMap{},
&corev1.Secret{},
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
3 changes: 1 addition & 2 deletions internal/controllers/cluster/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,10 @@ 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")
tracker, err := remote.NewClusterCacheTracker(
mgr,
remote.ClusterCacheTrackerOptions{
Log: &log,
Log: &ctrl.Log,
Indexes: []remote.Index{remote.NodeProviderIDIndex},
},
)
Expand Down
3 changes: 1 addition & 2 deletions internal/controllers/machine/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,10 @@ 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")
tracker, err := remote.NewClusterCacheTracker(
mgr,
remote.ClusterCacheTrackerOptions{
Log: &log,
Log: &ctrl.Log,
Indexes: []remote.Index{remote.NodeProviderIDIndex},
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re

err = r.reconcile(ctx, cluster, deployment)
if err != nil {
log.Error(err, "Failed to reconcile MachineDeployment")
r.recorder.Eventf(deployment, corev1.EventTypeWarning, "ReconcileError", "%v", err)
}
return ctrl.Result{}, err
Expand Down
3 changes: 1 addition & 2 deletions internal/controllers/machinedeployment/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,10 @@ 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")
tracker, err := remote.NewClusterCacheTracker(
mgr,
remote.ClusterCacheTrackerOptions{
Log: &log,
Log: &ctrl.Log,
Indexes: []remote.Index{remote.NodeProviderIDIndex},
},
)
Expand Down
3 changes: 1 addition & 2 deletions internal/controllers/machinehealthcheck/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,10 @@ 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")
tracker, err := remote.NewClusterCacheTracker(
mgr,
remote.ClusterCacheTrackerOptions{
Log: &log,
Log: &ctrl.Log,
Indexes: []remote.Index{remote.NodeProviderIDIndex},
},
)
Expand Down
2 changes: 1 addition & 1 deletion internal/controllers/machineset/machineset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ func (r *Reconciler) updateStatus(ctx context.Context, cluster *clusterv1.Cluste
availableReplicasCount++
}
} else if machine.GetDeletionTimestamp().IsZero() {
log.Info("Waiting for the Kubernetes node on the machine to report ready state")
log.V(4).Info("Waiting for the Kubernetes node on the machine to report ready state")
}
}

Expand Down
3 changes: 1 addition & 2 deletions internal/controllers/machineset/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,10 @@ 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")
tracker, err := remote.NewClusterCacheTracker(
mgr,
remote.ClusterCacheTrackerOptions{
Log: &log,
Log: &ctrl.Log,
Indexes: []remote.Index{remote.NodeProviderIDIndex},
},
)
Expand Down
3 changes: 1 addition & 2 deletions internal/controllers/topology/cluster/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ 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")
secretCachingClient, err := client.New(mgr.GetConfig(), client.Options{
HTTPClient: mgr.GetHTTPClient(),
Cache: &client.CacheOptions{
Expand All @@ -89,7 +88,7 @@ func TestMain(m *testing.M) {
tracker, err := remote.NewClusterCacheTracker(
mgr,
remote.ClusterCacheTrackerOptions{
Log: &log,
Log: &ctrl.Log,
SecretCachingClient: secretCachingClient,
},
)
Expand Down
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,13 +380,12 @@ 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")
tracker, err := remote.NewClusterCacheTracker(
mgr,
remote.ClusterCacheTrackerOptions{
SecretCachingClient: secretCachingClient,
ControllerName: controllerName,
Log: &log,
Log: &ctrl.Log,
Indexes: []remote.Index{remote.NodeProviderIDIndex},
},
)
Expand Down
3 changes: 1 addition & 2 deletions test/infrastructure/docker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,12 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
os.Exit(1)
}

log := ctrl.Log.WithName("remote").WithName("ClusterCacheTracker")
tracker, err := remote.NewClusterCacheTracker(
mgr,
remote.ClusterCacheTrackerOptions{
SecretCachingClient: secretCachingClient,
ControllerName: controllerName,
Log: &log,
Log: &ctrl.Log,
},
)
if err != nil {
Expand Down

0 comments on commit 87e940d

Please sign in to comment.