predicate

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package predicate provides serializable predicate support for filtering Kubernetes resources in Δ-controller source specifications.

Predicates allow controllers to selectively watch and process resource changes that match specific criteria, improving performance and reducing unnecessary reconciliation work.

Supported predicate types:

  • GenerationChanged: Triggers on metadata.generation changes.
  • ResourceVersionChanged: Triggers on any resource changes.
  • LabelChanged: Triggers on label modifications.
  • AnnotationChanged: Triggers on annotation modifications.

Boolean combinators allow complex predicate logic:

  • And: All predicates must be true.
  • Or: Any predicate must be true.
  • Not: Inverts predicate result.

Predicates are JSON-serializable and can be embedded in Operator specifications to control source resource filtering behavior.

Example usage:

predicate := Predicate{
    BoolPredicate: BoolPredicate{
        "And": []Predicate{
            {BasicPredicate: &BasicPredicate("GenerationChanged")},
            {BasicPredicate: &BasicPredicate("LabelChanged")},
        },
    },
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromLabelSelector

func FromLabelSelector(labelSelector metav1.LabelSelector) (predicate.TypedPredicate[client.Object], error)

FromLabelSelector creates converts a seriaized label selector into a native controller runtime label selector predicate.

func FromNamespace

func FromNamespace(namespace string) predicate.TypedPredicate[client.Object]

FromNamespace creates a namespace selector predicate from a namespace.

func FromPredicate

func FromPredicate(predicate Predicate) (predicate.TypedPredicate[client.Object], error)

FromPredicate converts a serialized Predicate into a native controller runtime predicate.

Types

type BasicPredicate

type BasicPredicate string

BasicPredicate represents an elemental predicate, namely one of "GenerationChanged", "ResourceVersionChanged", "LabelChanged" or "AnnotationChanged".

func (*BasicPredicate) ToPredicate

func (pw *BasicPredicate) ToPredicate() (predicate.TypedPredicate[client.Object], error)

ToPredicate implements ToPredicate() for basic predicates.

type BoolPredicate

type BoolPredicate map[string]([]Predicate)

BoolPredicate is a complex predicate composed of basic predicates and other bool predicates.

func (*BoolPredicate) ToPredicate

func (cp *BoolPredicate) ToPredicate() (predicate.TypedPredicate[client.Object], error)

ToPredicate implements ToPredicate() for bool predicates.

type Interface

type Interface interface {
	// ToPredicate converts a serialized predicate into a native controller runtime predicate.
	ToPredicate() (predicate.TypedPredicate[client.Object], error)
}

Interface is the general interface for predicates.

type Predicate

type Predicate struct {
	*BasicPredicate `json:",inline"`
	*BoolPredicate  `json:",inline"`
}

Predicate is the top level representation of a predicate.

func (*Predicate) DeepCopy

func (p *Predicate) DeepCopy() *Predicate

DeepCopy copies a predicate.

func (Predicate) DeepCopyInto

func (p Predicate) DeepCopyInto(d *Predicate)

DeepCopyInto copies a predicate into target predicate.

func (Predicate) MarshalJSON

func (p Predicate) MarshalJSON() ([]byte, error)

MarshalJSON encodes a predicate in JSON format.

func (*Predicate) ToPredicate

func (p *Predicate) ToPredicate() (predicate.TypedPredicate[client.Object], error)

ToPredicate converts a serialized predicate into a native controller runtime predicate.

func (*Predicate) UnmarshalJSON

func (p *Predicate) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes a predicate from JSON format.

Jump to

Keyboard shortcuts

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