Skip to content

Commit 3bd480e

Browse files
author
sdutta133
committed
klog structured logging
Signed-off-by: sdutta133 <[email protected]> fix lint issues fix cicd Signed-off-by: sdutta133 <[email protected]> consistent naming Signed-off-by: sdutta133 <[email protected]>
1 parent 84359ef commit 3bd480e

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

pkg/controllers/applicationfailover/common.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,9 @@ func buildPreservedLabelState(statePreservation *policyv1alpha1.StatePreservatio
131131
for _, rule := range statePreservation.Rules {
132132
value, err := parseJSONValue(rawStatus, rule.JSONPath)
133133
if err != nil {
134-
klog.Errorf("Failed to parse value with jsonPath(%s) from status(%v), error: %v",
135-
rule.JSONPath, string(rawStatus), err)
134+
klog.ErrorS(err, "Failed to parse value with jsonPath from status",
135+
"jsonPath", rule.JSONPath,
136+
"status", string(rawStatus))
136137
return nil, err
137138
}
138139
results[rule.AliasLabelName] = value

pkg/controllers/applicationfailover/crb_application_failover_controller.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type CRBApplicationFailoverController struct {
5959
// The Controller will requeue the Request to be processed again if an error is non-nil or
6060
// Result.Requeue is true, otherwise upon completion it will remove the work from the queue.
6161
func (c *CRBApplicationFailoverController) Reconcile(ctx context.Context, req controllerruntime.Request) (controllerruntime.Result, error) {
62-
klog.V(4).Infof("Reconciling ClusterResourceBinding %s.", req.Name)
62+
klog.V(4).InfoS("Reconciling ClusterResourceBinding", "name", req.Name)
6363

6464
binding := &workv1alpha2.ClusterResourceBinding{}
6565
if err := c.Client.Get(ctx, req.NamespacedName, binding); err != nil {
@@ -80,7 +80,7 @@ func (c *CRBApplicationFailoverController) Reconcile(ctx context.Context, req co
8080
return controllerruntime.Result{}, err
8181
}
8282
if retryDuration > 0 {
83-
klog.V(4).Infof("Retry to check health status of the workload after %v seconds.", retryDuration.Seconds())
83+
klog.V(4).InfoS("Retry to check health status of the workload", "afterSeconds", retryDuration.Seconds())
8484
return controllerruntime.Result{RequeueAfter: retryDuration}, nil
8585
}
8686
return controllerruntime.Result{}, nil
@@ -132,7 +132,7 @@ func (c *CRBApplicationFailoverController) syncBinding(ctx context.Context, bind
132132

133133
err := c.evictBinding(binding, needEvictClusters)
134134
if err != nil {
135-
klog.Errorf("Failed to evict binding(%s), err: %v.", binding.Name, err)
135+
klog.ErrorS(err, "Failed to evict binding", "name", binding.Name)
136136
return 0, err
137137
}
138138

@@ -153,7 +153,9 @@ func (c *CRBApplicationFailoverController) evictBinding(binding *workv1alpha2.Cl
153153
for _, cluster := range clusters {
154154
taskOpts, err := buildTaskOptions(binding.Spec.Failover.Application, binding.Status.AggregatedStatus, cluster, CRBApplicationFailoverControllerName, clustersBeforeFailover)
155155
if err != nil {
156-
klog.Errorf("failed to build TaskOptions for ClusterResourceBinding(%s) under Cluster(%s): %v", binding.Name, cluster, err)
156+
klog.ErrorS(err, "Failed to build TaskOptions for ClusterResourceBinding under Cluster",
157+
"name", binding.Name,
158+
"cluster", cluster)
157159
return err
158160
}
159161
binding.Spec.GracefulEvictCluster(cluster, workv1alpha2.NewTaskOptions(taskOpts...))
@@ -225,7 +227,7 @@ func (c *CRBApplicationFailoverController) clusterResourceBindingFilter(crb *wor
225227
resourceKey, err := helper.ConstructClusterWideKey(crb.Spec.Resource)
226228
if err != nil {
227229
// Never reach
228-
klog.Errorf("Failed to construct clusterWideKey from clusterResourceBinding(%s)", crb.Name)
230+
klog.ErrorS(err, "Failed to construct clusterWideKey from clusterResourceBinding", "name", crb.Name)
229231
return false
230232
}
231233

pkg/controllers/applicationfailover/rb_application_failover_controller.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type RBApplicationFailoverController struct {
5959
// The Controller will requeue the Request to be processed again if an error is non-nil or
6060
// Result.Requeue is true, otherwise upon completion it will remove the work from the queue.
6161
func (c *RBApplicationFailoverController) Reconcile(ctx context.Context, req controllerruntime.Request) (controllerruntime.Result, error) {
62-
klog.V(4).Infof("Reconciling ResourceBinding %s.", req.NamespacedName.String())
62+
klog.V(4).InfoS("Reconciling ResourceBinding", "namespace", req.Namespace, "name", req.Name)
6363

6464
binding := &workv1alpha2.ResourceBinding{}
6565
if err := c.Client.Get(ctx, req.NamespacedName, binding); err != nil {
@@ -80,7 +80,7 @@ func (c *RBApplicationFailoverController) Reconcile(ctx context.Context, req con
8080
return controllerruntime.Result{}, err
8181
}
8282
if retryDuration > 0 {
83-
klog.V(4).Infof("Retry to check health status of the workload after %v seconds.", retryDuration.Seconds())
83+
klog.V(4).InfoS("Retry to check health status of the workload", "afterSeconds", retryDuration.Seconds())
8484
return controllerruntime.Result{RequeueAfter: retryDuration}, nil
8585
}
8686
return controllerruntime.Result{}, nil
@@ -132,7 +132,7 @@ func (c *RBApplicationFailoverController) syncBinding(ctx context.Context, bindi
132132

133133
err := c.evictBinding(binding, needEvictClusters)
134134
if err != nil {
135-
klog.Errorf("Failed to evict binding(%s/%s), err: %v.", binding.Namespace, binding.Name, err)
135+
klog.ErrorS(err, "Failed to evict binding", "namespace", binding.Namespace, "name", binding.Name)
136136
return 0, err
137137
}
138138

@@ -153,7 +153,10 @@ func (c *RBApplicationFailoverController) evictBinding(binding *workv1alpha2.Res
153153
for _, cluster := range clusters {
154154
taskOpts, err := buildTaskOptions(binding.Spec.Failover.Application, binding.Status.AggregatedStatus, cluster, RBApplicationFailoverControllerName, clustersBeforeFailover)
155155
if err != nil {
156-
klog.Errorf("failed to build TaskOptions for ResourceBinding(%s/%s) under Cluster(%s): %v", binding.Namespace, binding.Name, cluster, err)
156+
klog.ErrorS(err, "Failed to build TaskOptions for ResourceBinding under Cluster",
157+
"namespace", binding.Namespace,
158+
"name", binding.Name,
159+
"cluster", cluster)
157160
return err
158161
}
159162
binding.Spec.GracefulEvictCluster(cluster, workv1alpha2.NewTaskOptions(taskOpts...))
@@ -225,7 +228,7 @@ func (c *RBApplicationFailoverController) bindingFilter(rb *workv1alpha2.Resourc
225228
resourceKey, err := helper.ConstructClusterWideKey(rb.Spec.Resource)
226229
if err != nil {
227230
// Never reach
228-
klog.Errorf("Failed to construct clusterWideKey from binding(%s/%s)", rb.Namespace, rb.Name)
231+
klog.ErrorS(err, "Failed to construct clusterWideKey from binding", "namespace", rb.Namespace, "name", rb.Name)
229232
return false
230233
}
231234

0 commit comments

Comments
 (0)