election

package
v0.0.30 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateLeaderIdentity

func GenerateLeaderIdentity() string

GenerateLeaderIdentity generates a string used for leader identity in the leader election process, this identity will be mostly the hostname, or if for some reason that cannot be fetched a random string.

func RunElection

func RunElection(
	ctx context.Context,
	leaderElectionIdentity string,
	lock *ClabernetesLeaseLock,
	timers Timers,
	startLeading func(c context.Context),
	stopLeading func(),
	newLeader func(newLeaderIdentity string),
)

RunElection runs the leader election process executing the provided callbacks for OnStartedLeading and OnStoppedLeading when those events happen.

Types

type ClabernetesLeaseLock

type ClabernetesLeaseLock struct {
	*resourcelock.LeaseLock
	// contains filtered or unexported fields
}

ClabernetesLeaseLock wraps resourcelock.LeaseLock Create method and adds labels to the created lease.

func GetLeaseLock

func GetLeaseLock(
	client *kubernetes.Clientset,
	appName, namespace, lockName, leaderIdentity string,
) *ClabernetesLeaseLock

GetLeaseLock returns a LeaseLock object for the given namespace/lock name/identity.

func (*ClabernetesLeaseLock) Create

Create calls the embedded resourcelock.LeaseLock Create method and then adds labels to the newly created lease.

type Timers

type Timers struct {
	// Duration of the leader election lease.
	Duration time.Duration
	// RenewDeadline for renewing leader election lease.
	RenewDeadline time.Duration
	// RetryPeriod window for leader election lease retries.
	RetryPeriod time.Duration
}

Timers holds duration values for leader election/lease.

Jump to

Keyboard shortcuts

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