leaderelection

package
v0.21.4 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadClusterConfig

func LoadClusterConfig(ctx *armadacontext.Context) (*rest.Config, error)

LoadClusterConfig loads Kubernetes cluster configuration. It attempts to use in-cluster config first, falling back to kubeconfig if not running in a cluster.

Types

type Config

type Config struct {
	// Mode specifies the leader election mode. Valid modes are "standalone" or "kubernetes".
	Mode Mode `validate:"required"`
	// LeaseLockName is the name of the Kubernetes Lock Object.
	LeaseLockName string
	// LeaseLockNamespace is the namespace of the Kubernetes Lock Object.
	LeaseLockNamespace string
	// LeaseDuration is how long the lease is held for.
	// Non-leaders must wait this long before trying to acquire the lease.
	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
	// PodName is the name of the pod.
	PodName string
	// Connection details to the leader
	LeaderConnection client.ApiConnectionDetails
}

Config holds the leader election configuration parameters.

type KubernetesLeaderController

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

KubernetesLeaderController uses the Kubernetes leader election mechanism to determine who is leader. This allows multiple instances of the scheduler to be run for high availability.

TODO: Move into package in common.

func NewKubernetesLeaderController

func NewKubernetesLeaderController(config Config, client coordinationv1client.LeasesGetter) *KubernetesLeaderController

func (*KubernetesLeaderController) GetLeaderReport

func (lc *KubernetesLeaderController) GetLeaderReport() LeaderReport

func (*KubernetesLeaderController) GetToken

func (lc *KubernetesLeaderController) GetToken() LeaderToken

func (*KubernetesLeaderController) RegisterListener

func (lc *KubernetesLeaderController) RegisterListener(listener LeaseListener)

func (*KubernetesLeaderController) Run

Run starts the controller. This is a blocking call that returns when the provided context is cancelled.

func (*KubernetesLeaderController) ValidateToken

func (lc *KubernetesLeaderController) ValidateToken(tok LeaderToken) bool

type LeaderClientConnectionProvider

type LeaderClientConnectionProvider interface {
	GetCurrentLeaderClientConnection() (bool, *grpc.ClientConn, error)
}

type LeaderConnectionProvider

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

func NewLeaderConnectionProvider

func NewLeaderConnectionProvider(leaderController LeaderController, leaderConfig Config, metrics *grpc_prometheus.ClientMetrics) *LeaderConnectionProvider

func (*LeaderConnectionProvider) GetCurrentLeaderClientConnection

func (l *LeaderConnectionProvider) GetCurrentLeaderClientConnection() (bool, *grpc.ClientConn, error)

type LeaderController

type LeaderController interface {
	// GetToken returns a LeaderToken which allows you to determine if you are leader or not
	GetToken() LeaderToken
	// ValidateToken allows a caller to determine whether a previously obtained token is still valid.
	// Returns true if the token is a leader and false otherwise
	ValidateToken(tok LeaderToken) bool
	// Run starts the controller.  This is a blocking call which will return when the provided context is cancelled
	Run(ctx *armadacontext.Context) error
	// GetLeaderReport returns a report about the current leader
	GetLeaderReport() LeaderReport
}

LeaderController is an interface to be implemented by structs that control which scheduler is leader

func CreateLeaderController

func CreateLeaderController(ctx *armadacontext.Context, config Config, metricsOptions *MetricsOptions) (LeaderController, error)

CreateLeaderController creates a leader controller based on the provided config and options. It returns a LeaderController interface for managing leader election.

type LeaderReport

type LeaderReport struct {
	IsCurrentProcessLeader bool
	LeaderName             string
}

type LeaderStatusMetricsCollector

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

func NewLeaderStatusMetricsCollector

func NewLeaderStatusMetricsCollector(metricsPrefix string, currentInstanceName string) *LeaderStatusMetricsCollector

func (*LeaderStatusMetricsCollector) Collect

func (l *LeaderStatusMetricsCollector) Collect(metrics chan<- prometheus.Metric)

func (*LeaderStatusMetricsCollector) Describe

func (l *LeaderStatusMetricsCollector) Describe(desc chan<- *prometheus.Desc)

func (*LeaderStatusMetricsCollector) MarkAsLeading

func (l *LeaderStatusMetricsCollector) MarkAsLeading()

MarkAsLeading sets the leader status to true. Used in standalone mode where the instance is always the leader.

type LeaderToken

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

LeaderToken is a token handed out to schedulers which they can use to determine if they are leader

func InvalidLeaderToken

func InvalidLeaderToken() LeaderToken

InvalidLeaderToken returns a LeaderToken indicating this instance is not leader.

func NewLeaderToken

func NewLeaderToken() LeaderToken

NewLeaderToken returns a LeaderToken indicating this instance is the leader.

func (LeaderToken) Leader

func (l LeaderToken) Leader() bool

type LeaseListener

type LeaseListener interface {
	// contains filtered or unexported methods
}

LeaseListener allows clients to listen for lease eventSequences.

type MetricsOptions

type MetricsOptions struct {
	// MetricsPrefix is the prefix for Prometheus metrics.
	MetricsPrefix string
	// MarkLeadingInStandaloneMode specifies whether to mark the instance as leading in standalone mode.
	MarkLeadingInStandaloneMode bool
}

MetricsOptions holds configuration options for leader election behavior.

type Mode

type Mode string
const (
	ModeStandalone Mode = "standalone"
	ModeKubernetes Mode = "kubernetes"
)

func (Mode) Validate

func (m Mode) Validate() error

type StandaloneLeaderController

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

StandaloneLeaderController returns a token that always indicates you are leader This can be used when only a single instance of the scheduler is needed

func NewStandaloneLeaderController

func NewStandaloneLeaderController() *StandaloneLeaderController

func (*StandaloneLeaderController) GetLeaderReport

func (lc *StandaloneLeaderController) GetLeaderReport() LeaderReport

func (*StandaloneLeaderController) GetToken

func (lc *StandaloneLeaderController) GetToken() LeaderToken

func (*StandaloneLeaderController) Run

func (*StandaloneLeaderController) SetToken

func (lc *StandaloneLeaderController) SetToken(token LeaderToken)

func (*StandaloneLeaderController) ValidateToken

func (lc *StandaloneLeaderController) ValidateToken(tok LeaderToken) bool

Jump to

Keyboard shortcuts

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