manager

package
v0.9.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2023 License: Apache-2.0 Imports: 24 Imported by: 2

Documentation

Overview

Package manager implements some basic abstractions around controllers and lifecycling them.

`Manager` provides a way to start and stop a collection of controllers together. Controllers can be dynamically added/removed after the manager has started, and it also starts health / debug servers that tie into the health of the underlying controllers.

`BasicController` provides default implementations of health and debug servers.

`OwnedResourceController` implements the most common pattern for a controller: reconciling a single resource type via a workqueue. On Start, it begins processing objects from the queue, but it doesn't start any informers itself; that is the responsibility of the caller.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicController

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

BasicController implements Controller with a no-op control loop and simple health check and debug handlers.

func NewBasicController

func NewBasicController(name string) *BasicController

func (*BasicController) DebuggingHandler

func (c *BasicController) DebuggingHandler() http.Handler

func (*BasicController) HealthChecker

func (*BasicController) Name

func (c *BasicController) Name() string

func (*BasicController) Start

func (c *BasicController) Start(_ context.Context, _ int)

type Controller

type Controller interface {
	controller.Interface
	controller.Debuggable
	controller.HealthCheckable

	Start(ctx context.Context, numThreads int)
}

Controller is the interface we require for all controllers this manager will manage.

type Manager

type Manager struct {

	// a registry of cancel functions for each individual controller
	sync.RWMutex
	// contains filtered or unexported fields
}

Manager ties a set of controllers to be lifecycled together and exposes common metrics, debug information, and health endpoints for the set.

func NewManager

func NewManager(debugConfig *componentconfig.DebuggingConfiguration, address string, broadcaster record.EventBroadcaster, sink record.EventSink) *Manager

NewManager returns a Manager object with settings for what and how to expose information for its managed set of controllers.

func (*Manager) Cancel

func (m *Manager) Cancel(controllers ...Controller)

Cancel stops the controllers that are passed in

func (*Manager) Go

func (m *Manager) Go(controllers ...Controller) error

Go adds controllers into the existing manager's errgroup

func (*Manager) Start

func (m *Manager) Start(ctx context.Context, controllers ...Controller) error

Start starts a set of controllers in an errgroup and serves health / debug endpoints for them. It stops when the context is cancelled. It will only have an effect the first time it is called.

type OwnedResourceController

type OwnedResourceController struct {
	*BasicController

	queue.OperationsContext
	Registry *typed.Registry
	Recorder record.EventRecorder
	Owned    schema.GroupVersionResource
	Queue    workqueue.RateLimitingInterface
	// contains filtered or unexported fields
}

OwnedResourceController implements a Controller that implements our standard controller pattern:

  • A single GVR is "owned" and watched
  • Changes to objects of that type are processed via a workqueue
  • Other resources are watched, but only for the purpose of requeueing the primary object type.
  • The owned object has standard meta.Conditions and emits metrics for them

func NewOwnedResourceController

func NewOwnedResourceController(log logr.Logger, name string, owned schema.GroupVersionResource, key queue.OperationsContext, registry *typed.Registry, broadcaster record.EventBroadcaster, syncFunc SyncFunc) *OwnedResourceController
Example
gvr := schema.GroupVersionResource{
	Group:    "example.com",
	Version:  "v1",
	Resource: "mytypes",
}
CtxQueue := queue.NewQueueOperationsCtx()
registry := typed.NewRegistry()
broadcaster := record.NewBroadcaster()
eventSink := &typedcorev1.EventSinkImpl{Interface: fake.NewSimpleClientset().CoreV1().Events("")}

// the controller processes objects on the queue, but doesn't set up any
// informers by default.
controller := NewOwnedResourceController(klogr.New(), "my-controller", gvr, CtxQueue, registry, broadcaster, func(ctx context.Context, gvr schema.GroupVersionResource, namespace, name string) {
	// process object
})

mgr := NewManager(ctrlmanageropts.RecommendedDebuggingOptions().DebuggingConfiguration, ":", broadcaster, eventSink)
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Millisecond)
defer cancel()
_ = mgr.Start(ctx, controller)
Output:

func (*OwnedResourceController) Start

func (c *OwnedResourceController) Start(ctx context.Context, numThreads int)

type SyncFunc

type SyncFunc func(ctx context.Context, gvr schema.GroupVersionResource, namespace, name string)

SyncFunc is a function called when an event needs processing

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL