@@ -232,9 +232,6 @@ func (upd *UpdaterImpl) writeStatuses(
232
232
obj client.Object ,
233
233
statusSetter func (client.Object ),
234
234
) {
235
- // To preserve and log the error message inside the function in wait.ExponentialBackoffWithContext
236
- var lastError error
237
-
238
235
err := wait .ExponentialBackoffWithContext (
239
236
ctx ,
240
237
wait.Backoff {
@@ -251,18 +248,33 @@ func (upd *UpdaterImpl) writeStatuses(
251
248
// Otherwise, the Update status API call can fail.
252
249
// Note: the default client uses a cache for reads, so we're not making an unnecessary API call here.
253
250
// the default is configurable in the Manager options.
254
- if lastError = upd .cfg .Client .Get (ctx , nsname , obj ); lastError != nil {
251
+ if err : = upd .cfg .Client .Get (ctx , nsname , obj ); err != nil {
255
252
// apierrors.IsNotFound(err) can happen when the resource is deleted,
256
253
// so no need to retry or return an error.
257
- if apierrors .IsNotFound (lastError ) {
254
+ if apierrors .IsNotFound (err ) {
255
+ upd .cfg .Logger .V (1 ).Info (
256
+ "Resource was not found when trying to update status" ,
257
+ "namespace" , nsname .Namespace ,
258
+ "name" , nsname .Name ,
259
+ "kind" , obj .GetObjectKind ().GroupVersionKind ().Kind )
258
260
return true , nil
259
261
}
262
+ upd .cfg .Logger .V (1 ).Info (
263
+ "Encountered error when getting resource to update status" ,
264
+ "namespace" , nsname .Namespace ,
265
+ "name" , nsname .Name ,
266
+ "kind" , obj .GetObjectKind ().GroupVersionKind ().Kind )
260
267
return false , nil
261
268
}
262
269
263
270
statusSetter (obj )
264
271
265
- if lastError = upd .cfg .Client .Status ().Update (ctx , obj ); lastError != nil {
272
+ if err := upd .cfg .Client .Status ().Update (ctx , obj ); err != nil {
273
+ upd .cfg .Logger .V (1 ).Info (
274
+ "Encountered error updating status" ,
275
+ "namespace" , nsname .Namespace ,
276
+ "name" , nsname .Name ,
277
+ "kind" , obj .GetObjectKind ().GroupVersionKind ().Kind )
266
278
return false , nil
267
279
}
268
280
@@ -271,7 +283,7 @@ func (upd *UpdaterImpl) writeStatuses(
271
283
)
272
284
if err != nil && ! errors .Is (err , context .Canceled ) {
273
285
upd .cfg .Logger .Error (
274
- fmt . Errorf ( "%s : %w" , err . Error (), lastError ) ,
286
+ err ,
275
287
"Failed to update status" ,
276
288
"namespace" , nsname .Namespace ,
277
289
"name" , nsname .Name ,
0 commit comments