Skip to content

fix(operatorconditions): don't retry on 404 #2679

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 17 additions & 22 deletions pkg/controller/operators/operatorcondition_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,39 +93,34 @@ var _ reconcile.Reconciler = &OperatorConditionReconciler{}

func (r *OperatorConditionReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
// Set up a convenient log object so we don't have to type request over and over again
log := r.log.WithValues("request", req)
log.V(2).Info("reconciling operatorcondition")
log := r.log.WithValues("request", req).V(1)
Copy link
Member Author

Choose a reason for hiding this comment

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

V(1) is debug level for the underlying logr implementation, zapr.

Copy link
Collaborator

Choose a reason for hiding this comment

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

lol - of course it is. Why would you call it...Debug...?

Copy link
Member

Choose a reason for hiding this comment

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

logr doesn't have named levels, really. It has error logs and info logs. info logs can have varying degrees of importance, so the number reflects the verbosity. Higher number = higher verbosity.

However logr is just an interface. There's an implementation of this interface for all the major logging libraries, so if the underlying implementation has named levels, they end up being mapped to a verbosity number in logr.

Copy link
Member

Choose a reason for hiding this comment

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

Also... in logr, the verbosity is additive. So log.V(1).V(1) is the same as log.V(2), It's somewhat misleading to say log.V(1) is equivalent to Debug since it depends on what the base verbosity of log is.

Copy link
Member Author

@njhale njhale Mar 2, 2022

Choose a reason for hiding this comment

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

Yeah, I'm not sure I'm a huge fan of the logr api from a user perspective.

I'll try to look for some more examples of this being used in the wild. Maybe there's some wrapper/conventions around setting the level that we're missing.

log.Info("reconciling")
metrics.EmitOperatorConditionReconcile(req.Namespace, req.Name)

operatorCondition := &operatorsv2.OperatorCondition{}
err := r.Client.Get(context.TODO(), req.NamespacedName, operatorCondition)
if err != nil {
log.V(1).Error(err, "Unable to find operatorcondition")
return ctrl.Result{}, err
if err := r.Client.Get(ctx, req.NamespacedName, operatorCondition); err != nil {
log.Info("Unable to find OperatorCondition")
Copy link
Member Author

Choose a reason for hiding this comment

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

.Error is always logged, regardless of level -- let the invoking controller log the error we bubble up, if any.

return ctrl.Result{}, client.IgnoreNotFound(err)
Copy link
Member Author

Choose a reason for hiding this comment

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

Non-nil errors returned from Reconcilers are always retried, regardless of the respective Result.

}

err = r.ensureOperatorConditionRole(operatorCondition)
if err != nil {
log.V(1).Error(err, "Error ensuring OperatorCondition Role")
return ctrl.Result{Requeue: true}, err
if err := r.ensureOperatorConditionRole(operatorCondition); err != nil {
log.Info("Error ensuring OperatorCondition Role")
return ctrl.Result{}, err
}

err = r.ensureOperatorConditionRoleBinding(operatorCondition)
if err != nil {
log.V(1).Error(err, "Error ensuring OperatorCondition RoleBinding")
return ctrl.Result{Requeue: true}, err
if err := r.ensureOperatorConditionRoleBinding(operatorCondition); err != nil {
log.Info("Error ensuring OperatorCondition RoleBinding")
return ctrl.Result{}, err
}

err = r.ensureDeploymentEnvVars(operatorCondition)
if err != nil {
log.V(1).Error(err, "Error ensuring OperatorCondition Deployment EnvVars")
return ctrl.Result{Requeue: true}, err
if err := r.ensureDeploymentEnvVars(operatorCondition); err != nil {
log.Info("Error ensuring OperatorCondition Deployment EnvVars")
return ctrl.Result{}, err
}

err = r.syncOperatorConditionStatus(operatorCondition)
if err != nil {
log.V(1).Error(err, "Error syncing OperatorCondition Status")
return ctrl.Result{Requeue: true}, err
if err := r.syncOperatorConditionStatus(operatorCondition); err != nil {
log.Info("Error syncing OperatorCondition Status")
return ctrl.Result{}, err
}

return ctrl.Result{}, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,13 @@ var _ reconcile.Reconciler = &OperatorConditionGeneratorReconciler{}

func (r *OperatorConditionGeneratorReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
// Set up a convenient log object so we don't have to type request over and over again
log := r.log.WithValues("request", req)
log := r.log.WithValues("request", req).V(1)
metrics.EmitOperatorConditionGeneratorReconcile(req.Namespace, req.Name)

in := &operatorsv1alpha1.ClusterServiceVersion{}
err := r.Client.Get(context.TODO(), req.NamespacedName, in)
if err != nil {
log.V(1).Error(err, "Unable to find ClusterServiceVersion")
return ctrl.Result{}, err
if err := r.Client.Get(ctx, req.NamespacedName, in); err != nil {
log.Info("Unable to find ClusterServiceVersion")
return ctrl.Result{}, client.IgnoreNotFound(err)
}

operatorCondition := &operatorsv2.OperatorCondition{
Expand All @@ -113,10 +112,9 @@ func (r *OperatorConditionGeneratorReconciler) Reconcile(ctx context.Context, re
}
ownerutil.AddOwner(operatorCondition, in, false, true)

err = r.ensureOperatorCondition(*operatorCondition)
if err != nil {
log.V(1).Error(err, "Error ensuring ClusterServiceVersion")
return ctrl.Result{Requeue: true}, err
if err := r.ensureOperatorCondition(*operatorCondition); err != nil {
log.Info("Error ensuring OperatorCondition")
return ctrl.Result{}, err
}

return ctrl.Result{}, nil
Expand Down