Skip to content

Commit

Permalink
Reduce log volume of operator
Browse files Browse the repository at this point in the history
  • Loading branch information
timebertt committed Sep 5, 2023
1 parent 39f4d64 commit 76a147c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions webhosting-operator/pkg/controllers/webhosting/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,26 @@ limitations under the License.
package webhosting

import (
"context"

apierrors "k8s.io/apimachinery/pkg/api/errors"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)

const fieldOwner = client.FieldOwner("webhosting-operator")

// SilenceConflicts wraps a reconciler to not return conflict errors. The requests is requeued with exponential backoff
// as if an error was returned but the error will not be logged.
func SilenceConflicts(r reconcile.Reconciler) reconcile.Reconciler {
return reconcile.Func(func(ctx context.Context, request reconcile.Request) (reconcile.Result, error) {
result, err := r.Reconcile(ctx, request)
if apierrors.IsConflict(err) {
result.Requeue = true
// RequeueAfter takes precedence over Requeue, set it to zero in case it was returned alongside a conflict error
result.RequeueAfter = 0
err = nil
}
return result, err
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ func (r *WebsiteReconciler) SetupWithManager(mgr ctrl.Manager) error {
WithOptions(controller.Options{
MaxConcurrentReconciles: 5,
}).
Build(r)
Build(SilenceConflicts(r))
if err != nil {
return err
}
Expand Down

0 comments on commit 76a147c

Please sign in to comment.