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 ¶
This section is empty.
Types ¶
type LabelSelector ¶
type LabelSelector struct {
Requirements []Requirement
}
LabelSelector contains a list of Requirements. LabelSelector is set-based and is distinguished from exact match-based selectors composed of key=value matching conjunctions. TODO: Remove previous sentence when exact match-based selectors are removed.
func (*LabelSelector) Matches ¶
func (lsel *LabelSelector) Matches(l Labels) (bool, error)
Matches for a LabelSelector returns true if all its Requirements match the input Labels. If any Requirement does not match, false is returned. An error is returned if any match attempt between a Requirement and the input Labels returns an error.
func (*LabelSelector) String ¶
func (lsel *LabelSelector) String() (string, error)
String returns a comma-separated string of all the LabelSelector Requirements' human-readable strings. An error is returned if any attempt to get a Requirement's human-readable string returns an error.
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 Operator ¶
type Operator int
Operator represents a key's relationship to a set of values in a Requirement.
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. See the NewRequirement constructor for creating a valid Requirement. Requirement is set-based and is distinguished from exact match-based selectors composed of key=value matching. TODO: Remove previous sentence when exact match-based selectors are removed.
func NewRequirement ¶
NewRequirement is the constructor for a Requirement. If either of these rules is violated, an error is returned: (1) The operator can only be In, NotIn or Exists. (2) If the operator is In or NotIn, the values set must
be non-empty.
The empty string is a valid value in the input values set.
func (*Requirement) Matches ¶
func (r *Requirement) Matches(ls Labels) (bool, error)
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 NotIn and Labels does not have the
Requirement's key.
If called on an invalid Requirement, an error is returned. See NewRequirement for creating a valid Requirement.
func (*Requirement) String ¶
func (r *Requirement) String() (string, error)
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.
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 // RequiresExactMatch allows a caller to introspect whether a given selector // requires a single specific label to be set, and if so returns the value it // requires. // TODO: expand this to be more general RequiresExactMatch(label string) (value string, found bool) // String returns a human readable string that represents this selector. String() string }
Selector represents a label selector.
func ParseSelector ¶
ParseSelector takes a string representing a selector and returns an object suitable for matching, or an error.
func SelectorFromSet ¶
SelectorFromSet returns a Selector which will match exactly the given Set. A nil Set is considered equivalent to Everything().