Documentation ¶
Overview ¶
Package source provides event streams to hook up to Controllers with Controller.Watch. Events are used with handler.EventHandlers to enqueue reconcile.Requests and trigger Reconciles for Kubernetes objects.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Channel ¶
type Channel struct { // Source is the source channel to fetch GenericEvents Source <-chan event.GenericEvent // DestBufferSize is the specified buffer size of dest channels. // Default to 1024 if not specified. DestBufferSize int // contains filtered or unexported fields }
Channel is used to provide a source of events originating outside the cluster (e.g. GitHub Webhook callback). Channel requires the user to wire the external source (eh.g. http handler) to write GenericEvents to the underlying channel.
Example ¶
This example reads GenericEvents from a channel and enqueues a reconcile.Request containing the Name and Namespace provided by the event.
package main import ( "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/handler" "sigs.k8s.io/controller-runtime/pkg/source" ) var ctrl controller.Controller func main() { events := make(chan event.GenericEvent) err := ctrl.Watch( &source.Channel{Source: events}, &handler.EnqueueRequestForObject{}, ) if err != nil { // handle it } }
Output:
func (*Channel) InjectStopChannel ¶
InjectStopChannel is internal should be called only by the Controller. It is used to inject the stop channel initialized by the ControllerManager.
type Func ¶
type Func func(context.Context, handler.EventHandler, workqueue.RateLimitingInterface, ...predicate.Predicate) error
Func is a function that implements Source
type Informer ¶ added in v0.1.5
Informer is used to provide a source of events originating inside the cluster from Watches (e.g. Pod Create)
func (*Informer) Start ¶ added in v0.1.5
func (is *Informer) Start(ctx context.Context, handler handler.EventHandler, queue workqueue.RateLimitingInterface, prct ...predicate.Predicate) error
Start is internal and should be called only by the Controller to register an EventHandler with the Informer to enqueue reconcile.Requests.
type Kind ¶
type Kind struct { // Type is the type of object to watch. e.g. &v1.Pod{} Type client.Object // contains filtered or unexported fields }
Kind is used to provide a source of events originating inside the cluster from Watches (e.g. Pod Create)
Example ¶
This example Watches for Pod Events (e.g. Create / Update / Delete) and enqueues a reconcile.Request with the Name and Namespace of the Pod.
package main import ( corev1 "k8s.io/api/core/v1" "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/handler" "sigs.k8s.io/controller-runtime/pkg/source" ) var ctrl controller.Controller func main() { err := ctrl.Watch(&source.Kind{Type: &corev1.Pod{}}, &handler.EnqueueRequestForObject{}) if err != nil { // handle it } }
Output:
func (*Kind) InjectCache ¶
InjectCache is internal should be called only by the Controller. InjectCache is used to inject the Cache dependency initialized by the ControllerManager.
func (*Kind) Start ¶
func (ks *Kind) Start(ctx context.Context, handler handler.EventHandler, queue workqueue.RateLimitingInterface, prct ...predicate.Predicate) error
Start is internal and should be called only by the Controller to register an EventHandler with the Informer to enqueue reconcile.Requests.
type Source ¶
type Source interface { // Start is internal and should be called only by the Controller to register an EventHandler with the Informer // to enqueue reconcile.Requests. Start(context.Context, handler.EventHandler, workqueue.RateLimitingInterface, ...predicate.Predicate) error }
Source is a source of events (eh.g. Create, Update, Delete operations on Kubernetes Objects, Webhook callbacks, etc) which should be processed by event.EventHandlers to enqueue reconcile.Requests.
* Use Kind for events originating in the cluster (e.g. Pod Create, Pod Update, Deployment Update).
* Use Channel for events originating outside the cluster (eh.g. GitHub Webhook callback, Polling external urls).
Users may build their own Source implementations. If their implementations implement any of the inject package interfaces, the dependencies will be injected by the Controller when Watch is called.
type SyncingSource ¶ added in v0.5.4
SyncingSource is a source that needs syncing prior to being usable. The controller will call its WaitForSync prior to starting workers.
func NewKindWithCache ¶ added in v0.5.1
func NewKindWithCache(object client.Object, cache cache.Cache) SyncingSource
NewKindWithCache creates a Source without InjectCache, so that it is assured that the given cache is used and not overwritten. It can be used to watch objects in a different cluster by passing the cache from that other cluster