controller-runtime: Index | Examples | Files

package manager

import ""

Package manager is required to create Controllers and provides shared dependencies such as clients, caches, schemes, etc. Controllers must be started by calling Manager.Start.



Package Files

doc.go internal.go manager.go testutil.go

type Manager Uses

type Manager interface {
    // Add will set reqeusted dependencies on the component, and cause the component to be
    // started when Start is called.  Add will inject any dependencies for which the argument
    // implements the inject interface - e.g. inject.Client
    Add(Runnable) error

    // SetFields will set any dependencies on an object for which the object has implemented the inject
    // interface - e.g. inject.Client.
    SetFields(interface{}) error

    // Start starts all registered Controllers and blocks until the Stop channel is closed.
    // Returns an error if there is an error starting any controller.
    Start(<-chan struct{}) error

    // GetConfig returns an initialized Config
    GetConfig() *rest.Config

    // GetScheme returns and initialized Scheme
    GetScheme() *runtime.Scheme

    // GetAdmissionDecoder returns the runtime.Decoder based on the scheme.
    GetAdmissionDecoder() types.Decoder

    // GetClient returns a client configured with the Config
    GetClient() client.Client

    // GetFieldIndexer returns a client.FieldIndexer configured with the client
    GetFieldIndexer() client.FieldIndexer

    // GetCache returns a cache.Cache
    GetCache() cache.Cache

    // GetRecorder returns a new EventRecorder for the provided name
    GetRecorder(name string) record.EventRecorder

    // GetRESTMapper returns a RESTMapper
    GetRESTMapper() meta.RESTMapper

Manager initializes shared dependencies such as Caches and Clients, and provides them to Runnables. A Manager is required to create Controllers.

func New Uses

func New(config *rest.Config, options Options) (Manager, error)

New returns a new Manager for creating Controllers.

This example creates a new Manager that can be used with controller.New to create Controllers.


cfg, err := config.GetConfig()
if err != nil {
    log.Error(err, "unable to get kubeconfig")

mgr, err := manager.New(cfg, manager.Options{})
if err != nil {
    log.Error(err, "unable to set up manager")
log.Info("created manager", "manager", mgr)

type Options Uses

type Options struct {
    // Scheme is the scheme used to resolve runtime.Objects to GroupVersionKinds / Resources
    // Defaults to the kubernetes/client-go scheme.Scheme
    Scheme *runtime.Scheme

    // MapperProvider provides the rest mapper used to map go types to Kubernetes APIs
    MapperProvider func(c *rest.Config) (meta.RESTMapper, error)

    // SyncPeriod determines the minimum frequency at which watched resources are
    // reconciled. A lower period will correct entropy more quickly, but reduce
    // responsiveness to change if there are many watched resources. Change this
    // value only if you know what you are doing. Defaults to 10 hours if unset.
    SyncPeriod *time.Duration

    // LeaderElection determines whether or not to use leader election when
    // starting the manager.
    LeaderElection bool

    // LeaderElectionNamespace determines the namespace in which the leader
    // election configmap will be created.
    LeaderElectionNamespace string

    // LeaderElectionID determines the name of the configmap that leader election
    // will use for holding the leader lock.
    LeaderElectionID string

    // Namespace if specified restricts the manager's cache to watch objects in the desired namespace
    // Defaults to all namespaces
    // Note: If a namespace is specified then controllers can still Watch for a cluster-scoped resource e.g Node
    // For namespaced resources the cache will only hold objects from the desired namespace.
    Namespace string

    // MetricsBindAddress is the TCP address that the controller should bind to
    // for serving prometheus metrics
    MetricsBindAddress string
    // contains filtered or unexported fields

Options are the arguments for creating a new Manager

type Runnable Uses

type Runnable interface {
    // Start starts running the component.  The component will stop running when the channel is closed.
    // Start blocks until the channel is closed or an error occurs.
    Start(<-chan struct{}) error

Runnable allows a component to be started.

type RunnableFunc Uses

type RunnableFunc func(<-chan struct{}) error

RunnableFunc implements Runnable

func (RunnableFunc) Start Uses

func (r RunnableFunc) Start(s <-chan struct{}) error

Start implements Runnable

Package manager imports 26 packages (graph) and is imported by 44 packages. Updated 2018-12-02. Refresh now. Tools for package owners.