Documentation ¶
Index ¶
- type OwnerNotMatch
- type Ranch
- func (r *Ranch) Acquire(rType, state, dest, owner, requestID string) (*crds.ResourceObject, metav1.Time, error)
- func (r *Ranch) AcquireByState(state, dest, owner string, names []string) ([]*crds.ResourceObject, error)
- func (r *Ranch) AllMetrics() ([]common.Metric, error)
- func (r *Ranch) Metric(rtype string) (common.Metric, error)
- func (r *Ranch) Release(name, dest, owner string) error
- func (r *Ranch) Reset(rtype, state string, expire time.Duration, dest string) (map[string]string, error)
- func (r *Ranch) StartRequestGC(gcPeriod time.Duration)
- func (r *Ranch) SyncConfig(configPath string) error
- func (r *Ranch) Update(name, owner, state string, ud *common.UserData) error
- type RequestManager
- func (rp *RequestManager) Delete(key interface{}, requestID string)
- func (rp *RequestManager) GetCreatedAt(key interface{}, id string) (metav1.Time, error)
- func (rp *RequestManager) GetRank(key interface{}, id string) (int, bool)
- func (rp *RequestManager) StartGC(gcPeriod time.Duration)
- func (rp *RequestManager) StopGC()
- type ResourceNotFound
- type ResourceTypeNotFound
- type StateNotMatch
- type Storage
- func (s *Storage) AddDynamicResourceLifeCycle(resource *crds.DRLCObject) error
- func (s *Storage) AddResource(resource *crds.ResourceObject) error
- func (s *Storage) DeleteDynamicResourceLifeCycle(name string) error
- func (s *Storage) DeleteResource(name string) error
- func (s *Storage) GetDynamicResourceLifeCycle(name string) (*crds.DRLCObject, error)
- func (s *Storage) GetDynamicResourceLifeCycles() (*crds.DRLCObjectList, error)
- func (s *Storage) GetResource(name string) (*crds.ResourceObject, error)
- func (s *Storage) GetResources() (*crds.ResourceObjectList, error)
- func (s *Storage) SyncResources(config *common.BoskosConfig) error
- func (s *Storage) UpdateAllDynamicResources(staticResources map[string]crds.ResourceObject) error
- func (s *Storage) UpdateDynamicResourceLifeCycle(resource *crds.DRLCObject) (*crds.DRLCObject, error)
- func (s *Storage) UpdateResource(resource *crds.ResourceObject) (*crds.ResourceObject, error)
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 ¶
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 ¶
AllMetrics returns a list of Metric objects for all resource types.
func (*Ranch) Release ¶
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 ¶
StartRequestGC starts the GC of expired requests
func (*Ranch) SyncConfig ¶
SyncConfig updates resource list from a file
func (*Ranch) Update ¶
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 ¶
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 ¶
DeleteDynamicResourceLifeCycle deletes a dynamic resource life cycle if it exists, errors otherwise
func (*Storage) DeleteResource ¶
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