@@ -69,7 +69,7 @@ type ClusterResourceBindingController struct {
69
69
// The Controller will requeue the Request to be processed again if an error is non-nil or
70
70
// Result.Requeue is true, otherwise upon completion it will remove the work from the queue.
71
71
func (c * ClusterResourceBindingController ) Reconcile (ctx context.Context , req controllerruntime.Request ) (controllerruntime.Result , error ) {
72
- klog .V (4 ).Infof ("Reconciling ClusterResourceBinding %s ." , req .NamespacedName .String () )
72
+ klog .V (4 ).InfoS ("Reconciling ClusterResourceBinding." , "ClusterResourceBinding" , req .NamespacedName .Name )
73
73
74
74
clusterResourceBinding := & workv1alpha2.ClusterResourceBinding {}
75
75
if err := c .Client .Get (ctx , req .NamespacedName , clusterResourceBinding ); err != nil {
@@ -82,9 +82,9 @@ func (c *ClusterResourceBindingController) Reconcile(ctx context.Context, req co
82
82
}
83
83
84
84
if ! clusterResourceBinding .DeletionTimestamp .IsZero () {
85
- klog .V (4 ).Infof ("Begin to delete works owned by binding(%s) ." , req . NamespacedName . String () )
85
+ klog .V (4 ).InfoS ("Begin to delete works owned by ClusterResourceBinding ." , "ClusterResourceBinding" , clusterResourceBinding . Name )
86
86
if err := helper .DeleteWorks (ctx , c .Client , "" , req .Name , clusterResourceBinding .Labels [workv1alpha2 .ClusterResourceBindingPermanentIDLabel ]); err != nil {
87
- klog .Errorf ( "Failed to delete works related to %s: %v" , clusterResourceBinding .GetName (), err )
87
+ klog .ErrorS ( err , "Failed to delete works related to ClusterResourceBinding." , "ClusterResourceBinding" , clusterResourceBinding .Name )
88
88
return controllerruntime.Result {}, err
89
89
}
90
90
return c .removeFinalizer (ctx , clusterResourceBinding )
@@ -121,22 +121,22 @@ func (c *ClusterResourceBindingController) syncBinding(ctx context.Context, bind
121
121
// So, just return without retry(requeue) would save unnecessary loop.
122
122
return controllerruntime.Result {}, nil
123
123
}
124
- klog .Errorf ( "Failed to fetch workload for clusterResourceBinding(%s). Error: %v." , binding .GetName (), err )
124
+ klog .ErrorS ( err , "Failed to fetch workload for ClusterResourceBinding." , "ClusterResourceBinding" , binding .Name )
125
125
return controllerruntime.Result {}, err
126
126
}
127
127
128
128
start := time .Now ()
129
129
err = ensureWork (ctx , c .Client , c .ResourceInterpreter , workload , c .OverrideManager , binding , apiextensionsv1 .ClusterScoped )
130
130
metrics .ObserveSyncWorkLatency (err , start )
131
131
if err != nil {
132
- klog .Errorf ( "Failed to transform clusterResourceBinding(%s) to works. Error: %v." , binding .GetName (), err )
132
+ klog .ErrorS ( err , "Failed to transform ClusterResourceBinding to works." , "ClusterResourceBinding" , binding .Name )
133
133
c .EventRecorder .Event (binding , corev1 .EventTypeWarning , events .EventReasonSyncWorkFailed , err .Error ())
134
134
c .EventRecorder .Event (workload , corev1 .EventTypeWarning , events .EventReasonSyncWorkFailed , err .Error ())
135
135
return controllerruntime.Result {}, err
136
136
}
137
137
138
- msg := fmt .Sprintf ("Sync work of clusterResourceBinding (%s) successful." , binding .GetName () )
139
- klog .V (4 ).Info ( msg )
138
+ msg := fmt .Sprintf ("Sync work of ClusterResourceBinding (%s) successful." , binding .Name )
139
+ klog .V (4 ).InfoS ( "Sync work of ClusterResourceBinding successful." , "ClusterResourceBinding" , binding . Name )
140
140
c .EventRecorder .Event (binding , corev1 .EventTypeNormal , events .EventReasonSyncWorkSucceed , msg )
141
141
c .EventRecorder .Event (workload , corev1 .EventTypeNormal , events .EventReasonSyncWorkSucceed , msg )
142
142
return controllerruntime.Result {}, nil
@@ -145,14 +145,14 @@ func (c *ClusterResourceBindingController) syncBinding(ctx context.Context, bind
145
145
func (c * ClusterResourceBindingController ) removeOrphanWorks (ctx context.Context , binding * workv1alpha2.ClusterResourceBinding ) error {
146
146
works , err := helper .FindOrphanWorks (ctx , c .Client , "" , binding .Name , binding .Labels [workv1alpha2 .ClusterResourceBindingPermanentIDLabel ], helper .ObtainBindingSpecExistingClusters (binding .Spec ))
147
147
if err != nil {
148
- klog .Errorf ( "Failed to find orphan works by ClusterResourceBinding(%s). Error: %v." , binding .GetName (), err )
148
+ klog .ErrorS ( err , "Failed to find orphan works of ClusterResourceBinding." , "ClusterResourceBinding" , binding .Name )
149
149
c .EventRecorder .Event (binding , corev1 .EventTypeWarning , events .EventReasonCleanupWorkFailed , err .Error ())
150
150
return err
151
151
}
152
152
153
153
err = helper .RemoveOrphanWorks (ctx , c .Client , works )
154
154
if err != nil {
155
- klog .Errorf ( "Failed to remove orphan works by clusterResourceBinding(%s). Error: %v." , binding .GetName (), err )
155
+ klog .ErrorS ( err , "Failed to remove orphan works of ClusterResourceBinding." , "ClusterResourceBinding" , binding .Name )
156
156
c .EventRecorder .Event (binding , corev1 .EventTypeWarning , events .EventReasonCleanupWorkFailed , err .Error ())
157
157
return err
158
158
}
@@ -183,15 +183,15 @@ func (c *ClusterResourceBindingController) newOverridePolicyFunc() handler.MapFu
183
183
184
184
readonlyBindingList := & workv1alpha2.ClusterResourceBindingList {}
185
185
if err := c .Client .List (ctx , readonlyBindingList , & client.ListOptions {UnsafeDisableDeepCopy : ptr .To (true )}); err != nil {
186
- klog .Errorf ( "Failed to list clusterResourceBindings, error: %v" , err )
186
+ klog .ErrorS ( err , "Failed to list ClusterResourceBindings" )
187
187
return nil
188
188
}
189
189
190
190
var requests []reconcile.Request
191
191
for _ , binding := range readonlyBindingList .Items {
192
192
// Nil resourceSelectors means matching all resources.
193
193
if len (overrideRS ) == 0 {
194
- klog .V (2 ).Infof ("Enqueue ClusterResourceBinding(%s) as cluster override policy(%s) changes." , binding .Name , a .GetName ())
194
+ klog .V (2 ).InfoS ("Enqueue ClusterResourceBinding as cluster override policy changes." , "ClusterResourceBinding" , binding .Name , "ClusterOverridePolicy" , a .GetName ())
195
195
requests = append (requests , reconcile.Request {NamespacedName : types.NamespacedName {Name : binding .Name }})
196
196
continue
197
197
}
@@ -200,13 +200,13 @@ func (c *ClusterResourceBindingController) newOverridePolicyFunc() handler.MapFu
200
200
if err != nil {
201
201
// If we cannot fetch resource template from binding, this may be due to the fact that the resource template has been deleted.
202
202
// Just skip it so that it will not affect other bindings.
203
- klog .Errorf ( "Failed to fetch workload for clusterResourceBinding(%s). Error: %v." , binding .Name , err )
203
+ klog .ErrorS ( err , "Failed to fetch workload for ClusterResourceBinding." , "ClusterResourceBinding" , binding .Name )
204
204
continue
205
205
}
206
206
207
207
for _ , rs := range overrideRS {
208
208
if util .ResourceMatches (workload , rs ) {
209
- klog .V (2 ).Infof ("Enqueue ClusterResourceBinding(%s) as cluster override policy(%s) changes." , binding .Name , a .GetName ())
209
+ klog .V (2 ).InfoS ("Enqueue ClusterResourceBinding as cluster override policy changes." , "ClusterResourceBinding" , binding .Name , "ClusterOverridePolicy" , a .GetName ())
210
210
requests = append (requests , reconcile.Request {NamespacedName : types.NamespacedName {Name : binding .Name }})
211
211
break
212
212
}
0 commit comments