Skip to content
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

Ignore reconcile errors that occur because a pod is being terminated #1233

Merged

Conversation

kevinearls
Copy link
Member

Signed-off-by: Kevin Earls [email protected]

This fixes #1219 by not logging errors that occur because we are trying to reconcile something in a namespace that is being terminated.

@kevinearls kevinearls marked this pull request as ready for review November 8, 2022 15:39
@kevinearls kevinearls requested a review from a team November 8, 2022 15:39
@@ -168,9 +169,12 @@ func (r *OpenTelemetryCollectorReconciler) Reconcile(ctx context.Context, req ct
func (r *OpenTelemetryCollectorReconciler) RunTasks(ctx context.Context, params reconcile.Params) error {
for _, task := range r.tasks {
if err := task.Do(ctx, params); err != nil {
r.log.Error(err, fmt.Sprintf("failed to reconcile %s", task.Name))
Copy link
Member

Choose a reason for hiding this comment

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

How often does this logline occur when a pod is terminated?

Copy link
Member Author

@kevinearls kevinearls Nov 9, 2022

Choose a reason for hiding this comment

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

Many. :-). Like for everything the reconciler touches. To be honest, it's not that big a deal, and probably something that will only be seen when running kuttl tests. But I found it very annoying, so I submitted the PR.

Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to end the reconciling with by returing nil if the reason is a terminating pod? That way the user gets informed that something did not work and we would get rid of all the unnecessary log lines?

@@ -168,6 +169,10 @@ func (r *OpenTelemetryCollectorReconciler) Reconcile(ctx context.Context, req ct
func (r *OpenTelemetryCollectorReconciler) RunTasks(ctx context.Context, params reconcile.Params) error {
for _, task := range r.tasks {
if err := task.Do(ctx, params); err != nil {
// If we get an error that occur because a pod is being terminated then exit this loop
if apierrors.IsForbidden(err) && strings.Contains(err.Error(), "because it is being terminated") {
Copy link
Member

Choose a reason for hiding this comment

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

one last thing, should we print the termination logline before? And maybe an extra hint, that we cancel the reconciliation?

Copy link
Member Author

Choose a reason for hiding this comment

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

@frzifus what log level should I print that at?

Copy link
Member

Choose a reason for hiding this comment

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

i thought maybe:

r.log.Error(err, fmt.Sprintf("failed to reconcile %s", task.Name))

And maybe an additional line that says that the reconciliation will be canceled?

Copy link
Member

Choose a reason for hiding this comment

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

I am a bit skeptical about checking the string because it is being terminated". This could easily change in the future

Copy link

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

@damemi Thanks!

Copy link
Member

@frzifus frzifus left a comment

Choose a reason for hiding this comment

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

up to the others

@kevinearls
Copy link
Member Author

@pavolloffay Can you merge this?

@@ -168,6 +168,11 @@ func (r *OpenTelemetryCollectorReconciler) Reconcile(ctx context.Context, req ct
func (r *OpenTelemetryCollectorReconciler) RunTasks(ctx context.Context, params reconcile.Params) error {
for _, task := range r.tasks {
if err := task.Do(ctx, params); err != nil {
// If we get an error that occurs because a pod is being terminated, then exit this loop
if apierrors.IsForbidden(err) && apierrors.HasStatusCause(err, corev1.NamespaceTerminatingCause) {
r.log.V(2).Info("Exiting reconcile loop because namespace", params.Instance.Namespace, "is being terminated")
Copy link

Choose a reason for hiding this comment

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

Suggested change
r.log.V(2).Info("Exiting reconcile loop because namespace", params.Instance.Namespace, "is being terminated")
r.log.V(2).Info("Exiting reconcile loop because namespace is being terminated", "namespace", params.Instance.Namespace)

(see https://pkg.go.dev/github.com/go-logr/logr#Logger.Info)

@kevinearls kevinearls requested a review from a team November 30, 2022 14:00
Copy link
Member

@secustor secustor left a comment

Choose a reason for hiding this comment

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

Linking issue #1291

@pavolloffay pavolloffay merged commit ce30a35 into open-telemetry:main Dec 1, 2022
@kevinearls kevinearls deleted the ignore-being-terminated-errors branch December 1, 2022 09:51
ihalaij1 pushed a commit to ihalaij1/opentelemetry-operator that referenced this pull request Dec 8, 2022
…pen-telemetry#1233)

* Ignore reconcile errors that occur because a pod is being terminated

Signed-off-by: Kevin Earls <[email protected]>

* Appease the all powerfull linter

Signed-off-by: Kevin Earls <[email protected]>

* Change behavior to end reconcile loop if pod has been terminated

Signed-off-by: Kevin Earls <[email protected]>

* Print a log message if we exit the reconciler loop

Signed-off-by: Kevin Earls <[email protected]>

* Look for NamespaceTerminatingCause

Signed-off-by: Kevin Earls <[email protected]>

* Appease the almighty linter

Signed-off-by: Kevin Earls <[email protected]>

* Fix log message

Signed-off-by: Kevin Earls <[email protected]>

* Skip flaky test

Signed-off-by: Kevin Earls <[email protected]>

Signed-off-by: Kevin Earls <[email protected]>
Co-authored-by: Ben B <[email protected]>
ItielOlenick pushed a commit to ItielOlenick/opentelemetry-operator that referenced this pull request May 1, 2024
…pen-telemetry#1233)

* Ignore reconcile errors that occur because a pod is being terminated

Signed-off-by: Kevin Earls <[email protected]>

* Appease the all powerfull linter

Signed-off-by: Kevin Earls <[email protected]>

* Change behavior to end reconcile loop if pod has been terminated

Signed-off-by: Kevin Earls <[email protected]>

* Print a log message if we exit the reconciler loop

Signed-off-by: Kevin Earls <[email protected]>

* Look for NamespaceTerminatingCause

Signed-off-by: Kevin Earls <[email protected]>

* Appease the almighty linter

Signed-off-by: Kevin Earls <[email protected]>

* Fix log message

Signed-off-by: Kevin Earls <[email protected]>

* Skip flaky test

Signed-off-by: Kevin Earls <[email protected]>

Signed-off-by: Kevin Earls <[email protected]>
Co-authored-by: Ben B <[email protected]>
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.

Log errors are created if we try to reconcile while a namespace is being deleted
5 participants