Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Controller ¶
type Controller interface { Start(ctx context.Context) error RequiresLeaderElection() bool Name() string }
Controller is implemented by all controllers inside controllers directory. They should be able to be started, have a name, and to inform if they need or not to be run only after a leader election.
type Starter ¶
type Starter struct {
// contains filtered or unexported fields
}
Starter provides facilities around starting Controllers. Leader election logic is embed into this entity.
func New ¶
func New(corcli corecli.Interface, ctrls ...Controller) *Starter
New returns a new controller starter. We read some env variables directly here and fall back to default values if they are not set.
func (*Starter) OnStartedLeading ¶
OnStartedLeading is called when we start being the leader of the pack. Goes through all controllers and start the ones that require a leader lease in place to run. Each controller is started in its own goroutine.
func (*Starter) OnStoppedLeading ¶
func (s *Starter) OnStoppedLeading()
OnStoppedLeading awaits for all running controllers to end before returning. As we don't know exactly why we are not the leader anymore we just cancel our internal context and wait for all the Controllers to finish before returning.
func (*Starter) Start ¶
Start starts all controllers within a Starter. This function only returns when all controllers have finished their job, i.e. provided context has been cancelled or the leader lease has been lost. lockID holds an arbitrary ID for the binary calling this function, it is used as config map name during leader election.