ranch

package
v0.0.0-...-59dbd6c Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: Apache-2.0 Imports: 18 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OwnerNotMatch

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

OwnerNotMatch will be returned if request owner does not match current owner for target resource.

func (OwnerNotMatch) Error

func (o OwnerNotMatch) Error() string

type Ranch

type Ranch struct {
	Storage *Storage
	// contains filtered or unexported fields
}

Ranch is the place which all of the Resource objects lives.

func NewRanch

func NewRanch(config string, s *Storage, ttl time.Duration) (*Ranch, error)

NewRanch creates a new Ranch object. In: config - path to resource file

storage - path to where to save/restore the state data

Out: A Ranch object, loaded from config/storage, or error

func (*Ranch) Acquire

func (r *Ranch) Acquire(rType, state, dest, owner, requestID string) (*crds.ResourceObject, metav1.Time, error)

Acquire checks out a type of resource in certain state without an owner, and move the checked out resource to the end of the resource list. In: rtype - name of the target resource

state - current state of the requested resource
dest - destination state of the requested resource
owner - requester of the resource
requestID - request ID to get a priority in the queue

Out: A valid Resource object and the time when the resource was originally requested on success, or

ResourceNotFound error if target type resource does not exist in target state.

func (*Ranch) AcquireByState

func (r *Ranch) AcquireByState(state, dest, owner string, names []string) ([]*crds.ResourceObject, error)

AcquireByState checks out resources of a given type without an owner, that matches a list of resources names. In: state - current state of the requested resource

dest - destination state of the requested resource
owner - requester of the resource
names - names of resource to acquire

Out: A valid list of Resource object on success, or

ResourceNotFound error if target type resource does not exist in target state.

func (*Ranch) AllMetrics

func (r *Ranch) AllMetrics() ([]common.Metric, error)

AllMetrics returns a list of Metric objects for all resource types.

func (*Ranch) Metric

func (r *Ranch) Metric(rtype string) (common.Metric, error)

Metric returns a metric object with metrics filled in

func (*Ranch) Release

func (r *Ranch) Release(name, dest, owner string) error

Release unsets owner for target resource and move it to a new state. In: name - name of the target resource

dest - destination state of the resource
owner - owner of the resource

Out: nil on success, or

OwnerNotMatch error if owner does not match current owner of the resource, or
ResourceNotFound error if target named resource does not exist.

func (*Ranch) Reset

func (r *Ranch) Reset(rtype, state string, expire time.Duration, dest string) (map[string]string, error)

Reset unstucks a type of stale resource to a new state. In: rtype - type of the resource

state - current state of the resource
expire - duration before resource's last update
dest - destination state of expired resources

Out: map of resource name - resource owner.

func (*Ranch) StartRequestGC

func (r *Ranch) StartRequestGC(gcPeriod time.Duration)

StartRequestGC starts the GC of expired requests

func (*Ranch) SyncConfig

func (r *Ranch) SyncConfig(configPath string) error

SyncConfig updates resource list from a file

func (*Ranch) Update

func (r *Ranch) Update(name, owner, state string, ud *common.UserData) error

Update updates the timestamp of a target resource. In: name - name of the target resource

    state - current state of the resource
    owner - current owner of the resource
	   info  - information on how to use the resource

Out: nil on success, or

OwnerNotMatch error if owner does not match current owner of the resource, or
ResourceNotFound error if target named resource does not exist, or
StateNotMatch error if state does not match current state of the resource.

type RequestManager

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

RequestManager facilitates management of RequestQueues for a set of (resource type, resource state) tuple.

func NewRequestManager

func NewRequestManager(ttl time.Duration) *RequestManager

NewRequestManager creates a new RequestManager

func (*RequestManager) Delete

func (rp *RequestManager) Delete(key interface{}, requestID string)

Delete deletes a specific request such that it is not accounted in the next GetRank call. This is usually called when the request has been fulfilled.

func (*RequestManager) GetCreatedAt

func (rp *RequestManager) GetCreatedAt(key interface{}, id string) (metav1.Time, error)

GetCreatedAt returns when the request was created

func (*RequestManager) GetRank

func (rp *RequestManager) GetRank(key interface{}, id string) (int, bool)

GetRank provides the rank of a given request and whether request is new (was added)

func (*RequestManager) StartGC

func (rp *RequestManager) StartGC(gcPeriod time.Duration)

StartGC starts a goroutine that will call cleanup every gcInterval

func (*RequestManager) StopGC

func (rp *RequestManager) StopGC()

StopGC is a blocking call that will stop the GC goroutine.

type ResourceNotFound

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

ResourceNotFound will be returned if requested resource does not exist.

func (ResourceNotFound) Error

func (r ResourceNotFound) Error() string

type ResourceTypeNotFound

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

ResourceTypeNotFound will be returned if requested resource type does not exist.

func (ResourceTypeNotFound) Error

func (r ResourceTypeNotFound) Error() string

type StateNotMatch

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

StateNotMatch will be returned if requested state does not match current state for target resource.

func (StateNotMatch) Error

func (s StateNotMatch) Error() string

type Storage

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

Storage is used to decouple ranch functionality with the resource persistence layer

func NewStorage

func NewStorage(ctx context.Context, client ctrlruntimeclient.Client, namespace string) *Storage

NewStorage instantiates a new Storage with a PersistenceLayer implementation

func NewTestingStorage

func NewTestingStorage(client ctrlruntimeclient.Client, namespace string, updateTime func() metav1.Time) *Storage

NewTestingStorage is used only for testing.

func (*Storage) AddDynamicResourceLifeCycle

func (s *Storage) AddDynamicResourceLifeCycle(resource *crds.DRLCObject) error

AddDynamicResourceLifeCycle adds a new dynamic resource life cycle

func (*Storage) AddResource

func (s *Storage) AddResource(resource *crds.ResourceObject) error

AddResource adds a new resource

func (*Storage) DeleteDynamicResourceLifeCycle

func (s *Storage) DeleteDynamicResourceLifeCycle(name string) error

DeleteDynamicResourceLifeCycle deletes a dynamic resource life cycle if it exists, errors otherwise

func (*Storage) DeleteResource

func (s *Storage) DeleteResource(name string) error

DeleteResource deletes a resource if it exists, errors otherwise

func (*Storage) GetDynamicResourceLifeCycle

func (s *Storage) GetDynamicResourceLifeCycle(name string) (*crds.DRLCObject, error)

GetDynamicResourceLifeCycle gets an existing dynamic resource life cycle, errors otherwise

func (*Storage) GetDynamicResourceLifeCycles

func (s *Storage) GetDynamicResourceLifeCycles() (*crds.DRLCObjectList, error)

GetDynamicResourceLifeCycles list all dynamic resource life cycle

func (*Storage) GetResource

func (s *Storage) GetResource(name string) (*crds.ResourceObject, error)

GetResource gets an existing resource, errors otherwise

func (*Storage) GetResources

func (s *Storage) GetResources() (*crds.ResourceObjectList, error)

GetResources list all resources

func (*Storage) SyncResources

func (s *Storage) SyncResources(config *common.BoskosConfig) error

SyncResources will update static and dynamic resources. It will add new resources to storage and try to remove newly deleted resources from storage. If the newly deleted resource is currently held by a user, the deletion will yield to next update cycle.

func (*Storage) UpdateAllDynamicResources

func (s *Storage) UpdateAllDynamicResources(staticResources map[string]crds.ResourceObject) error

UpdateAllDynamicResources queries for all existing DynamicResourceLifeCycles and dynamic resources and calls updateDynamicResources for each type. This ensures that the MinCount and MaxCount parameters are honored, that any expired resources are deleted, and that any Tombstoned resources are completely removed. nolint:gocognit

func (*Storage) UpdateDynamicResourceLifeCycle

func (s *Storage) UpdateDynamicResourceLifeCycle(resource *crds.DRLCObject) (*crds.DRLCObject, error)

UpdateDynamicResourceLifeCycle updates a dynamic resource life cycle. if it exists, errors otherwise

func (*Storage) UpdateResource

func (s *Storage) UpdateResource(resource *crds.ResourceObject) (*crds.ResourceObject, error)

UpdateResource updates a resource if it exists, errors otherwise

Jump to

Keyboard shortcuts

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