Skip to content

Commit e15e496

Browse files
authored
Merge pull request #6508 from wenhuwang/remedy-ctrl-logs
Add json logging support for remediation controller
2 parents 1c4af4b + 941ace0 commit e15e496

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

pkg/controllers/remediation/eventhandlers.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (h *remedyEventHandler) Create(ctx context.Context, e event.TypedCreateEven
9999
clusterList := &clusterv1alpha1.ClusterList{}
100100
err := h.client.List(ctx, clusterList)
101101
if err != nil {
102-
klog.Errorf("Failed to list cluster: %v", err)
102+
klog.ErrorS(err, "Failed to list cluster")
103103
return
104104
}
105105

@@ -122,7 +122,7 @@ func (h *remedyEventHandler) Update(ctx context.Context, e event.TypedUpdateEven
122122
clusterList := &clusterv1alpha1.ClusterList{}
123123
err := h.client.List(ctx, clusterList)
124124
if err != nil {
125-
klog.Errorf("Failed to list cluster: %v", err)
125+
klog.ErrorS(err, "Failed to list cluster")
126126
return
127127
}
128128

@@ -174,7 +174,7 @@ func (h *remedyEventHandler) Delete(ctx context.Context, e event.TypedDeleteEven
174174
clusterList := &clusterv1alpha1.ClusterList{}
175175
err := h.client.List(ctx, clusterList)
176176
if err != nil {
177-
klog.Errorf("Failed to list cluster: %v", err)
177+
klog.ErrorS(err, "Failed to list cluster")
178178
return
179179
}
180180

pkg/controllers/remediation/remedy_controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type RemedyController struct {
4949
// The Controller will requeue the Request to be processed again if an error is non-nil or
5050
// Result.Requeue is true, otherwise upon completion it will remove the work from the queue.
5151
func (c *RemedyController) Reconcile(ctx context.Context, req controllerruntime.Request) (controllerruntime.Result, error) {
52-
klog.V(4).Infof("Start to reconcile cluster(%s)", req.NamespacedName.String())
52+
klog.V(4).InfoS("Start to reconcile cluster", "cluster", req.NamespacedName.String())
5353
cluster := &clusterv1alpha1.Cluster{}
5454
if err := c.Client.Get(ctx, req.NamespacedName, cluster); err != nil {
5555
if apierrors.IsNotFound(err) {
@@ -64,7 +64,7 @@ func (c *RemedyController) Reconcile(ctx context.Context, req controllerruntime.
6464

6565
clusterRelatedRemedies, err := getClusterRelatedRemedies(ctx, c.Client, cluster)
6666
if err != nil {
67-
klog.Errorf("Failed to get cluster(%s) related remedies: %v", cluster.Name, err)
67+
klog.ErrorS(err, "Failed to get cluster related remedies", "cluster", cluster.Name)
6868
return controllerruntime.Result{}, err
6969
}
7070

@@ -76,10 +76,10 @@ func (c *RemedyController) Reconcile(ctx context.Context, req controllerruntime.
7676
})
7777
return err
7878
}); err != nil {
79-
klog.Errorf("Failed to sync cluster(%s) remedy actions: %v", cluster.Name, err)
79+
klog.ErrorS(err, "Failed to sync cluster remedy actions", "cluster", cluster.Name)
8080
return controllerruntime.Result{}, err
8181
}
82-
klog.V(4).Infof("Success to sync cluster(%s) remedy actions: %v", cluster.Name, actions)
82+
klog.V(4).InfoS("Success to sync cluster remedy actions", "cluster", cluster.Name, "actions", actions)
8383
return controllerruntime.Result{}, nil
8484
}
8585

0 commit comments

Comments
 (0)