Back to godoc.org

Package reconciler

v0.0.0-...-c52b3dd
Latest Go to latest

The latest major version is .

Published: Mar 3, 2020 | License: Apache-2.0 | Module: github.com/chizhg/knative-gcp

Overview

Package reconciler defines implementations of the Reconciler interface defined at knative.dev/pkg/controller.Reconciler. 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.

Index

Constants

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"

	// TopicReadyCountN is the number of topics that have become ready.
	TopicReadyCountN = "topic_ready_count"
	// TopicReadyLatencyN is the time it takes for a topic to become ready since the resource is created.
	TopicReadyLatencyN = "topic_ready_latency"

	// CloudStorageSourceReadyCountN is the number of storages that have become ready.
	CloudStorageSourceReadyCountN = "storage_ready_count"
	// CloudStorageSourceReadyLatencyN is the time it takes for a storage to become ready since the resource is created.
	CloudStorageSourceReadyLatencyN = "storage_ready_latency"

	// PubSubReadyCountN is the number of pubsubs that have become ready.
	PubSubReadyCountN = "pubsub_ready_count"
	// PubSubReadyLatencyN is the time it takes for a pubsub to become ready since the resource is created.
	PubSubReadyLatencyN = "pubsub_ready_latency"

	// CloudSchedulerSourceReadyCountN is the number of schedulers that have become ready.
	CloudSchedulerSourceReadyCountN = "scheduler_ready_count"
	// CloudSchedulerSourceReadyLatencyN is the time it takes for a scheduler to become ready since the resource is created.
	CloudSchedulerSourceReadyLatencyN = "scheduler_ready_latency"

	// CloudAuditLogsSourceReadyCountN is the number of CloudAuditLogsSources that have become ready.
	CloudAuditLogsSourceReadyCountN = "cloudauditlogssource_ready_count"
	// CloudAuditLogsSourceReadyLatencyN is the time it takes for an CloudAuditLogsSource to become ready since the resource is created.
	CloudAuditLogsSourceReadyLatencyN = "cloudauditlogssource_ready_latency"
)
const (
	ControllerType = "events.cloud.google.com/controller"
)
const (
	// DefaultResyncPeriod sets the period between reconciliations in case nothing we are watching within the
	// cluster changed. This is needed because an external resource (e.g., Pub/Sub subscription, GCS notification, etc.)
	// could have been deleted outside the cluster, and we want to properly update our K8s object statuses.
	DefaultResyncPeriod = 5 * time.Minute
)

Variables

var (
	KindToStatKeys = map[string]StatKey{

		"Channel": {
			ReadyCountKey:   ChannelReadyCountN,
			ReadyLatencyKey: ChannelReadyLatencyN,
		},

		"PullSubscription": {
			ReadyCountKey:   PullSubscriptionReadyCountN,
			ReadyLatencyKey: PullSubscriptionReadyLatencyN,
		},
		"Topic": {
			ReadyCountKey:   TopicReadyCountN,
			ReadyLatencyKey: TopicReadyLatencyN,
		},

		"CloudStorageSource": {
			ReadyCountKey:   CloudStorageSourceReadyCountN,
			ReadyLatencyKey: CloudStorageSourceReadyLatencyN,
		},
		"PubSub": {
			ReadyCountKey:   PubSubReadyCountN,
			ReadyLatencyKey: PubSubReadyLatencyN,
		},
		"CloudSchedulerSource": {
			ReadyCountKey:   CloudSchedulerSourceReadyCountN,
			ReadyLatencyKey: CloudSchedulerSourceReadyLatencyN,
		},
		"CloudAuditLogsSource": {
			ReadyCountKey:   CloudAuditLogsSourceReadyCountN,
			ReadyLatencyKey: CloudAuditLogsSourceReadyLatencyN,
		},
	}

	KindToMeasurements map[string]Measurements
)

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

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier