Skip to content

Commit b1fcff1

Browse files
committed
Remove lastError and add debug level logs
1 parent 2d17d36 commit b1fcff1

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

internal/framework/status/updater.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,6 @@ func (upd *UpdaterImpl) writeStatuses(
232232
obj client.Object,
233233
statusSetter func(client.Object),
234234
) {
235-
// To preserve and log the error message inside the function in wait.ExponentialBackoffWithContext
236-
var lastError error
237-
238235
err := wait.ExponentialBackoffWithContext(
239236
ctx,
240237
wait.Backoff{
@@ -251,18 +248,33 @@ func (upd *UpdaterImpl) writeStatuses(
251248
// Otherwise, the Update status API call can fail.
252249
// Note: the default client uses a cache for reads, so we're not making an unnecessary API call here.
253250
// 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 {
255252
// apierrors.IsNotFound(err) can happen when the resource is deleted,
256253
// 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)
258260
return true, nil
259261
}
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)
260267
return false, nil
261268
}
262269

263270
statusSetter(obj)
264271

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)
266278
return false, nil
267279
}
268280

@@ -271,7 +283,7 @@ func (upd *UpdaterImpl) writeStatuses(
271283
)
272284
if err != nil && !errors.Is(err, context.Canceled) {
273285
upd.cfg.Logger.Error(
274-
fmt.Errorf("%s : %w", err.Error(), lastError),
286+
err,
275287
"Failed to update status",
276288
"namespace", nsname.Namespace,
277289
"name", nsname.Name,

0 commit comments

Comments
 (0)