controller-runtime: sigs.k8s.io/controller-runtime/pkg/predicate Index | Examples | Files

package predicate

import "sigs.k8s.io/controller-runtime/pkg/predicate"

Package predicate defines Predicates used by Controllers to filter Events before they are provided to EventHandlers.

Index

Examples

Package Files

doc.go predicate.go

type Funcs Uses

type Funcs struct {
    // Create returns true if the Create event should be processed
    CreateFunc func(event.CreateEvent) bool

    // Delete returns true if the Delete event should be processed
    DeleteFunc func(event.DeleteEvent) bool

    // Update returns true if the Update event should be processed
    UpdateFunc func(event.UpdateEvent) bool

    // Generic returns true if the Generic event should be processed
    GenericFunc func(event.GenericEvent) bool
}

Funcs is a function that implements Predicate.

This example creates a new Predicate to drop Update Events where the Generation has not changed.

Code:

package main

import (
    "sigs.k8s.io/controller-runtime/pkg/event"
    "sigs.k8s.io/controller-runtime/pkg/predicate"
)

var p predicate.Predicate

// This example creates a new Predicate to drop Update Events where the Generation has not changed.
func main() {
    p = predicate.Funcs{
        UpdateFunc: func(e event.UpdateEvent) bool {
            return e.MetaOld.GetGeneration() != e.MetaNew.GetGeneration()
        },
    }
}

func (Funcs) Create Uses

func (p Funcs) Create(e event.CreateEvent) bool

Create implements Predicate

func (Funcs) Delete Uses

func (p Funcs) Delete(e event.DeleteEvent) bool

Delete implements Predicate

func (Funcs) Generic Uses

func (p Funcs) Generic(e event.GenericEvent) bool

Generic implements Predicate

func (Funcs) Update Uses

func (p Funcs) Update(e event.UpdateEvent) bool

Update implements Predicate

type GenerationChangedPredicate Uses

type GenerationChangedPredicate struct {
    Funcs
}

GenerationChangedPredicate implements a default update predicate function on Generation change.

This predicate will skip update events that have no change in the object's metadata.generation field. The metadata.generation field of an object is incremented by the API server when writes are made to the spec field of an object. This allows a controller to ignore update events where the spec is unchanged, and only the metadata and/or status fields are changed.

For CustomResource objects the Generation is only incremented when the status subresource is enabled.

Caveats:

* The assumption that the Generation is incremented only on writing to the spec does not hold for all APIs. E.g For Deployment objects the Generation is also incremented on writes to the metadata.annotations field. For object types other than CustomResources be sure to verify which fields will trigger a Generation increment when they are written to.

* With this predicate, any update events with writes only to the status field will not be reconciled. So in the event that the status block is overwritten or wiped by someone else the controller will not self-correct to restore the correct status.

func (GenerationChangedPredicate) Update Uses

func (GenerationChangedPredicate) Update(e event.UpdateEvent) bool

Update implements default UpdateEvent filter for validating generation change

type Predicate Uses

type Predicate interface {
    // Create returns true if the Create event should be processed
    Create(event.CreateEvent) bool

    // Delete returns true if the Delete event should be processed
    Delete(event.DeleteEvent) bool

    // Update returns true if the Update event should be processed
    Update(event.UpdateEvent) bool

    // Generic returns true if the Generic event should be processed
    Generic(event.GenericEvent) bool
}

Predicate filters events before enqueuing the keys.

type ResourceVersionChangedPredicate Uses

type ResourceVersionChangedPredicate struct {
    Funcs
}

ResourceVersionChangedPredicate implements a default update predicate function on resource version change

func (ResourceVersionChangedPredicate) Update Uses

func (ResourceVersionChangedPredicate) Update(e event.UpdateEvent) bool

Update implements default UpdateEvent filter for validating resource version change

Package predicate imports 2 packages (graph) and is imported by 94 packages. Updated 2019-08-14. Refresh now. Tools for package owners.