component

package
v0.0.0-...-8aa1e91 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 24, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LeaderComponentAddAfterStartErr = errors.New("cannot add leader component after component manager is started")

Functions

This section is empty.

Types

type Component

type Component interface {
	// Start blocks until the channel is closed or an error occurs.
	// The component will stop running when the channel is closed.
	Start(<-chan struct{}) error

	// NeedLeaderElection indicates if component should be run only by one instance of Control Plane even with many Control Plane replicas.
	NeedLeaderElection() bool
}

Component defines a process that will be run in the application Component should be designed in such a way that it can be stopped by stop channel and started again (for example when instance is reelected for a leader).

func NewResilientComponent

func NewResilientComponent(log logr.Logger, component Component) Component

type ComponentFunc

type ComponentFunc func(<-chan struct{}) error

func (ComponentFunc) NeedLeaderElection

func (f ComponentFunc) NeedLeaderElection() bool

func (ComponentFunc) Start

func (f ComponentFunc) Start(stop <-chan struct{}) error

type GracefulComponent

type GracefulComponent interface {
	Component

	// WaitForDone blocks until all components are done.
	// If a component was not started (i.e. leader components on non-leader CP) it returns immediately.
	WaitForDone()
}

GracefulComponent is a component that supports waiting until it's finished. It's useful if there is cleanup logic that has to be executed before the process exits (i.e. sending SIGTERM signals to subprocesses started by this component).

type LeaderCallbacks

type LeaderCallbacks struct {
	OnStartedLeading func()
	OnStoppedLeading func()
}

LeaderCallbacks defines callbacks for events from LeaderElector It is guaranteed that each methods will be executed from the same goroutine, so only one method can be run at once.

type LeaderComponentFunc

type LeaderComponentFunc func(<-chan struct{}) error

func (LeaderComponentFunc) NeedLeaderElection

func (f LeaderComponentFunc) NeedLeaderElection() bool

func (LeaderComponentFunc) Start

func (f LeaderComponentFunc) Start(stop <-chan struct{}) error

type LeaderElector

type LeaderElector interface {
	AddCallbacks(LeaderCallbacks)
	// IsLeader should be used for diagnostic reasons (metrics/API info), because there may not be any leader elector for a short period of time.
	// Use Callbacks to write logic to execute when Leader is elected.
	IsLeader() bool

	// Start blocks until the channel is closed or an error occurs.
	Start(stop <-chan struct{})
}

type LeaderInfo

type LeaderInfo interface {
	IsLeader() bool
}

type LeaderInfoComponent

type LeaderInfoComponent struct {
	// contains filtered or unexported fields
}

func (*LeaderInfoComponent) IsLeader

func (p *LeaderInfoComponent) IsLeader() bool

func (*LeaderInfoComponent) NeedLeaderElection

func (l *LeaderInfoComponent) NeedLeaderElection() bool

func (*LeaderInfoComponent) Start

func (l *LeaderInfoComponent) Start(stop <-chan struct{}) error

type Manager

type Manager interface {
	// Add registers a component, i.e. gRPC Server, HTTP server, reconciliation loop.
	Add(...Component) error

	// Start starts registered components and blocks until the Stop channel is closed.
	// Returns an error if there is an error starting any component.
	// If there are any GracefulComponent, it waits until all components are done.
	Start(<-chan struct{}) error
}

func NewManager

func NewManager(leaderElector LeaderElector) Manager

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL