leases

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2016 License: Apache-2.0 Imports: 4 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// TimeFormat is the standard format that all lease expiration times are stored as in k8s
	// annotations
	TimeFormat = time.RFC3339
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrEncodeLease

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

ErrEncodeLease is an error implementation that's returned whenever a func failed to encode a lease into json

func (ErrEncodeLease) Error

func (e ErrEncodeLease) Error() string

Error is the error interface implementation

type ErrMalformedUUID

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

ErrMalformedUUID is an error implementation that's returned whenever a func failed to parse a UUID from plain text

func (ErrMalformedUUID) Error

func (m ErrMalformedUUID) Error() string

Error is the error interface implementation

type Lease

type Lease struct {
	ClusterName         string `json:"cluster_name"`
	LeaseExpirationTime string `json:"lease_expiration_time"`
}

Lease is the json-encodable struct that represents what's in the value of one lease annotation in k8s

func NewLease

func NewLease(clusterName string, exprTime time.Time) *Lease

NewLease creates a new lease with the given cluster name and expiration time

func ParseLease

func ParseLease(leaseStr string) (*Lease, error)

ParseLease decodes leaseStr from json into a Lease structure. Returns nil and any decoding error if there was one, and a valid lease and nil otherwise

func (Lease) ExpirationTime

func (l Lease) ExpirationTime() (time.Time, error)

ExpirationTime returns the expiration time of this lease, if l.LeaseExpirationTime was a well formed time string, returns the time and nil. Otherwise returns the zero value of time (i.e. t.IsZero() will return true) and a non-nil error

type Map

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

Map holds an in-memory representation of the set of leases written to k8s annotations. It can look up leases by lease token (which is a UUID) or cluster name

func ParseMapFromAnnotations

func ParseMapFromAnnotations(annotations map[string]string) (*Map, error)

ParseMapFromAnnotations parses a map of Kubernetes annotations into a lease map. Returns nil and an appropriate error if the parsing failed, non-nil and no error otherwise

func (*Map) CreateLease

func (m *Map) CreateLease(u uuid.UUID, l *Lease) bool

CreateLease attempts to set the given lease under the given uuid. If u already existed or l.ClusterName otherwise already has a lease associated with it, does nothing and returns false. Otherwise adds the lease to the map and returns true

func (*Map) DeleteLease

func (m *Map) DeleteLease(u uuid.UUID) bool

DeleteLease attempts to delete the lease under the given uuid. If there is no such lease, does nothing and returns false. Otherwise, completes the delete operation and returns true

func (Map) LeaseByClusterName

func (m Map) LeaseByClusterName(clusterName string) (*Lease, bool)

LeaseByClusterName finds a lease in m by the given cluster name. returns nil and false if no lease exists for the given cluster name, non-nil and true otherwise

func (Map) LeaseForUUID

func (m Map) LeaseForUUID(u uuid.UUID) (*Lease, bool)

LeaseForUUID looks up a lease for the given UUID. Returns nil and false if none was found, non-nil and true otherwise

func (*Map) ToAnnotations

func (m *Map) ToAnnotations() (map[string]string, error)

ToAnnotations returns a raw map[string]string of lease tokens and json-encoded leases. This map is suitable for use in Kubernetes annotations, and will be parseable by ParseMapFromAnnotations

func (Map) UUIDs

func (m Map) UUIDs() ([]uuid.UUID, error)

UUIDs returns the map of lease UUIDs to the lease for that UUID

type UUIDAndLease

type UUIDAndLease struct {
	UUID  uuid.UUID
	Lease *Lease
}

UUIDAndLease is a simple struct to encapsulate the token (which is a UUID) for a lease and the corresponding lease itself. This structure is represented as a key/value pair in a k8s annotations map

func NewUUIDAndLease

func NewUUIDAndLease(u uuid.UUID, l *Lease) *UUIDAndLease

NewUUIDAndLease creates a new UUIDAndLease struct populated with u and l for its UUID and Lease fields, respectively

Jump to

Keyboard shortcuts

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