operatorkit: github.com/giantswarm/operatorkit/controller Index | Files | Directories

package controller

import "github.com/giantswarm/operatorkit/controller"

Index

Package Files

controller.go error.go finalizer.go metric.go resource_set.go string_cache.go

Constants

const (
    DefaultResyncPeriod   = 5 * time.Minute
    DisableMetricsServing = "0"
)
const (
    PrometheusNamespace = "operatorkit"
    PrometheusSubsystem = "controller"
)

func IsExecutionFailed Uses

func IsExecutionFailed(err error) bool

IsExecutionFailed asserts executionFailedError.

func IsInvalidConfig Uses

func IsInvalidConfig(err error) bool

IsInvalidConfig asserts invalidConfigError.

func IsNoResourceSet Uses

func IsNoResourceSet(err error) bool

IsNoResourceSet asserts noResourceSetError.

func IsPortforward Uses

func IsPortforward(err error) bool

IsPortforward asserts portForwardError.

func IsStatusForbidden Uses

func IsStatusForbidden(err error) bool

IsStatusForbiddenError asserts statusForbiddenError and apimachinery StatusError with StatusReasonForbidden.

func IsTooManyResourceSets Uses

func IsTooManyResourceSets(err error) bool

IsTooManyResourceSets asserts tooManyResourceSetsError.

func ProcessDelete Uses

func ProcessDelete(ctx context.Context, obj interface{}, resources []resource.Interface) error

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 := c.ProcessDelete(obj, resources)
    if err != nil {
        // error handling here
    }
}

newResourceEventHandler := &cache.ResourceEventHandlerFuncs{
    DeleteFunc:    deleteFunc,
}

func ProcessUpdate Uses

func ProcessUpdate(ctx context.Context, obj interface{}, resources []resource.Interface) error

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 := c.ProcessUpdate(newObj, resources)
    if err != nil {
        // error handling here
    }
}

newResourceEventHandler := &cache.ResourceEventHandlerFuncs{
    UpdateFunc:    updateFunc,
}

type Config Uses

type Config struct {
    CRD *apiextensionsv1beta1.CustomResourceDefinition
    // K8sClient is the client collection used to setup and manage certain
    // operatorkit primitives. The CRD Client it provides is used to ensure the
    // CRD being created, in case the CRD option is configured. The Controller
    // Client is used to fetch runtime objects. It therefore must be properly
    // configured using the AddToScheme option. The REST Client is used to patch
    // finalizers on runtime objects.
    K8sClient k8sclient.Interface
    Logger    micrologger.Logger
    // NewRuntimeObjectFunc returns a new initialized pointer of a type
    // implementing the runtime object interface. The object returned is used with
    // the controller-runtime client to fetch the latest version of the object
    // itself. That way we can manage all runtime objects in a somewhat generic
    // way. See the example below.
    //
    //     func() pkgruntime.Object {
    //        return new(corev1.ConfigMap)
    //     }
    //
    NewRuntimeObjectFunc func() pkgruntime.Object
    // ResourceSets is a list of resource sets. 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.
    ResourceSets []*ResourceSet
    // Selector is used to filter objects before passing them to the controller.
    Selector labels.Selector

    // Name is the name which the controller uses on finalizers for resources.
    // The name used should be unique in the kubernetes cluster, to ensure that
    // two operators which handle the same resource add two distinct finalizers.
    Name string
    // ResyncPeriod is the duration after which a complete sync with all known
    // runtime objects the controller watches is performed. Defaults to
    // DefaultResyncPeriod.
    ResyncPeriod time.Duration
}

type Controller Uses

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

func New Uses

func New(config Config) (*Controller, error)

New creates a new configured operator controller.

func (*Controller) Boot Uses

func (c *Controller) Boot(ctx context.Context)

func (*Controller) Booted Uses

func (c *Controller) Booted() chan struct{}

func (*Controller) Reconcile Uses

func (c *Controller) Reconcile(req reconcile.Request) (reconcile.Result, error)

Reconcile implements the reconciler given to the controller-runtime controller. Reconcile never returns any error as we deal with them in operatorkit internally.

type ResourceSet Uses

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

func NewResourceSet Uses

func NewResourceSet(c ResourceSetConfig) (*ResourceSet, error)

func (*ResourceSet) Handles Uses

func (r *ResourceSet) Handles(obj interface{}) bool

func (*ResourceSet) InitCtx Uses

func (r *ResourceSet) InitCtx(ctx context.Context, obj interface{}) (context.Context, error)

func (*ResourceSet) Resources Uses

func (r *ResourceSet) Resources() []resource.Interface

type ResourceSetConfig Uses

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 controller resources being executed on runtime
    // object reconciliation if Handles returns true when asked by the
    // controller. Resources are executed in given order.
    Resources []resource.Interface
}

Directories

PathSynopsis
collector
context/finalizerskeptcontextPackage finalizerskeptcontext stores and accesses the kept in context.Context.
context/reconciliationcanceledcontextPackage reconciliationcanceledcontext stores and accesses the canceled in context.Context.
context/resourcecanceledcontextPackage resourcecanceledcontext stores and accesses the canceled in context.Context.
context/updateallowedcontextPackage updateallowedcontext stores and accesses the update allowed in context.Context.

Package controller imports 39 packages (graph) and is imported by 34 packages. Updated 2020-01-25. Refresh now. Tools for package owners.