-
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?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -18,6 +18,7 @@ package controllers | |||||||||
|
|
||||||||||
| import ( | ||||||||||
| "context" | ||||||||||
| "errors" | ||||||||||
| "fmt" | ||||||||||
| "maps" | ||||||||||
| "time" | ||||||||||
|
|
@@ -79,47 +80,41 @@ func (r *NVIDIADriverReconciler) Reconcile(ctx context.Context, req ctrl.Request | |||||||||
|
|
||||||||||
| // Get the NvidiaDriver instance from this request | ||||||||||
| instance := &nvidiav1alpha1.NVIDIADriver{} | ||||||||||
| var condErr error | ||||||||||
| err := r.Get(ctx, req.NamespacedName, instance) | ||||||||||
| if err != nil { | ||||||||||
| if err := r.Get(ctx, req.NamespacedName, instance); err != nil { | ||||||||||
| if apierrors.IsNotFound(err) { | ||||||||||
| // Request object not found, could have been deleted after reconcile request. | ||||||||||
| // Owned objects are automatically garbage collected. For additional cleanup logic use finalizers. | ||||||||||
| // Return and don't requeue | ||||||||||
| return reconcile.Result{}, nil | ||||||||||
| } | ||||||||||
| err = fmt.Errorf("error getting NVIDIADriver object: %w", err) | ||||||||||
| logger.V(consts.LogLevelError).Error(nil, err.Error()) | ||||||||||
| wrappedErr := fmt.Errorf("error getting NVIDIADriver object: %w", err) | ||||||||||
| logger.Error(err, "error getting NVIDIADriver object") | ||||||||||
| instance.Status.State = nvidiav1alpha1.NotReady | ||||||||||
| condErr = r.conditionUpdater.SetConditionsError(ctx, instance, conditions.ReconcileFailed, err.Error()) | ||||||||||
| if condErr != nil { | ||||||||||
| logger.V(consts.LogLevelDebug).Error(nil, condErr.Error()) | ||||||||||
| if condErr := r.conditionUpdater.SetConditionsError(ctx, instance, conditions.ReconcileFailed, wrappedErr.Error()); condErr != nil { | ||||||||||
| logger.Error(condErr, "failed to set condition") | ||||||||||
| } | ||||||||||
| // Error reading the object - requeue the request. | ||||||||||
| return reconcile.Result{}, err | ||||||||||
| return reconcile.Result{}, wrappedErr | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // Get the singleton NVIDIA ClusterPolicy object in the cluster. | ||||||||||
| clusterPolicyList := &gpuv1.ClusterPolicyList{} | ||||||||||
| err = r.List(ctx, clusterPolicyList) | ||||||||||
| if err != nil { | ||||||||||
| err = fmt.Errorf("error getting ClusterPolicy list: %v", err) | ||||||||||
| logger.V(consts.LogLevelError).Error(nil, err.Error()) | ||||||||||
| if err := r.List(ctx, clusterPolicyList); err != nil { | ||||||||||
| err = fmt.Errorf("error getting ClusterPolicy list: %w", err) | ||||||||||
| logger.Error(err, "error getting ClusterPolicy list") | ||||||||||
|
||||||||||
| 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?
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.
Yeah, we can do that here as well. Updated the code.
Outdated
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?
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.
Yes, msg and error keys will have the same message. I updated it now to have different values. Here is what it will log now:
{"level":"error","ts":1762442249.3265705,"msg":"failed to get ClusterPolicy object","controller":"nvidia-driver-controller","object":{"name":"test1"},"namespace":"","name":"test1","reconcileID":"c1345edc-ac0c-4417-841f-d71f101c5071","error":"no ClusterPolicy object found in the cluster"}
{"level":"error","ts":1762442249.3296852,"msg":"Reconciler error","controller":"nvidia-driver-controller","object":{"name":"test1"},"namespace":"","name":"test1","reconcileID":"c1345edc-ac0c-4417-841f-d71f101c5071","error":"no ClusterPolicy object found in the cluster"}
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,7 +86,7 @@ func (r *UpgradeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct | |
| clusterPolicy := &gpuv1.ClusterPolicy{} | ||
| err := r.Get(ctx, req.NamespacedName, clusterPolicy) | ||
| if err != nil { | ||
| reqLogger.V(consts.LogLevelError).Error(err, "Error getting ClusterPolicy object") | ||
| reqLogger.Error(err, "Error getting ClusterPolicy object") | ||
| if clusterPolicyCtrl.operatorMetrics != nil { | ||
| clusterPolicyCtrl.operatorMetrics.reconciliationStatus.Set(reconciliationStatusClusterPolicyUnavailable) | ||
| } | ||
|
|
@@ -218,7 +218,7 @@ func (r *UpgradeReconciler) removeNodeUpgradeStateLabels(ctx context.Context) er | |
| delete(node.Labels, upgradeStateLabel) | ||
| err = r.Update(ctx, node) | ||
| if err != nil { | ||
| r.Log.V(consts.LogLevelError).Error( | ||
| r.Log.Error( | ||
|
||
| err, "Failed to reset upgrade state label from node", "node", node) | ||
| return err | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.