Documentation ¶
Index ¶
- Constants
- Variables
- func SanitizeName(in string) string
- type Driver
- type Dsync
- type Election
- type ElectionDriver
- type ElectionID
- type Interface
- type Lock
- func (l Lock) DoWithLock(ctx context.Context, f func() error) error
- func (l Lock) DoWithTryLock(ctx context.Context, f func() error) error
- func (l Lock) Err() error
- func (l Lock) Lock() error
- func (l Lock) LockContext(ctx context.Context) error
- func (l Lock) Resource() Resource
- func (l Lock) TryLock() error
- func (l Lock) Unlock() error
- type LockDriver
- type LockID
- type Logger
- type PodID
- type Resource
- type ResourceName
- type Term
Constants ¶
const ( DefaultNamespace = configs.DefNamespace DefaultScope = configs.DefLeaseScope MasterTask = "master" )
const NamePattern = `^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$`
NamePattern is enforced kubernetes on lease names. https://regex101.com/r/9zbjQ0/1 example: kebab-case-with-0-9.seperated-by-dots
Matches a domain-like string that: - Starts and ends with an alphanumeric character (a-z0-9). - Can have multiple segments separated by dots (.). - Each segment must start and end with an alphanumeric character and may contain hyphens in between. - Supports optional subdomains or multiple levels. Examples that match: - example - example.com - sub.domain.com - a1-b2.c3-d4 Examples that don’t match: - .example (starts with a dot) - example. (ends with a dot) - ex..ample (consecutive dots)
Variables ¶
var ( ErrBadResourceName = errors.New("bad resource scope or name") ErrInvalidState = errors.New("invalid state") ErrLockNotFound = errors.New("lock not found") ErrNoLeader = errors.New("no leader right now") ErrNotFound = errors.New("resource not found") ErrAlreadyLocked = errors.New("resource is already locked") ErrNotLockHolder = errors.New("resource locked by someone else") ErrNotLocked = errors.New("resource not locked") )
Functions ¶
func SanitizeName ¶
Types ¶
type Driver ¶
type Driver interface { Resource(string) Resource GetLock(context.Context, ResourceName, PodID) (LockDriver, error) GetElection(context.Context, ResourceName, PodID) (ElectionDriver, error) }
type Dsync ¶
type Dsync struct {
// contains filtered or unexported fields
}
func (Dsync) NewElection ¶
NewElection will return an Election if there is an error or not the returned election will simply no-op in case of an error
func (Dsync) NewLock ¶
NewLock constructs and returns a Lock if there is any error with the Lock itself then the methods on Lock will return them therefore no need to return the error here if you want to check the error yourself use Lock.Err()
func (Dsync) SanitizeName ¶
SanitizeName returns a valid resource name the best it can upper case letters will be made lower case special chars will be converted to dashes and dashes will be trimmed from start and end
type Election ¶
type Election struct {
// contains filtered or unexported fields
}
func (Election) WhenElected ¶
type ElectionDriver ¶
type ElectionID ¶
type ElectionID = string
type LockDriver ¶
type Resource ¶
func NewResource ¶
func NewScopedResource ¶
func ToResource ¶
func (Resource) ElectionName ¶
type ResourceName ¶
type ResourceName = string