@@ -58,18 +58,18 @@ type ClusterTaintPolicyController struct {
58
58
// The Controller will requeue the Request to be processed again if an error is non-nil or
59
59
// Result.Requeue is true, otherwise upon completion it will remove the work from the queue.
60
60
func (c * ClusterTaintPolicyController ) Reconcile (ctx context.Context , req controllerruntime.Request ) (controllerruntime.Result , error ) {
61
- klog .V (4 ).Infof ("Reconciling Cluster %s. " , req .Name )
61
+ klog .V (4 ).InfoS ("Reconciling Cluster" , "cluster " , req .Name )
62
62
63
63
clusterObj := & clusterv1alpha1.Cluster {}
64
64
if err := c .Client .Get (ctx , req .NamespacedName , clusterObj ); err != nil {
65
- klog .Errorf ( "Failed to get Cluster(%s), error: %v" , req .Name , err )
65
+ klog .ErrorS ( err , "Failed to get Cluster" , "cluster" , req .Name )
66
66
return controllerruntime.Result {}, client .IgnoreNotFound (err )
67
67
}
68
68
69
69
clusterTaintPolicyList := & policyv1alpha1.ClusterTaintPolicyList {}
70
70
listOption := & client.ListOptions {UnsafeDisableDeepCopy : ptr .To (true )}
71
71
if err := c .Client .List (ctx , clusterTaintPolicyList , listOption ); err != nil {
72
- klog .Errorf ( "Failed to list ClusterTaintPolicy, error: %v" , err )
72
+ klog .ErrorS ( err , "Failed to list ClusterTaintPolicy" )
73
73
return controllerruntime.Result {}, err
74
74
}
75
75
@@ -99,18 +99,18 @@ func (c *ClusterTaintPolicyController) Reconcile(ctx context.Context, req contro
99
99
objPatch := client .MergeFrom (clusterObj )
100
100
err := c .Client .Patch (ctx , clusterCopyObj , objPatch )
101
101
if err != nil {
102
- klog .Errorf ( "Failed to patch Cluster(%s), error: %v" , req .Name , err )
102
+ klog .ErrorS ( err , "Failed to patch Cluster" , "cluster" , req .Name )
103
103
c .EventRecorder .Event (clusterCopyObj , corev1 .EventTypeWarning , events .EventReasonTaintClusterFailed , err .Error ())
104
104
return controllerruntime.Result {}, err
105
105
}
106
106
107
107
msg := fmt .Sprintf ("Update Cluster(%s) with taints(%v) succeed" , req .Name ,
108
108
utilhelper .GenerateTaintsMessage (clusterCopyObj .Spec .Taints ))
109
- klog .Info ( msg )
109
+ klog .InfoS ( "Successfully updated cluster taints" , "cluster" , req . Name , "taints" , clusterCopyObj . Spec . Taints )
110
110
c .EventRecorder .Event (clusterCopyObj , corev1 .EventTypeNormal , events .EventReasonTaintClusterSucceed , msg )
111
111
return controllerruntime.Result {}, nil
112
112
}
113
- klog .V (4 ).Infof ("Cluster(%s) taints are up to date." , req .Name )
113
+ klog .V (4 ).InfoS ("Cluster taints are up to date." , "cluster " , req .Name )
114
114
return controllerruntime.Result {}, nil
115
115
}
116
116
@@ -147,7 +147,8 @@ func conditionMatches(conditions []metav1.Condition, matchConditions []policyv1a
147
147
}
148
148
}
149
149
default :
150
- klog .Errorf ("Unsupported MatchCondition operator: %s" , matchCondition .Operator )
150
+ err := fmt .Errorf ("unsupported MatchCondition operator" )
151
+ klog .ErrorS (err , "operator" , matchCondition .Operator )
151
152
return false
152
153
}
153
154
}
@@ -235,7 +236,7 @@ func (c *ClusterTaintPolicyController) SetupWithManager(mgr controllerruntime.Ma
235
236
clusterList := & clusterv1alpha1.ClusterList {}
236
237
listOption := & client.ListOptions {UnsafeDisableDeepCopy : ptr .To (true )}
237
238
if err := c .Client .List (ctx , clusterList , listOption ); err != nil {
238
- klog .Errorf ( "Failed to list Cluster, error: %v" , err )
239
+ klog .ErrorS ( err , "Failed to list Cluster" )
239
240
return nil
240
241
}
241
242
0 commit comments