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

health support RequeueAfter #1666

Merged
merged 2 commits into from
Jun 30, 2023
Merged
Changes from 1 commit
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
38 changes: 25 additions & 13 deletions pkg/controller/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,15 +294,27 @@ func (c *Controller) processNextHealthCheckItem() bool {
return nil
}
klog.V(2).Infof("Key from healthCheckQueue: %s", key)
// Run the syncHandler, passing it the namespace/name string of the
// Tenant resource to be synced.
if err := c.syncHealthCheckHandler(key); err != nil {

result, err := c.syncHealthCheckHandler(key)
switch {
case err != nil:
c.workqueue.AddRateLimited(key)
return fmt.Errorf("error checking health check '%s': %s", key, err.Error())
case result.RequeueAfter > 0:
// The result.RequeueAfter request will be lost, if it is returned
// along with a non-nil error. But this is intended as
// We need to drive to stable reconcile loops before queuing due
// to result.RequestAfter
c.workqueue.Forget(obj)
c.workqueue.AddAfter(key, result.RequeueAfter)
case result.Requeue:
c.workqueue.AddRateLimited(key)
default:
// Finally, if no error occurs we Forget this item so it does not
// get queued again until another change happens.
c.workqueue.Forget(obj)
klog.V(4).Infof("Successfully health checked '%s'", key)
}
// Finally, if no error occurs we Forget this item so it does not
// get queued again until another change happens.
c.healthCheckQueue.Forget(obj)
klog.V(4).Infof("Successfully health checked '%s'", key)
return nil
}

Expand All @@ -314,11 +326,11 @@ func (c *Controller) processNextHealthCheckItem() bool {
}

// syncHealthCheckHandler acts on work items from the healthCheckQueue
func (c *Controller) syncHealthCheckHandler(key string) error {
func (c *Controller) syncHealthCheckHandler(key string) (Result, error) {
// Convert the namespace/name string into a distinct namespace and name
if key == "" {
runtime.HandleError(fmt.Errorf("Invalid resource key: %s", key))
return nil
return WrapResult(Result{}, nil)
}

namespace, tenantName := key2NamespaceName(key)
Expand All @@ -329,17 +341,17 @@ func (c *Controller) syncHealthCheckHandler(key string) error {
// The Tenant resource may no longer exist, in which case we stop processing.
if k8serrors.IsNotFound(err) {
runtime.HandleError(fmt.Errorf("Tenant '%s' in work queue no longer exists", key))
return nil
return WrapResult(Result{}, nil)
}
return err
return WrapResult(Result{}, err)
}

tenant.EnsureDefaults()

if err = c.updateHealthStatusForTenant(tenant); err != nil {
klog.Errorf("%v", err)
return err
return WrapResult(Result{}, err)
}

return nil
return WrapResult(Result{}, nil)
}