Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Callbacks ¶
type Callbacks struct {
// OnStartedLeading is called when the instance becomes the leader
OnStartedLeading func(ctx context.Context)
// OnStoppedLeading is called when the instance stops being the leader
OnStoppedLeading func()
// OnNewLeader is called when a new leader is observed (may be self or another instance)
OnNewLeader func(identity string)
}
Callbacks contains callback functions for leader election events.
type Config ¶
type Config struct {
// Enabled determines if leader election is active
Enabled bool
// Identity is the unique identifier of this instance (usually pod name)
Identity string
// LeaseName is the name of the Lease resource
LeaseName string
// LeaseNamespace is the namespace of the Lease resource
LeaseNamespace string
// LeaseDuration is the duration that non-leader candidates will wait to force acquire leadership
LeaseDuration time.Duration
// RenewDeadline is the duration that the acting leader will retry refreshing leadership before giving up
RenewDeadline time.Duration
// RetryPeriod is the duration the LeaderElector clients should wait between tries of actions
RetryPeriod time.Duration
// ReleaseOnCancel should be true to release leadership when the context is cancelled
ReleaseOnCancel bool
}
Config contains configuration for leader election.
type Elector ¶
type Elector struct {
// contains filtered or unexported fields
}
Elector manages leader election using Kubernetes Lease resources.
This is a pure component that wraps k8s.io/client-go/tools/leaderelection with a clean interface. It has no dependencies on the event bus or controller coordination logic.
func New ¶
func New( config *Config, clientset kubernetes.Interface, callbacks Callbacks, logger *slog.Logger, ) (*Elector, error)
New creates a new leader elector.
The elector is not started until Start() is called.
func (*Elector) GetLeader ¶
GetLeader returns the identity of the current leader.
Returns empty string if no leader has been observed yet.
Click to show internal directories.
Click to hide internal directories.