@@ -69,7 +69,7 @@ type ResourceBindingController 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 * ResourceBindingController ) Reconcile (ctx context.Context , req controllerruntime.Request ) (controllerruntime.Result , error ) {
72
- klog .V (4 ).Infof ("Reconciling ResourceBinding %s. " , req .NamespacedName .String ())
72
+ klog .V (4 ).InfoS ("Reconciling ResourceBinding" , "binding " , req .NamespacedName .String ())
73
73
74
74
binding := & workv1alpha2.ResourceBinding {}
75
75
if err := c .Client .Get (ctx , req .NamespacedName , binding ); err != nil {
@@ -82,9 +82,9 @@ func (c *ResourceBindingController) Reconcile(ctx context.Context, req controlle
82
82
}
83
83
84
84
if ! binding .DeletionTimestamp .IsZero () {
85
- klog .V (4 ).Infof ("Begin to delete works owned by binding(%s). " , req .NamespacedName .String ())
85
+ klog .V (4 ).InfoS ("Begin deleting works owned by ResourceBinding" , " binding" , req .NamespacedName .String ())
86
86
if err := helper .DeleteWorks (ctx , c .Client , req .Namespace , req .Name , binding .Labels [workv1alpha2 .ResourceBindingPermanentIDLabel ]); err != nil {
87
- klog .Errorf ( "Failed to delete works related to %s/%s: %v" , binding .GetNamespace (), binding .GetName (), err )
87
+ klog .ErrorS ( err , "Failed deleting works owned by ResourceBinding" , "namespace" , binding .GetNamespace (), " binding" , binding .GetName ())
88
88
return controllerruntime.Result {}, err
89
89
}
90
90
return c .removeFinalizer (ctx , binding )
@@ -121,23 +121,21 @@ func (c *ResourceBindingController) syncBinding(ctx context.Context, binding *wo
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 resourceBinding(%s/%s). Error: %v." ,
125
- binding .GetNamespace (), binding .GetName (), err )
124
+ klog .ErrorS (err , "Failed to fetch workload for ResourceBinding" , "namespace" , binding .GetNamespace (), "binding" , binding .GetName ())
126
125
return controllerruntime.Result {}, err
127
126
}
128
127
start := time .Now ()
129
128
err = ensureWork (ctx , c .Client , c .ResourceInterpreter , workload , c .OverrideManager , binding , apiextensionsv1 .NamespaceScoped )
130
129
metrics .ObserveSyncWorkLatency (err , start )
131
130
if err != nil {
132
- klog .Errorf ("Failed to transform resourceBinding(%s/%s) to works. Error: %v." ,
133
- binding .GetNamespace (), binding .GetName (), err )
131
+ klog .ErrorS (err , "Failed to transform ResourceBinding to works" , "namespace" , binding .GetNamespace (), "binding" , binding .GetName ())
134
132
c .EventRecorder .Event (binding , corev1 .EventTypeWarning , events .EventReasonSyncWorkFailed , err .Error ())
135
133
c .EventRecorder .Event (workload , corev1 .EventTypeWarning , events .EventReasonSyncWorkFailed , err .Error ())
136
134
return controllerruntime.Result {}, err
137
135
}
138
136
139
- msg := fmt .Sprintf ("Sync work of resourceBinding (%s/%s) successful." , binding .Namespace , binding .Name )
140
- klog .V (4 ).Info (msg )
137
+ msg := fmt .Sprintf ("Sync work of ResourceBinding (%s/%s) successful." , binding .Namespace , binding .Name )
138
+ klog .V (4 ).InfoS (msg , "namespace" , binding . GetNamespace (), "binding" , binding . GetName () )
141
139
c .EventRecorder .Event (binding , corev1 .EventTypeNormal , events .EventReasonSyncWorkSucceed , msg )
142
140
c .EventRecorder .Event (workload , corev1 .EventTypeNormal , events .EventReasonSyncWorkSucceed , msg )
143
141
return controllerruntime.Result {}, nil
@@ -147,16 +145,14 @@ func (c *ResourceBindingController) removeOrphanWorks(ctx context.Context, bindi
147
145
works , err := helper .FindOrphanWorks (ctx , c .Client , binding .Namespace , binding .Name ,
148
146
binding .Labels [workv1alpha2 .ResourceBindingPermanentIDLabel ], helper .ObtainBindingSpecExistingClusters (binding .Spec ))
149
147
if err != nil {
150
- klog .Errorf ("Failed to find orphan works by resourceBinding(%s/%s). Error: %v." ,
151
- binding .GetNamespace (), binding .GetName (), err )
148
+ klog .ErrorS (err , "Failed to find orphaned works by ResourceBinding" , "namespace" , binding .GetNamespace (), "binding" , binding .GetName ())
152
149
c .EventRecorder .Event (binding , corev1 .EventTypeWarning , events .EventReasonCleanupWorkFailed , err .Error ())
153
150
return err
154
151
}
155
152
156
153
err = helper .RemoveOrphanWorks (ctx , c .Client , works )
157
154
if err != nil {
158
- klog .Errorf ("Failed to remove orphan works by resourceBinding(%s/%s). Error: %v." ,
159
- binding .GetNamespace (), binding .GetName (), err )
155
+ klog .ErrorS (err , "Failed to remove orphaned works by ResourceBinding" , "namespace" , binding .GetNamespace (), "binding" , binding .GetName ())
160
156
c .EventRecorder .Event (binding , corev1 .EventTypeWarning , events .EventReasonCleanupWorkFailed , err .Error ())
161
157
return err
162
158
}
@@ -201,15 +197,16 @@ func (c *ResourceBindingController) newOverridePolicyFunc() handler.MapFunc {
201
197
}
202
198
}
203
199
if err := c .Client .List (ctx , readonlyBindingList , listOption ); err != nil {
204
- klog .Errorf ( "Failed to list resourceBindings, error: %v" , err )
200
+ klog .ErrorS ( err , "Failed to list ResourceBindings for policy" , "namespace" , a . GetNamespace (), "name" , a . GetName () )
205
201
return nil
206
202
}
207
203
208
204
var requests []reconcile.Request
209
205
for _ , binding := range readonlyBindingList .Items {
210
206
// Nil resourceSelectors means matching all resources.
211
207
if len (overrideRS ) == 0 {
212
- klog .V (2 ).Infof ("Enqueue ResourceBinding(%s/%s) as override policy(%s/%s) changes." , binding .Namespace , binding .Name , a .GetNamespace (), a .GetName ())
208
+ klog .V (2 ).InfoS ("Enqueue ResourceBinding as override policy changes" , "namespace" , binding .Namespace ,
209
+ "binding" , binding .Name , "policyNamespace" , a .GetNamespace (), "policy" , a .GetName ())
213
210
requests = append (requests , reconcile.Request {NamespacedName : types.NamespacedName {Namespace : binding .Namespace , Name : binding .Name }})
214
211
continue
215
212
}
@@ -218,13 +215,14 @@ func (c *ResourceBindingController) newOverridePolicyFunc() handler.MapFunc {
218
215
if err != nil {
219
216
// If we cannot fetch resource template from binding, this may be due to the fact that the resource template has been deleted.
220
217
// Just skip it so that it will not affect other bindings.
221
- klog .Errorf ( "Failed to fetch workload for resourceBinding(%s/%s). Error: %v." , binding .Namespace , binding . Name , err )
218
+ klog .ErrorS ( err , "Failed to fetch workload for ResourceBinding" , "namespace" , binding .Namespace , " binding" , binding . Name )
222
219
continue
223
220
}
224
221
225
222
for _ , rs := range overrideRS {
226
223
if util .ResourceMatches (workload , rs ) {
227
- klog .V (2 ).Infof ("Enqueue ResourceBinding(%s/%s) as override policy(%s/%s) changes." , binding .Namespace , binding .Name , a .GetNamespace (), a .GetName ())
224
+ klog .V (2 ).InfoS ("Enqueue ResourceBinding as override policy changes" , "namespace" , binding .Namespace ,
225
+ "binding" , binding .Name , "policyNamespace" , a .GetNamespace (), "policy" , a .GetName ())
228
226
requests = append (requests , reconcile.Request {NamespacedName : types.NamespacedName {Namespace : binding .Namespace , Name : binding .Name }})
229
227
break
230
228
}
0 commit comments