Documentation
¶
Index ¶
- Constants
- func DefaultBackOffFactory() func() backoff.BackOff
- func DefaultResourceSetResourceFunc(rs []Resource) func(ctx context.Context, obj interface{}) ([]Resource, error)
- func IsExecutionFailed(err error) bool
- func IsInvalidConfig(err error) bool
- func IsNoResourceSet(err error) bool
- func ProcessDelete(ctx context.Context, obj interface{}, resources []Resource) error
- func ProcessUpdate(ctx context.Context, obj interface{}, resources []Resource) error
- type CRUDResource
- type CRUDResourceConfig
- type CRUDResourceOps
- type Config
- type Framework
- type Patch
- type Resource
- type ResourceRouter
- type ResourceRouterConfig
- type ResourceSet
- type ResourceSetConfig
Constants ¶
const ( PrometheusNamespace = "operatorkit" PrometheusSubsystem = "framework" )
Variables ¶
This section is empty.
Functions ¶
func DefaultBackOffFactory ¶
func IsExecutionFailed ¶
IsExecutionFailed asserts executionFailedError.
func IsInvalidConfig ¶
IsInvalidConfig asserts invalidConfigError.
func IsNoResourceSet ¶
IsNoResourceSet asserts noResourceSetError.
func ProcessDelete ¶
ProcessDelete is a drop-in for an informer's DeleteFunc. It receives the custom object observed during custom resource watches and anything that implements Resource. ProcessDelete takes care about all necessary reconciliation logic for delete events.
func deleteFunc(obj interface{}) { err := f.ProcessDelete(obj, resources) if err != nil { // error handling here } } newResourceEventHandler := &cache.ResourceEventHandlerFuncs{ DeleteFunc: deleteFunc, }
func ProcessUpdate ¶
ProcessUpdate is a drop-in for an informer's UpdateFunc. It receives the new custom object observed during custom resource watches and anything that implements Resource. ProcessUpdate takes care about all necessary reconciliation logic for update events. For complex resources this means state has to be created, deleted and updated eventually, in this order.
func updateFunc(oldObj, newObj interface{}) { err := f.ProcessUpdate(newObj, resources) if err != nil { // error handling here } } newResourceEventHandler := &cache.ResourceEventHandlerFuncs{ UpdateFunc: updateFunc, }
Types ¶
type CRUDResource ¶
type CRUDResource struct { CRUDResourceOps // contains filtered or unexported fields }
CRUDResource allows implementing complex CRUD Resrouces in structured way. Besides that is implements various context features defined in subpackages of the context package.
func NewCRUDResource ¶
func NewCRUDResource(config CRUDResourceConfig) (*CRUDResource, error)
func (*CRUDResource) EnsureCreated ¶
func (r *CRUDResource) EnsureCreated(ctx context.Context, obj interface{}) error
func (*CRUDResource) EnsureDeleted ¶
func (r *CRUDResource) EnsureDeleted(ctx context.Context, obj interface{}) error
type CRUDResourceConfig ¶
type CRUDResourceConfig struct { Logger micrologger.Logger // Ops is a set of operations used by CRUDResource to implement the // Resource interface. Ops CRUDResourceOps }
type CRUDResourceOps ¶
type CRUDResourceOps interface { // Name returns the resource's name used for identification. Name() string // GetCurrentState receives the custom object observed during custom // resource watches. Its purpose is to return the current state of the // resources being managed by the operator. This can e.g. be some // actual data within a configmap as provided by the Kubernetes API. // This is not limited to Kubernetes resources though. Another example // would be to fetch and return information about Flannel bridges. // // NOTE GetCurrentState is called on create, delete and update events. When // called on create and delete events the provided custom object will be the // custom object currently known to the informer. On update events the // informer knows about the old and the new custom object. GetCurrentState // then receives the new custom object to be able to consume the current state // of a system. GetCurrentState(ctx context.Context, obj interface{}) (interface{}, error) // GetDesiredState receives the custom object observed during custom // resource watches. Its purpose is to return the desired state of the // resources being managed by the operator. The desired state should // always be able to be made up using the information provided by the // custom object. This can e.g. be some data within a configmap, how it // should be provided by the Kubernetes API. This is not limited to // Kubernetes resources though. Another example would be to make up and // return information about Flannel bridges, how they should look like // on a server host. // // NOTE GetDesiredState is called on create, delete and update events. // When called on create events the provided custom object will be the // custom object currently known to the informer. On update events the // informer knows about the old and the new custom object. // GetDesiredState then receives the new custom object to be able to // compute the desired state of a system. GetDesiredState(ctx context.Context, obj interface{}) (interface{}, error) // NewUpdatePatch is called upon observed custom object change. It receives // the observed custom object, the current state as provided by // GetCurrentState and the desired state as provided by // GetDesiredState. NewUpdatePatch analyses the current and desired // state and returns the patch to be applied by Create, Delete, and // Update functions. ApplyCreateChange, ApplyDeleteChange, and // ApplyUpdateChange are called only when the corresponding patch part // was created. NewUpdatePatch(ctx context.Context, obj, currentState, desiredState interface{}) (*Patch, error) // NewDeletePatch is called upon observed custom object deletion. It // receives the deleted custom object, the current state as provided by // GetCurrentState and the desired state as provided by // GetDesiredState. NewDeletePatch analyses the current and desired // state returns the patch to be applied by Create, Delete, and Update // functions. ApplyCreateChange, ApplyDeleteChange, and // ApplyUpdateChange are called only when the corresponding patch part // was created. NewDeletePatch(ctx context.Context, obj, currentState, desiredState interface{}) (*Patch, error) // ApplyCreateChange receives the new custom object observed during // custom resource watches. It also receives the create portion of the // Patch provided by NewUpdatePatch or NewDeletePatch. // ApplyCreateChange only has to create resources based on its provided // input. All other reconciliation logic and state transformation is // already done at this point of the reconciliation loop. ApplyCreateChange(ctx context.Context, obj, createChange interface{}) error // ApplyDeleteChange receives the new custom object observed during // custom resource watches. It also receives the delete portion of the // Patch provided by NewUpdatePatch or NewDeletePatch. // ApplyDeleteChange only has to delete resources based on its provided // input. All other reconciliation logic and state transformation is // already done at this point of the reconciliation loop. ApplyDeleteChange(ctx context.Context, obj, deleteChange interface{}) error // ApplyUpdateChange receives the new custom object observed during // custom resource watches. It also receives the update portion of the // Patch provided by NewUpdatePatch or NewDeletePatch. // ApplyUpdateChange has to update resources based on its provided // input. All other reconciliation logic and state transformation is // already done at this point of the reconciliation loop. ApplyUpdateChange(ctx context.Context, obj, updateChange interface{}) error }
CRUDResourceOps provides set of building blocks of a CRUDResource business logic being reconciled when observing custom objects. The interface provides a guideline for an easier way to follow the rather complex intentions of operators in general.
type Config ¶
type Config struct { CRD *apiextensionsv1beta1.CustomResourceDefinition CRDClient *k8scrdclient.CRDClient Informer informer.Interface Logger micrologger.Logger // ResourceRouter determines which resource set to use on reconciliation based // on its own implementation. A resource router is to decide which resource // set to execute. A resource set provides a specific function to initialize // the request context and a list of resources to be executed for a // reconciliation loop. That way each runtime object being reconciled is // executed against a desired list of resources. Since runtime objects may // differ in version and/or structure the resource router enables custom // inspection before each reconciliation loop. That way the complete list of // resources being executed for the received runtime object can be versioned // and different resources can be executed depending on the runtime object // being reconciled. ResourceRouter *ResourceRouter BackOffFactory func() backoff.BackOff }
Config represents the configuration used to create a new operator framework.
type Framework ¶
type Framework struct {
// contains filtered or unexported fields
}
func (*Framework) DeleteFunc ¶
func (f *Framework) DeleteFunc(obj interface{})
DeleteFunc executes the framework's ProcessDelete function.
func (*Framework) ProcessEvents ¶
func (f *Framework) ProcessEvents(ctx context.Context, deleteChan chan watch.Event, updateChan chan watch.Event, errChan chan error)
ProcessEvents takes the event channels created by the operatorkit informer and executes the framework's event functions accordingly.
func (*Framework) UpdateFunc ¶
func (f *Framework) UpdateFunc(oldObj, newObj interface{})
UpdateFunc executes the framework's ProcessUpdate function.
type Patch ¶
type Patch struct {
// contains filtered or unexported fields
}
Patch is a set of information required in order to reconcile to the desired state. Patch is split into three parts: create, delete and update changes. The parts are passed as arguments to Resource's ApplyCreateChange, ApplyDeleteChange and ApplyUpdateChange functions respectively. Patch changes are guaranteed to be applied in that order (i.e. create, update, delete).
func (*Patch) SetCreateChange ¶
func (p *Patch) SetCreateChange(create interface{})
func (*Patch) SetDeleteChange ¶
func (p *Patch) SetDeleteChange(delete interface{})
func (*Patch) SetUpdateChange ¶
func (p *Patch) SetUpdateChange(update interface{})
type Resource ¶
type Resource interface { // Name returns the resource's name used for identification. Name() string // EnsureCreated is called when observed object is created or updated. // The object is in state after cration or modification. This method must // be idempotent. EnsureCreated(ctx context.Context, obj interface{}) error // EnsureDeleted is called when observed object is deleted. The object // is in last observed state before the deletion. This method must be // idempotent. EnsureDeleted(ctx context.Context, obj interface{}) error }
Resource is an interface. Resources are the building blocks of the operator's reconciliation logic. Note there can be multiple Resources reconciling the same object in the chain. In that case they are guaranteed to be executed in order one one after another.
type ResourceRouter ¶
type ResourceRouter struct {
// contains filtered or unexported fields
}
func NewResourceRouter ¶
func NewResourceRouter(c ResourceRouterConfig) (*ResourceRouter, error)
func (*ResourceRouter) ResourceSet ¶
func (r *ResourceRouter) ResourceSet(obj interface{}) (*ResourceSet, error)
ResourceSet tries to lookup the appropriate resource set based on the received runtime object. There might be not any resource set for an observed runtime object if an operator uses multiple frameworks for reconciliations. There must not be multiple resource sets per observed runtime object though. If this is the case, ResourceSet returns an error.
type ResourceRouterConfig ¶
type ResourceRouterConfig struct { Logger micrologger.Logger ResourceSets []*ResourceSet }
type ResourceSet ¶
type ResourceSet struct {
// contains filtered or unexported fields
}
func NewResourceSet ¶
func NewResourceSet(c ResourceSetConfig) (*ResourceSet, error)
func (*ResourceSet) Handles ¶
func (r *ResourceSet) Handles(obj interface{}) bool
func (*ResourceSet) Resources ¶
func (r *ResourceSet) Resources() []Resource
type ResourceSetConfig ¶
type ResourceSetConfig struct { // Handles determines if this resource set handles the reconciliation of the // object. Handles func(obj interface{}) bool // InitCtx is to prepare the given context for a single reconciliation loop. // Operators can implement common context packages to enable communication // between resources. These context packages can be set up within this context // initializer function. InitCtx receives the runtime object being reconciled // as second argument. Information provided by the runtime object can be used // to initialize the context. InitCtx func(ctx context.Context, obj interface{}) (context.Context, error) // Logger is a usual micrologger instance to emit log messages, if any. Logger micrologger.Logger // Resources is the list of framework resources being executed on runtime // object reconciliation if Handles returns true when asked by the framework. Resources []Resource }
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
context
|
|
deletionallowedcontext
Package deletionallowedcontext stores and accesses the deletion allowed in context.Context.
|
Package deletionallowedcontext stores and accesses the deletion allowed in context.Context. |
reconciliationcanceledcontext
Package reconciliationcanceledcontext stores and accesses the canceled in context.Context.
|
Package reconciliationcanceledcontext stores and accesses the canceled in context.Context. |
resourcecanceledcontext
Package resourcecanceledcontext stores and accesses the canceled in context.Context.
|
Package resourcecanceledcontext stores and accesses the canceled in context.Context. |
updateallowedcontext
Package updateallowedcontext stores and accesses the update allowed in context.Context.
|
Package updateallowedcontext stores and accesses the update allowed in context.Context. |
updatenecessarycontext
Package updatenecessarycontext stores and accesses the update necessary in context.Context.
|
Package updatenecessarycontext stores and accesses the update necessary in context.Context. |
resource
|
|