v0.8.0 Latest Latest

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

Go to latest
Published: Aug 7, 2019 License: Apache-2.0 Imports: 27 Imported by: 0



Package reconciler defines implementations of the Reconciler interface defined at These implement the basic workhorse functionality of controllers, while leaving the shared controller implementation to manage things like the workqueue.

Despite defining a Reconciler, each of the packages here are expected to expose a controller constructor like:

func NewController(...) *controller.Impl { ... }

These constructors will:

  1. Construct the Reconciler,
  2. Construct a controller.Impl with that Reconciler,
  3. Wire the assorted informers this Reconciler watches to call appropriate enqueue methods on the controller.



View Source
const (
	// ChannelReadyCountN is the number of channels that have become ready.
	ChannelReadyCountN = "channel_ready_count"
	// ChannelReadyLatencyN is the time it takes for a channel to become ready since the resource is created.
	ChannelReadyLatencyN = "channel_ready_latency"

	// PullSubscriptionReadyCountN is the number of pull subscriptions that have become ready.
	PullSubscriptionReadyCountN = "pullsubscription_ready_count"
	// PullSubscriptionReadyLatencyN is the time it takes for a pull subscription to become ready since the resource is created.
	PullSubscriptionReadyLatencyN = "pullsubscription_ready_latency"
View Source
const (
	ControllerType = ""


View Source
var (
	KindToStatKeys = map[string]StatKey{
		"Channel": {
			ReadyCountKey:   ChannelReadyCountN,
			ReadyLatencyKey: ChannelReadyLatencyN,
		"PullSubscription": {
			ReadyCountKey:   PullSubscriptionReadyCountN,
			ReadyLatencyKey: PullSubscriptionReadyLatencyN,

	KindToMeasurements map[string]Measurements


func MustNewStatsReporter

func MustNewStatsReporter(reconciler string, logger *zap.SugaredLogger) controller.StatsReporter

MustNewStatsReporter creates a new instance of StatsReporter. Panics if creation fails.

func WithStatsReporter

func WithStatsReporter(ctx context.Context, sr StatsReporter) context.Context

WithStatsReporter attaches the given StatsReporter to the provided context in the returned context.


type Base

type Base struct {
	// KubeClientSet allows us to talk to the k8s for core APIs
	KubeClientSet kubernetes.Interface

	// DynamicClientSet allows us to configure pluggable Build objects
	DynamicClientSet dynamic.Interface

	// RunClientSet is the client for cloud run events.
	RunClientSet clientset.Interface

	// ServingClientSet is the client for Knative Serving
	ServingClientSet servingclientset.Interface

	// ConfigMapWatcher allows us to watch for ConfigMap changes.
	ConfigMapWatcher configmap.Watcher

	// Recorder is an event recorder for recording Event resources to the
	// Kubernetes API.
	Recorder record.EventRecorder

	// StatsReporter reports reconciler's metrics.
	StatsReporter StatsReporter

	// Sugared logger is easier to use but is not as performant as the
	// raw logger. In performance critical paths, call logger.Desugar()
	// and use the returned raw logger instead. In addition to the
	// performance benefits, raw logger also preserves type-safety at
	// the expense of slightly greater verbosity.
	Logger *zap.SugaredLogger

Base implements the core controller logic, given a Reconciler.

func NewBase

func NewBase(ctx context.Context, controllerAgentName string, cmw configmap.Watcher) *Base

NewBase instantiates a new instance of Base implementing the common & boilerplate code between our reconcilers.

type Measurement

type Measurement int

type Measurements

type Measurements struct {
	ReadyLatencyStat *stats.Int64Measure
	ReadyCountStat   *stats.Int64Measure

type Options

type Options struct {
	KubeClientSet    kubernetes.Interface
	DynamicClientSet dynamic.Interface

	RunClientSet clientset.Interface

	Recorder      record.EventRecorder
	StatsReporter StatsReporter

	ConfigMapWatcher configmap.Watcher
	Logger           *zap.SugaredLogger

	ResyncPeriod time.Duration
	StopChannel  <-chan struct{}

Options defines the common reconciler options. We define this to reduce the boilerplate argument list when creating our controllers.

func NewOptionsOrDie

func NewOptionsOrDie(cfg *rest.Config, logger *zap.SugaredLogger, stopCh <-chan struct{}) Options

func (Options) GetTrackerLease

func (o Options) GetTrackerLease() time.Duration

GetTrackerLease returns a multiple of the resync period to use as the duration for tracker leases. This attempts to ensure that resyncs happen to refresh leases frequently enough that we don't miss updates to tracked objects.

type StatKey

type StatKey struct {
	ReadyLatencyKey string
	ReadyCountKey   string

type StatsReporter

type StatsReporter interface {
	// ReportReady reports the time it took a resource to become Ready.
	ReportReady(kind, namespace, service string, d time.Duration) error

StatsReporter reports reconcilers' metrics.

func GetStatsReporter

func GetStatsReporter(ctx context.Context) StatsReporter

GetStatsReporter attempts to look up the StatsReporter on a given context. It may return null if none is found.

func NewStatsReporter

func NewStatsReporter(reconciler string) (StatsReporter, error)

NewStatsReporter creates a reporter for reconcilers' metrics


Path Synopsis
Package channel implements the Pub/Sub Channel controller.
Package channel implements the Pub/Sub Channel controller.
Package pullsubscription implements the Pub/Sub PullSubscription controller.
Package pullsubscription implements the Pub/Sub PullSubscription controller.
Package topic implements the Cloud Pub/Sub Topic controller.
Package topic implements the Cloud Pub/Sub Topic controller.

Jump to

Keyboard shortcuts

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