Documentation
¶
Index ¶
- Constants
- Variables
- func KeyExtractor(text string) func(instance.Description) (string, error)
- type Collection
- func (c *Collection) CurrentSpec() (s types.Spec)
- func (c *Collection) Delete(k string)
- func (c *Collection) Enforce(spec types.Spec) (object *types.Object, err error)
- func (c *Collection) EventCh() chan<- *event.Event
- func (c *Collection) EventID(v string) string
- func (c *Collection) Events() event.Plugin
- func (c *Collection) Free() (*types.Object, error)
- func (c *Collection) Get(k string) *Item
- func (c *Collection) GetByFSM(f fsm.FSM) (item *Item)
- func (c *Collection) GetCountByState(state fsm.Index) (count int)
- func (c *Collection) GetPrevSpec() (s *types.Spec)
- func (c *Collection) Inspect() (object *types.Object, err error)
- func (c *Collection) List(topic types.Path) ([]string, error)
- func (c *Collection) Metadata() metadata.Plugin
- func (c *Collection) MetadataExport(key func(instance.Description) (string, error), v []instance.Description) error
- func (c *Collection) MetadataGone(key func(instance.Description) (string, error), v []instance.Description)
- func (c *Collection) Pause() (object *types.Object, err error)
- func (c *Collection) Plan(op controller.Operation, spec types.Spec) (object *types.Object, plan *controller.Plan, err error)
- func (c *Collection) PublishOn(events chan<- *event.Event)
- func (c *Collection) Put(k string, fsm fsm.FSM, spec *fsm.Spec, data map[string]interface{}) *Item
- func (c *Collection) Render(any *types.Any, item Item) (*types.Any, error)
- func (c *Collection) Running() bool
- func (c *Collection) Scope() scope.Scope
- func (c *Collection) SetPrevSpec(s types.Spec)
- func (c *Collection) Start()
- func (c *Collection) Stop() error
- func (c *Collection) Terminate() (object *types.Object, err error)
- func (c *Collection) Topic(p types.Path) types.Path
- func (c *Collection) Visit(v func(Item) bool)
- type ControlLoop
- type Controller
- func (c *Controller) Commit(operation controller.Operation, spec types.Spec) (object types.Object, err error)
- func (c *Controller) Controllers() (map[string]controller.Controller, error)
- func (c *Controller) Describe(search *types.Metadata) (objects []types.Object, err error)
- func (c *Controller) Free(search *types.Metadata) (objects []types.Object, err error)
- func (c *Controller) List(topic types.Path) ([]string, error)
- func (c *Controller) Metadata() (plugins map[string]metadata.Plugin, err error)
- func (c *Controller) Plan(operation controller.Operation, spec types.Spec) (object types.Object, plan controller.Plan, err error)
- func (c *Controller) PublishOn(events chan<- *event.Event)
- type InstanceAccess
- type InstanceObserver
- func (o *InstanceObserver) Difference(before, after []instance.Description) instance.Descriptions
- func (o *InstanceObserver) Init(scope scope.Scope, retry time.Duration) error
- func (o *InstanceObserver) KeyOf(instance instance.Description) (string, error)
- func (o *InstanceObserver) Lost() <-chan []instance.Description
- func (o *InstanceObserver) Observations() <-chan []instance.Description
- func (o *InstanceObserver) Pause(v bool)
- func (o *InstanceObserver) Start()
- func (o *InstanceObserver) Stop()
- func (o *InstanceObserver) Validate(defaults *InstanceObserver) error
- type Item
- type Managed
- type Poller
Constants ¶
const ( // SpecHash is the label name used to include a hash of the instance.Spec used to provision SpecHash = "infrakit_spec_hash" // InstanceLabel is the label name used for labeling the resource with the name in the collection InstanceLabel = "infrakit_instance" // CollectionLabel is the the label used to label the name of the collection CollectionLabel = "infrakit_collection" )
Variables ¶
var ( // TopicMetadataUpdate is the topic to get metadata updates TopicMetadataUpdate = types.PathFromString("metadata/update") // TopicMetadataGone is the topic to get metadata gone TopicMetadataGone = types.PathFromString("metadata/gone") // TopicCollectionUpdate is the topic to get collection updates TopicCollectionUpdate = types.PathFromString("collection/update") // TopicCollectionGone is the topic to get collection gones TopicCollectionGone = types.PathFromString("collection/gone") )
Functions ¶
func KeyExtractor ¶
func KeyExtractor(text string) func(instance.Description) (string, error)
KeyExtractor returns a function that can extract the link key from an instance description
Types ¶
type Collection ¶
type Collection struct {
// PlanFunc returns a plan based on the intent
PlanFunc func(controller.Operation, types.Spec) (controller.Plan, error) `json:"-"`
// StartFunc begins the actual processing. This will be called synchronously
// so the body needs to start goroutines.
StartFunc func(context.Context) `json:"-"`
// UpdateSpecFunc is called when a new spec is posted. This will be executed
// with exclusive lock on the collection.
UpdateSpecFunc func(cur types.Spec, prev *types.Spec) error `json:"-"`
// PauseFunc is called when the controller tries to pause.
PauseFunc func(bool) `json:"-"`
// StopFunc is called when the collection is stopped terminally.
StopFunc func() error `json:"-"`
// TerminateFunc is called when this collection is to be destroyed / terminated.
// This is not the same as Stop, which stops monitoring.
TerminateFunc func() error `json:"-"`
types.Spec
// contains filtered or unexported fields
}
Collection is a Managed that tracks a set of finite state machines.
func NewCollection ¶
NewCollection returns a Managed controller object that represents a collection of finite state machines (FSM).
func (*Collection) CurrentSpec ¶
func (c *Collection) CurrentSpec() (s types.Spec)
CurrentSpec returns the spec this collection is enforcing
func (*Collection) Delete ¶
func (c *Collection) Delete(k string)
Delete an item by key. This is unsychronized.
func (*Collection) Enforce ¶
Enforce will call the behavior to update the spec once it passes validation, and the collection will start running / polling. Since the collection is one-time use (it gets created and replaced by the base controller implementation), enforce will be called only once.
func (*Collection) EventCh ¶
func (c *Collection) EventCh() chan<- *event.Event
EventCh returns the events channel to publish events
func (*Collection) EventID ¶
func (c *Collection) EventID(v string) string
EventID is the type of the events emitted by this object
func (*Collection) Events ¶
func (c *Collection) Events() event.Plugin
Events returns events plugin implementation. Optional; ok to be nil
func (*Collection) Free ¶
func (c *Collection) Free() (*types.Object, error)
Free is an alias for Pause
func (*Collection) Get ¶
func (c *Collection) Get(k string) *Item
Get returns an item by key. This is unsynchronized so caller / user needs to synchronize as needed.
func (*Collection) GetByFSM ¶
func (c *Collection) GetByFSM(f fsm.FSM) (item *Item)
GetByFSM returns an item by the state machine
func (*Collection) GetCountByState ¶
func (c *Collection) GetCountByState(state fsm.Index) (count int)
GetCountByState returns the number of instances in the given state
func (*Collection) GetPrevSpec ¶
func (c *Collection) GetPrevSpec() (s *types.Spec)
GetPrevSpec returns the spec the this collection continues from.
func (*Collection) Inspect ¶
func (c *Collection) Inspect() (object *types.Object, err error)
Inspect inspects the current state of the collection.
func (*Collection) List ¶
func (c *Collection) List(topic types.Path) ([]string, error)
List implements event.List
func (*Collection) Metadata ¶
func (c *Collection) Metadata() metadata.Plugin
Metadata returns a metadata plugin implementation. Optional; ok to be nil
func (*Collection) MetadataExport ¶
func (c *Collection) MetadataExport(key func(instance.Description) (string, error), v []instance.Description) error
MetadataExport exports the objects in the metadata plugin interface. A keyfunc is required to compute the key based on the instance.
func (*Collection) MetadataGone ¶
func (c *Collection) MetadataGone(key func(instance.Description) (string, error), v []instance.Description)
MetadataGone removes the object in the metadata plugin interface
func (*Collection) Pause ¶
func (c *Collection) Pause() (object *types.Object, err error)
Pause pauses the collection from monitoring and reconciling. This is temporary compared to Stop.
func (*Collection) Plan ¶
func (c *Collection) Plan(op controller.Operation, spec types.Spec) (object *types.Object, plan *controller.Plan, err error)
Plan returns a plan, the current state, or error
func (*Collection) PublishOn ¶
func (c *Collection) PublishOn(events chan<- *event.Event)
PublishOn sets the channel to publish on
func (*Collection) Put ¶
Put puts an item by key - this is unsynchronized so caller / user needs to synchronize the Put
func (*Collection) Running ¶
func (c *Collection) Running() bool
Running returns true if managed is running
func (*Collection) Scope ¶
func (c *Collection) Scope() scope.Scope
Scope returns the scope the collection uses to access plugins
func (*Collection) SetPrevSpec ¶
func (c *Collection) SetPrevSpec(s types.Spec)
SetPrevSpec sets the spec that a previous version of the collection was managing. This gives the context to the collection so that it is able to remove resources that no longer are needed, for example.
func (*Collection) Stop ¶
func (c *Collection) Stop() error
Stop stops the collection from monitoring and any processing. This operation is terminal.
func (*Collection) Terminate ¶
func (c *Collection) Terminate() (object *types.Object, err error)
Terminate destroys the resources associated with this collection.
func (*Collection) Topic ¶
func (c *Collection) Topic(p types.Path) types.Path
Topic returns a topic suitable for the events in this collection
func (*Collection) Visit ¶
func (c *Collection) Visit(v func(Item) bool)
Visit visits the items managed in this collection.
type ControlLoop ¶
ControlLoop gives status and means to stop the object
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller implements the pkg/controller/Controller interface and manages a collection of controls
func NewController ¶
func NewController(alloc func(types.Spec) (Managed, error), keyfunc func(types.Metadata) string) *Controller
NewController creates a controller injecting dependencies
func (*Controller) Commit ¶
func (c *Controller) Commit(operation controller.Operation, spec types.Spec) (object types.Object, err error)
Commit commits the spec to the controller for management or destruction. The controller's job is to ensure reality matches the operation and the specification. The spec can be composed and references other controllers or plugins. When a spec is committed to a controller, the controller returns the object state corresponding to the spec. When operation is Destroy, only Metadata portion of the spec is needed to identify the object to be destroyed.
func (*Controller) Controllers ¶
func (c *Controller) Controllers() (map[string]controller.Controller, error)
Controllers returns a map of managed objects as subcontrollers
func (*Controller) Describe ¶
Describe returns a list of objects matching the metadata provided. A list of objects are possible because metadata can be a tags search. An object has state, and its original spec can be accessed as well. A nil Metadata will instruct the controller to return all objects under management.
func (*Controller) Free ¶
Free tells the controller to pause management of objects matching. To resume, commit again.
func (*Controller) List ¶
func (c *Controller) List(topic types.Path) ([]string, error)
List implements event.List
func (*Controller) Metadata ¶
func (c *Controller) Metadata() (plugins map[string]metadata.Plugin, err error)
Metadata exposes any metdata implementations
func (*Controller) Plan ¶
func (c *Controller) Plan(operation controller.Operation, spec types.Spec) (object types.Object, plan controller.Plan, err error)
Plan is a commit without actually making the changes. The controller returns a proposed object state after commit, with a Plan, or error.
func (*Controller) PublishOn ¶
func (c *Controller) PublishOn(events chan<- *event.Event)
PublishOn sets the channel to publish on
type InstanceAccess ¶
type InstanceAccess struct {
*InstanceObserver `json:",inline" yaml:",inline"`
// Spec is the spec to use when provisioning the instance
instance.Spec `json:",inline" yaml:",inline"`
}
InstanceAccess is an entity capable of observing an instance plugin while providing the same interface methods as an instance Plugin. It also contains the fields necessary for provisioning an instance.
type InstanceObserver ¶
type InstanceObserver struct {
instance.Plugin
// Name is the name of the instance plugin
Name plugin.Name `json:"plugin" yaml:"plugin"`
// Select are the labels to use when querying for instances. This is the namespace.
Select map[string]string
// ObserveInterval is the polling interval for making an observation
ObserveInterval types.Duration
// CacheDescribeInstances is true to turn on caching with ttl equal to the ObserveInterval
CacheDescribeInstances bool
// KeySelector is a string template for selecting the join key from
// an instance's instance.Description. This selector template should use escapes
// so that the template {{ and }} are preserved. For example,
// SourceKeySelector: \{\{ .ID \}\} # selects the ID field.
KeySelector string
// contains filtered or unexported fields
}
InstanceObserver is an entity that observes an instance plugin for a list of instance descriptions at some specified polling interval. Not thread safe.
func (*InstanceObserver) Difference ¶
func (o *InstanceObserver) Difference(before, after []instance.Description) instance.Descriptions
Difference computes the difference before and after samples
func (*InstanceObserver) KeyOf ¶
func (o *InstanceObserver) KeyOf(instance instance.Description) (string, error)
KeyOf returns the key of the instance based on the key extractor configured here
func (*InstanceObserver) Lost ¶
func (o *InstanceObserver) Lost() <-chan []instance.Description
Lost returns the channel to receive instances that are missing in the current sample from the last.
func (*InstanceObserver) Observations ¶
func (o *InstanceObserver) Observations() <-chan []instance.Description
Observations returns the channel to receive observations. When stopped, the channel is closed.
func (*InstanceObserver) Pause ¶
func (o *InstanceObserver) Pause(v bool)
Pause pauses or unpauses the observations
func (*InstanceObserver) Start ¶
func (o *InstanceObserver) Start()
Start starts the observations. This call is nonblocking.
func (*InstanceObserver) Stop ¶
func (o *InstanceObserver) Stop()
Stop permanents stops the observer
func (*InstanceObserver) Validate ¶
func (o *InstanceObserver) Validate(defaults *InstanceObserver) error
Validate validates the receiver with default values provided if some optional fields are not set.
type Item ¶
type Item struct {
Key string
Ordinal int
State stateMachine
Data map[string]interface{} `json:",omitempty"`
}
Item is an item in the collection.
type Managed ¶
type Managed interface {
ControlLoop
CurrentSpec() types.Spec
SetPrevSpec(types.Spec)
GetPrevSpec() *types.Spec // optional since the first one will not have it set
Metadata() metadata.Plugin
Events() event.Plugin
Plan(controller.Operation, types.Spec) (*types.Object, *controller.Plan, error)
Enforce(types.Spec) (*types.Object, error)
Inspect() (*types.Object, error)
Free() (*types.Object, error)
Terminate() (*types.Object, error)
}
Managed is the interface implemented by managed objects within a controller
type Poller ¶
type Poller struct {
// contains filtered or unexported fields
}
Poller is the entity that executes a unit of work at a predefined interval
func PollWithCleanup ¶
func PollWithCleanup(shouldRun func() bool, work func() error, ticker <-chan time.Time, cleanup func()) *Poller
PollWithCleanup creates a poller with a clean up function that is invoked after the poller stops terminally.