mirror of
https://github.com/stakater/Reloader.git
synced 2026-04-20 17:06:47 +00:00
Add leadership election
This commit is contained in:
@@ -2,9 +2,10 @@ package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/stakater/Reloader/internal/pkg/options"
|
||||
"time"
|
||||
|
||||
"github.com/stakater/Reloader/internal/pkg/options"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/stakater/Reloader/internal/pkg/handler"
|
||||
"github.com/stakater/Reloader/internal/pkg/metrics"
|
||||
@@ -29,6 +30,7 @@ type Controller struct {
|
||||
namespace string
|
||||
ignoredNamespaces util.List
|
||||
collectors metrics.Collectors
|
||||
isLeader bool
|
||||
}
|
||||
|
||||
// controllerInitialized flag determines whether controlled is being initialized
|
||||
@@ -56,6 +58,7 @@ func NewController(
|
||||
c.informer = informer
|
||||
c.queue = queue
|
||||
c.collectors = collectors
|
||||
c.isLeader = true
|
||||
return &c, nil
|
||||
}
|
||||
|
||||
@@ -140,7 +143,7 @@ func (c *Controller) processNextItem() bool {
|
||||
defer c.queue.Done(resourceHandler)
|
||||
|
||||
// Invoke the method containing the business logic
|
||||
err := resourceHandler.(handler.ResourceHandler).Handle()
|
||||
err := resourceHandler.(handler.ResourceHandler).Handle(c.isLeader)
|
||||
// Handle the error if something went wrong during the execution of the business logic
|
||||
c.handleErr(err, resourceHandler)
|
||||
return true
|
||||
@@ -171,3 +174,7 @@ 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user