selector

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BuilderRequirement

type BuilderRequirement struct {
	*resourcepb.ExpressionSelectorRequirement
}

PCRequirement contains a expression, a value, and an operator that relates the field and value. the value is also an expression targeting the parent

func NewBuilderRequirement

func NewBuilderRequirement(expr string, op resourcepb.Operator, vals []string) (BuilderRequirement, error)

NewRequirement is the constructor for a Requirement. If any of these rules is violated, an error is returned:

  1. The operator can only be Equals, DoubleEquals, Gt, Lt, NotEquals, Exists, or DoesNotExist.
  2. If the operator is Equals, DoubleEquals, or NotEquals, the values set must contain one value.

The empty string is a valid value in the input values set. Returned error, if not nil, is guaranteed to be an aggregated field.ErrorList

func (*BuilderRequirement) GetMatch

func (r *BuilderRequirement) GetMatch(parent map[string]any) (string, string, error)

Matches returns true if the Requirement matches the input Labels.

type BuilderRequirements

type BuilderRequirements []BuilderRequirement

Requirements is AND of all requirements.

type Operator

type Operator string
const (
	DoesNotExist Operator = "!"
	Equals       Operator = "="
	DoubleEquals Operator = "=="
	In           Operator = "in"
	NotEquals    Operator = "!="
	NotIn        Operator = "notin"
	Exists       Operator = "exists"
	GreaterThan  Operator = "gt"
	LessThan     Operator = "lt"
)

type Requirement

type Requirement struct {
	*resourcepb.ExpressionSelectorRequirement
}

Requirement contains a expression, a value, and an operator that relates the field and value. This is currently for reading internal selection information of expression selector.

func NewRequirement

func NewRequirement(expr string, op resourcepb.Operator, vals []string) (Requirement, error)

NewRequirement is the constructor for a Requirement. If any of these rules is violated, an error is returned:

  1. The operator can only be In, NotIn, Equals, DoubleEquals, Gt, Lt, NotEquals, Exists, or DoesNotExist.
  2. If the operator is In or NotIn, the values set must be non-empty.
  3. If the operator is Equals, DoubleEquals, or NotEquals, the values set must contain one value.
  4. If the operator is Exists or DoesNotExist, the value set must be empty.
  5. If the operator is Gt or Lt, the values set must contain only one value, which will be interpreted as an integer.

The empty string is a valid value in the input values set. Returned error, if not nil, is guaranteed to be an aggregated field.ErrorList

func (*Requirement) Matches

func (r *Requirement) Matches(data map[string]any) bool

Matches returns true if the Requirement matches the input Labels. There is a match in the following cases:

  1. The operator is Exists and Labels has the Requirement's key.
  2. The operator is In, Labels has the Requirement's key and Labels' value for that key is in Requirement's value set.
  3. The operator is NotIn, Labels has the Requirement's key and Labels' value for that key is not in Requirement's value set.
  4. The operator is DoesNotExist or NotIn and Labels does not have the Requirement's key.
  5. The operator is GreaterThanOperator or LessThanOperator, and Labels has the Requirement's key and the corresponding value satisfies mathematical inequality.

type Requirements

type Requirements []Requirement

Requirements is AND of all requirements.

type Selector

type Selector interface {
	// Matches returns true if this selector matches the given struct.
	Matches(map[string]any) bool

	// Add adds requirements to the Selector
	Add(r ...Requirement) Selector

	// String returns a human readable string that represents this selector.
	String() string
}

func Everything

func Everything() Selector

Everything returns a selector that matches all labels.

func ExprSelectorAsSelector

func ExprSelectorAsSelector(es *selector1alpha1.ExpressionSelector) (Selector, error)

func NewSelector

func NewSelector() Selector

NewSelector returns a nil selector

func Nothing

func Nothing() Selector

Nothing returns a selector that matches no labels

func ResourceExprSelectorAsSelector

func ResourceExprSelectorAsSelector(es *resourcepb.ExpressionSelector) (Selector, error)

type SelectorBuilder

type SelectorBuilder interface {
	// Matches returns true if the expression match both objectss.
	GetSelector(map[string]any) map[string]string

	// Add adds requirements to the Selector
	Add(r ...BuilderRequirement) SelectorBuilder

	String() string
}

func NewSelectorBuilder

func NewSelectorBuilder() SelectorBuilder

NewParentChildSelector returns a nil parent child selector

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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