Skip to content

Conversation

@rahulait
Copy link
Contributor

This PR improves the error logging for various controllers. Changes include:

  1. Changing r.Log.V(consts.LogLevelDebug).Error to r.log.Error as logr doesn't have verbosity levels for Error messages. Error messages are always logged. https://pkg.go.dev/github.com/go-logr/logr#hdr-Verbosity
  2. Logging entire error object instead of just the message so that other relevant info also gets logged.
  3. Used %w instead of %v when doing error wrapping so that entire error object gets wrapped and any helper functions like apierrors.IsNotFound(err) can look into wrapped error as well to identify the error correctly. Previously, since %v was used, these helper functions would have failed to correctly identify the wrapped error.
  4. Changed return ctrl.Result{RequeueAfter: time.Second * 5}, statusError to return ctrl.Result{}, statusError as the fixed retry interval gets ignored if returned error is not nil. https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile#TypedReconciler

@copy-pr-bot
Copy link

copy-pr-bot bot commented Oct 30, 2025

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

Signed-off-by: Rahul Sharma <[email protected]>
@rahulait
Copy link
Contributor Author

/ok to test 0e2492a

@rahulait rahulait changed the title [imporvement] : fix logging for controllers [improvement] : fix logging for controllers Oct 30, 2025
Comment on lines +103 to +104
err = fmt.Errorf("error getting ClusterPolicy list: %w", err)
logger.Error(err, "error getting ClusterPolicy list")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean

Suggested change
err = fmt.Errorf("error getting ClusterPolicy list: %w", err)
logger.Error(err, "error getting ClusterPolicy list")
wrappedError := fmt.Errorf("error getting ClusterPolicy list: %w", err)
logger.Error(err, "error getting ClusterPolicy list")

to align with the similar code block from above?

err = fmt.Errorf("no ClusterPolicy object found in the cluster")
logger.V(consts.LogLevelError).Error(nil, err.Error())
err := fmt.Errorf("no ClusterPolicy object found in the cluster")
logger.Error(err, "no ClusterPolicy object found in the cluster")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: What will get printed here? I assume our message will be printed twice?

err = r.Update(ctx, node)
if err != nil {
r.Log.V(consts.LogLevelError).Error(
r.Log.Error(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we update this to just be one line?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants