labels

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Labels

type Labels interface {
	Get(key string) string
	Has(key string) bool
}

Labels is a set of labels.

type Operator

type Operator string

Operator represents a key's relationship operator.

const (
	// Exists is a special operator that checks whether a key exists.
	Exists Operator = "exists"
	// NotExist is a special operator that checks whether a key does not exist.
	NotExist Operator = "!"
	// Equals is a regular key/value matching.
	Equals Operator = "="
	// NotEquals is a regular key/value matching.
	NotEquals Operator = "!="
	// In is a regular key/value matching.
	In Operator = "in"
	// NotIn is a regular key/value matching.
	NotIn Operator = "notin"
	// GreaterThan is a regular key/value matching.
	GreaterThan Operator = ">"
	// LessThan is a regular key/value matching.
	LessThan Operator = "<"
	// GreaterOrEqual is a regular key/value matching.
	GreaterOrEqual Operator = ">="
	// LessOrEqual is a regular key/value matching.
	LessOrEqual Operator = "<="
)

type Requirement

type Requirement struct {
	// contains filtered or unexported fields
}

Requirement is a single key/value pair that is used to filter

func NewRequirement

func NewRequirement(key string, op Operator, vals []string) (*Requirement, error)

NewRequirement creates a new Requirement based on the provided key, operator and values. If any of these rules is violated, an error is returned when constructed. 1. The Operator must be one of the predefined constants. such as: Exists, NotExist, Equals, NotEquals, In, NotIn, GreaterThan, LessThan, GreaterOrEqual, LessOrEqual 2. For operators GreaterThan, LessThan, GreaterOrEqual, LessOrEqual, the values must be a number. 3. For operators In, NotIn, the values must not be empty. 4. For operators Exists, NotExist, the values must not be empty. 5. For operators Equals, NotEquals, the values must have exactly one entry.

func (*Requirement) Matches

func (r *Requirement) Matches(labels Labels) bool

Matches checks whether the given Labels match this Requirement.

func (*Requirement) String

func (r *Requirement) String() string

String converts a Requirement to a string.

type Requirements

type Requirements []Requirement

Requirements is a single element selector.

func (Requirements) AddRequirement

func (x Requirements) AddRequirement(r ...Requirement) Selector

AddRequirement adds new Requirement to this Selector.

func (Requirements) Matches

func (x Requirements) Matches(labels Labels) bool

Matches returns true if all requirements matches the given Labels.

func (Requirements) String

func (x Requirements) String() string

String converts this Selector to a string.

type Selector

type Selector interface {
	// Matches returns true if the specified Labels match this Selector.
	Matches(labels Labels) bool

	// AddRequirement adds new Requirement to this Selector.
	AddRequirement(r ...Requirement) Selector
}

Selector is a label selector.

func NewSelector

func NewSelector() Selector

NewSelector creates an empty Selector.

func Parse

func Parse(in string) Selector

Parse parses a string into a Requirements.

type Set

type Set map[string]string

Set is a set of key-value pairs.

func (Set) AsSelector

func (s Set) AsSelector() Selector

AsSelector converts labels into a selectors. It does not perform any validation, which means the server will reject the request if the Set contains invalid values.

func (Set) AsValidatedSelector

func (s Set) AsValidatedSelector() (Selector, error)

AsValidatedSelector converts labels into a selectors. The Set is validated client-side, which allows to catch errors early.

func (Set) Get

func (s Set) Get(key string) string

Get returns the value of the given label.

func (Set) Has

func (s Set) Has(key string) bool

Has returns true if the given label is set.

func (Set) String

func (s Set) String() string

String returns all labels listed as a human-readable string. The returned operator defaults to Equals, Used ',' join between multiple key-value pairs.

Jump to

Keyboard shortcuts

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