-
Notifications
You must be signed in to change notification settings - Fork 406
[improvement] : fix logging for controllers #1844
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Rahul Sharma <[email protected]>
|
/ok to test 0e2492a |
| err = fmt.Errorf("error getting ClusterPolicy list: %w", err) | ||
| logger.Error(err, "error getting ClusterPolicy list") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean
| 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") |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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?
This PR improves the error logging for various controllers. Changes include:
r.Log.V(consts.LogLevelDebug).Errortor.log.Erroras 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%winstead of%vwhen doing error wrapping so that entire error object gets wrapped and any helper functions likeapierrors.IsNotFound(err)can look into wrapped error as well to identify the error correctly. Previously, since%vwas used, these helper functions would have failed to correctly identify the wrapped error.return ctrl.Result{RequeueAfter: time.Second * 5}, statusErrortoreturn ctrl.Result{}, statusErroras the fixed retry interval gets ignored if returned error is not nil. https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile#TypedReconciler