Shutdown on leader election loss

This commit is contained in:
Alex Vest
2022-09-15 12:09:15 +01:00
parent 16079bd1d4
commit 919f75bb62
5 changed files with 37 additions and 43 deletions

View File

@@ -30,7 +30,6 @@ type Controller struct {
namespace string
ignoredNamespaces util.List
collectors metrics.Collectors
isLeader bool
}
// controllerInitialized flag determines whether controlled is being initialized
@@ -58,7 +57,7 @@ func NewController(
c.informer = informer
c.queue = queue
c.collectors = collectors
c.isLeader = true
logrus.Infof("created controller for: %s", resource)
return &c, nil
}
@@ -143,7 +142,7 @@ func (c *Controller) processNextItem() bool {
defer c.queue.Done(resourceHandler)
// Invoke the method containing the business logic
err := resourceHandler.(handler.ResourceHandler).Handle(c.isLeader)
err := resourceHandler.(handler.ResourceHandler).Handle()
// Handle the error if something went wrong during the execution of the business logic
c.handleErr(err, resourceHandler)
return true
@@ -174,8 +173,3 @@ func (c *Controller) handleErr(err error, key interface{}) {
runtime.HandleError(err)
logrus.Infof("Dropping the key %q out of the queue: %v", key, err)
}
func (c *Controller) SetLeader(isLeader bool) {
c.isLeader = isLeader
logrus.Info("controller active")
}