-
Notifications
You must be signed in to change notification settings - Fork 43
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
refactor: refactor the logs of lvmcluster controller #137
Conversation
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.
- general observation, do we need to log error/info in both call and execution site (ex:
getRunningPodImage
)? - it seems PR increased number of info level logs, (ex:
openshiftsccs
) - when we debug issues, we first jump into error site and go up the stack and logging similar errors may not be helpful always (this is only my opinion)
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.
Can you post the before and after logs for the operator so we can see what the changes look like?
controllers/lvmcluster_controller.go
Outdated
@@ -183,7 +186,8 @@ func (r *LVMClusterReconciler) reconcile(ctx context.Context, instance *lvmv1alp | |||
for _, unit := range resourceCreationList { | |||
err := unit.ensureCreated(r, ctx, instance) | |||
if err != nil { | |||
return ctrl.Result{}, fmt.Errorf("failed reconciling: %s %w", unit.getName(), err) | |||
r.Log.Error(err, "failed reconciling", "Resource", unit.getName()) |
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.
This is actually changing the error being returned, right?
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 I know, We should return an original error IMO as that can be used to determine the error in the caller's place.
controllers/lvmcluster_controller.go
Outdated
} | ||
|
||
pod := &corev1.Pod{} | ||
if err := r.Get(ctx, types.NamespacedName{Name: podName, Namespace: r.Namespace}, pod); err != nil { | ||
return fmt.Errorf("failed to get pod %s in namespace %s", podName, r.Namespace) | ||
r.Log.Error(err, "Failed to get pod.") |
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.
Will this include information about the pod that was requested?
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 error will have it, This is the error which gets generated pods "test" not found
when I ran the below code.
pod := &corev1.Pod{}
err = fakeReconciler.Client.Get(context.TODO(), types.NamespacedName{Name: "test", Namespace: "test"}, pod)
fmt.Println(err)
|
Can the following be done?
|
f7db3db
to
097c59a
Compare
made most of the changes, pls take a look. |
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.
minor comments.
@@ -324,10 +340,11 @@ func (r *LVMClusterReconciler) getRunningPodImage(ctx context.Context) error { | |||
} | |||
} | |||
|
|||
return fmt.Errorf("failed to get container image for %s in pod %s", LVMOperatorContainerName, podName) | |||
err := fmt.Errorf("failed to get container image for %s in pod %s", LVMOperatorContainerName, podName) | |||
r.Log.Error(err, "container image not found") |
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.
- we need
LVMOperatorContainerName
in log as well to know we are looking for correct container or not
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.
We already have if you see above created err.
controllers/lvmcluster_controller.go
Outdated
} | ||
|
||
pod := &corev1.Pod{} | ||
if err := r.Get(ctx, types.NamespacedName{Name: podName, Namespace: r.Namespace}, pod); err != nil { | ||
return fmt.Errorf("failed to get pod %s in namespace %s", podName, r.Namespace) | ||
r.Log.Error(err, "failed to get pod") |
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.
- better log at-least pod name
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.
agree
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.
err will have it, but still i added in the logs again.
controllers/lvmcluster_controller.go
Outdated
@@ -183,7 +186,8 @@ func (r *LVMClusterReconciler) reconcile(ctx context.Context, instance *lvmv1alp | |||
for _, unit := range resourceCreationList { | |||
err := unit.ensureCreated(r, ctx, instance) | |||
if err != nil { | |||
return ctrl.Result{}, fmt.Errorf("failed reconciling: %s %w", unit.getName(), err) | |||
r.Log.Error(err, "failed reconciling", "resource", unit.getName()) |
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.
r.Log.Error(err, "failed reconciling", "resource", unit.getName()) | |
r.Log.Error(err, "failed to reconcile", "resource", unit.getName()) |
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.
done
controllers/lvmcluster_controller.go
Outdated
} | ||
|
||
pod := &corev1.Pod{} | ||
if err := r.Get(ctx, types.NamespacedName{Name: podName, Namespace: r.Namespace}, pod); err != nil { | ||
return fmt.Errorf("failed to get pod %s in namespace %s", podName, r.Namespace) | ||
r.Log.Error(err, "failed to get pod") |
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.
agree
@@ -52,14 +52,16 @@ func (c openshiftSccs) ensureCreated(r *LVMClusterReconciler, ctx context.Contex | |||
r.Log.Info("creating SecurityContextConstraint", "SecurityContextConstraint", scc.Name) | |||
_, err := r.SecurityClient.SecurityContextConstraints().Create(ctx, scc, metav1.CreateOptions{}) | |||
if err != nil { | |||
return fmt.Errorf("failed to create SCC %q: %v", scc.Name, err) |
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.
Please include the scc name in the error and the log
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.
err will already have it, But I have added it again in the logs.
Signed-off-by: Nitin Goyal <[email protected]>
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.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: iamniting, leelavg, nbalacha The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Signed-off-by: Nitin Goyal [email protected]