k8s

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultLockTTL       = time.Second * 0 // unlimited
	DefaultRetryInterval = time.Second
)

Variables

View Source
var (
	ErrNoLeader        = dsync.ErrNoLeader
	ErrNotFound        = dsync.ErrNotFound
	ErrAlreadyLocked   = dsync.ErrAlreadyLocked
	ErrLeaseNotFound   = errors.New("resource lease not found")
	ErrUpdateLeaseFail = errors.New("resource lease update failed")
	ErrCreateLeaseFail = errors.New("resource lease create failed")
	ErrNotLockHolder   = dsync.ErrNotLockHolder
	ErrNotLocked       = dsync.ErrNotLocked
)

Functions

This section is empty.

Types

type Election

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

func NewElection

func NewElection(
	ctx context.Context,
	client LeaseClient,
	r dsync.Resource,
	candidate string,
	callbacks ...LeaderCallbacks,
) (*Election, error)

func (*Election) Candidate

func (e *Election) Candidate() string

func (*Election) Err

func (e *Election) Err() error

func (*Election) GetLeader

func (e *Election) GetLeader() string

func (*Election) IsLeader

func (e *Election) IsLeader() bool

func (*Election) Resource

func (e *Election) Resource() dsync.Resource

func (*Election) Stop

func (e *Election) Stop()

func (*Election) WhenElected

func (e *Election) WhenElected(fn func(context.Context))

type Elector

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

func NewLeaderElector

func NewLeaderElector(
	ctx context.Context,
	client LeaseClient,
	r dsync.Resource,
	candidate string,
	callbacks ...LeaderCallbacks,
) (*Elector, error)

func (Elector) GetLeader

func (e Elector) GetLeader() string

GetLeader will return the current leader if the election has not completed it returns empty string

func (Elector) IsLeader

func (e Elector) IsLeader() bool

IsLeader will tell you if you are the leader right now however you could become the new leader at any moment

func (Elector) Task

func (e Elector) Task() string

type Kube

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

func New

func New(opts ...KubeOpt) (*Kube, error)

func (Kube) GetLeader

func (k Kube) GetLeader(ctx context.Context, r dsync.Resource) (string, error)

func (Kube) GetLease

func (k Kube) GetLease(ctx context.Context, namespace, name string) (*v1.Lease, error)

func (Kube) GetLock

func (k Kube) GetLock(ctx context.Context, r dsync.Resource, requester string) (*Lock, error)

func (Kube) NewElection

func (k Kube) NewElection(
	ctx context.Context,
	r dsync.Resource,
	candidate string,
	callbacks ...LeaderCallbacks,
) (*Election, error)

type KubeOpt

type KubeOpt func(k *Kube)

func KubeWithCS

func KubeWithCS(cs kubernetes.Interface) KubeOpt

func KubeWithKCP

func KubeWithKCP(kcp string) KubeOpt

func KubeWithLockTTL

func KubeWithLockTTL(d time.Duration) KubeOpt

type LeaderCallbacks

type LeaderCallbacks struct {
	// OnStartedLeading is called when a LeaderElector client starts leading
	OnStartedLeading func(context.Context)
	// OnStoppedLeading is called when a LeaderElector client stops leading
	OnStoppedLeading func()
	// OnNewLeader is called when the client observes a leader that is
	// not the previously observed leader. This includes the first observed
	// leader when the client starts.
	OnNewLeader func(identity string)
}

LeaderCallbacks callbacks that are triggered during certain lifecycle events This is copied directly out of k8s.io/client-go/tools/leaderelection

type Lock

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

func NewLock

func NewLock(
	ctx context.Context, lc LeaseClient,
	r dsync.Resource, pod string, opts ...LockOption,
) (*Lock, error)

func (*Lock) Holder

func (l *Lock) Holder() string

func (*Lock) Lock

func (l *Lock) Lock() error

func (*Lock) LockContext

func (l *Lock) LockContext(ctx context.Context) error

func (*Lock) Pod

func (l *Lock) Pod() string

func (*Lock) Resource

func (l *Lock) Resource() dsync.Resource

func (*Lock) TryLock

func (l *Lock) TryLock() error

func (*Lock) Unlock

func (l *Lock) Unlock() error

type LockOption

type LockOption func(*Lock)

func LockWithRetryInterval

func LockWithRetryInterval(d time.Duration) LockOption

func LockWithTTL

func LockWithTTL(d time.Duration) LockOption

Jump to

Keyboard shortcuts

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