Documentation
¶
Overview ¶
Package selector is a high performance selector parsing library, tightly coupled to the functionality of selectors found in Kubernetes.
Index ¶
- Constants
- Variables
- func CheckKey(key string) (err error)
- func CheckLabels(labels Labels) (err error)
- func CheckValue(value string) error
- func SkipValidation(p *Parser)
- type And
- type Any
- type Equals
- type Error
- type HasKey
- type In
- type Labels
- type NotEquals
- type NotHasKey
- type NotIn
- type Option
- type Parser
- type Selector
Constants ¶
const ( // OpEquals is an operator. OpEquals = "=" // OpDoubleEquals is an operator. OpDoubleEquals = "==" // OpNotEquals is an operator. OpNotEquals = "!=" // OpIn is an operator. OpIn = "in" // OpNotIn is an operator. OpNotIn = "notin" )
const ( // At is a common rune. At = rune('@') // Colon is a common rune. Colon = rune(':') // Dash is a common rune. Dash = rune('-') // Underscore is a common rune. Underscore = rune('_') // Dot is a common rune. Dot = rune('.') // ForwardSlash is a common rune. ForwardSlash = rune('/') // BackSlash is a common rune. BackSlash = rune('\\') // BackTick is a common rune. BackTick = rune('`') // Bang is a common rune. Bang = rune('!') // Comma is a common rune. Comma = rune(',') // OpenBracket is a common rune. OpenBracket = rune('[') // OpenParens is a common rune. OpenParens = rune('(') // OpenCurly is a common rune. OpenCurly = rune('{') // CloseBracket is a common rune. CloseBracket = rune(']') // CloseParens is a common rune. CloseParens = rune(')') // Equal is a common rune. Equal = rune('=') // Space is a common rune. Space = rune(' ') // Tab is a common rune. Tab = rune('\t') // Tilde is a common rune. Tilde = rune('~') // CarriageReturn is a common rune. CarriageReturn = rune('\r') // NewLine is a common rune. NewLine = rune('\n') )
const ( // ErrInvalidOperator is returned if the operator is invalid. ErrInvalidOperator = Error("invalid operator") // ErrInvalidSelector is returned if there is a structural issue with the selector. ErrInvalidSelector = Error("invalid selector") // ErrKeyEmpty indicates a key is empty. ErrKeyEmpty = Error("key empty") // ErrKeyTooLong indicates a key is too long. ErrKeyTooLong = Error("key too long") // ErrKeyDNSPrefixEmpty indicates a key's "dns" prefix is empty. ErrKeyDNSPrefixEmpty = Error("key dns prefix empty") // ErrKeyDNSPrefixTooLong indicates a key's "dns" prefix is empty. ErrKeyDNSPrefixTooLong = Error("key dns prefix too long; must be less than 253 characters") // ErrValueTooLong indicates a value is too long. ErrValueTooLong = Error("value too long; must be less than 63 characters") // ErrKeyInvalidCharacter indicates a key contains characters ErrKeyInvalidCharacter = Error(`key contains invalid characters, regex used: ([A-Za-z0-9_-\.])`) // MaxDNSPrefixLen is the maximum dns prefix length. MaxDNSPrefixLen = 253 // MaxKeyLen is the maximum key length. MaxKeyLen = 63 // MaxValueLen is the maximum value length. MaxValueLen = 63 )
Variables ¶
var ( // MaxKeyTotalLen is the maximum total key length. MaxKeyTotalLen = MaxDNSPrefixLen + MaxKeyLen + 1 )
Functions ¶
func CheckLabels ¶
CheckLabels validates all the keys and values for the label set.
func SkipValidation ¶
func SkipValidation(p *Parser)
SkipValidation is an option to skip checking the values of selector expressions.
Types ¶
type And ¶
type And []Selector
And is a combination selector.
type Any ¶
type Any struct{}
Any matches everything
type Equals ¶
type Equals struct {
Key, Value string
}
Equals returns if a key strictly equals a value.
type Error ¶
type Error string
Error is a hard alias to string.
func (Error) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
type HasKey ¶
type HasKey string
HasKey returns if a label set has a given key.
type In ¶
In returns if a key matches a set of values.
type NotEquals ¶
type NotEquals struct {
Key, Value string
}
NotEquals returns if a key strictly equals a value.
type NotHasKey ¶
type NotHasKey string
NotHasKey returns if a label set does not have a given key.
type NotIn ¶
NotIn returns if a key does not match a set of values.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser parses a selector incrementally.
type Selector ¶
Selector is the common interface for selector types.
func Parse ¶
Parse takes a string representing a selector and returns a selector object, or an error. 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. Max length is 63 characters. VALUE is a sequence of zero or more characters "([A-Za-z0-9_-\.])". Max length is 63 characters. 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.