Documentation ¶
Overview ¶
Package labels implements a simple label system, parsing and matching selectors with sets of labels.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatLabels ¶ added in v1.0.7
FormatLables convert label map into plain string
Types ¶
type Labels ¶
type Labels interface { // Has returns whether the provided label exists. Has(label string) (exists bool) // Get returns the value for the provided label. Get(label string) (value string) }
Labels allows you to present labels independently from their storage.
type Lexer ¶
type Lexer struct {
// contains filtered or unexported fields
}
Lexer represents the Lexer struct for label selector. It contains necessary informationt to tokenize the input string
type Operator ¶
type Operator string
Operator represents a key's relationship to a set of values in a Requirement.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser data structure contains the label selector parser data strucutre
type ParserContext ¶
type ParserContext int
Parser context represents context during parsing: some literal for example 'in' and 'notin' can be recognized as operator for example 'x in (a)' but it can be recognized as value for example 'value in (in)'
const ( KeyAndOperator ParserContext = iota Values )
type Requirement ¶
type Requirement struct {
// contains filtered or unexported fields
}
Requirement is a selector that contains values, a key and an operator that relates the key and values. The zero value of Requirement is invalid. Requirement implements both set based match and exact match Requirement is initialized via NewRequirement constructor for creating a valid Requirement.
func NewRequirement ¶
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, 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) The key is invalid due to its length, or sequence
of characters. See validateLabelKey for more details.
The empty string is a valid value in the input values set.
func (*Requirement) Key ¶ added in v1.0.7
func (r *Requirement) Key() string
func (*Requirement) Matches ¶
func (r *Requirement) Matches(ls Labels) 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.
func (*Requirement) Operator ¶ added in v1.0.7
func (r *Requirement) Operator() Operator
func (*Requirement) String ¶
func (r *Requirement) String() string
String returns a human-readable string that represents this Requirement. If called on an invalid Requirement, an error is returned. See NewRequirement for creating a valid Requirement.
func (*Requirement) Values ¶ added in v1.0.7
func (r *Requirement) Values() sets.String
type ScannedItem ¶
type ScannedItem struct {
// contains filtered or unexported fields
}
The item produced by the lexer. It contains the Token and the literal.
type Selector ¶
type Selector interface { // Matches returns true if this selector matches the given set of labels. Matches(Labels) bool // Empty returns true if this selector does not restrict the selection space. Empty() bool // String returns a human readable string that represents this selector. String() string // Add adds requirements to the Selector Add(r ...Requirement) Selector }
Selector represents a label selector.
func NewSelector ¶ added in v1.1.2
func NewSelector() Selector
func Nothing ¶ added in v1.0.8
func Nothing() Selector
Nothing returns a selector that matches no labels
func Parse ¶
Parse takes a string representing a selector and returns a selector object, or an error. This parsing function differs from ParseSelector as they parse different selectors with different syntaxes. The input will cause an error if it does not follow this form:
<selector-syntax> ::= <requirement> | <requirement> "," <selector-syntax> ] <requirement> ::= [!] KEY [ <set-based-restriction> | <exact-match-restriction> ] <set-based-restriction> ::= "" | <inclusion-exclusion> <value-set> <inclusion-exclusion> ::= <inclusion> | <exclusion>
<exclusion> ::= "notin" <inclusion> ::= "in" <value-set> ::= "(" <values> ")" <values> ::= VALUE | VALUE "," <values>
<exact-match-restriction> ::= ["="|"=="|"!="] VALUE KEY is a sequence of one or more characters following [ DNS_SUBDOMAIN "/" ] DNS_LABEL VALUE is a sequence of zero or more characters "([A-Za-z0-9_-\.])". Max length is 64 character. Delimiter is white space: (' ', '\t') Example of valid syntax:
"x in (foo,,baz),y,z notin ()"
Note:
(1) Inclusion - " in " - denotes that the KEY exists and is equal to any of the VALUEs in its requirement (2) Exclusion - " notin " - denotes that the KEY is not equal to any of the VALUEs in its requirement or does not exist (3) The empty string is a valid VALUE (4) A requirement with just a KEY - as in "y" above - denotes that the KEY exists and can be any VALUE. (5) A requirement with just !KEY requires that the KEY not exist.
func SelectorFromSet ¶
SelectorFromSet returns a Selector which will match exactly the given Set. A nil and empty Sets are considered equivalent to Everything().