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 CheckDNS(value string) (err error)
- func CheckKey(key string) (err error)
- func CheckLabels(labels Labels) (err error)
- func CheckName(value string) (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 ParseError
- type Parser
- type Selector
Constants ¶
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 ( // 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" )
Variables ¶
var ( // MaxLabelKeyTotalLen is the maximum total key length. MaxLabelKeyTotalLen = MaxLabelKeyDNSSubdomainLen + MaxLabelKeyLen + 1 )
Functions ¶
func CheckDNS ¶ added in v1.20210103.1
CheckDNS returns if a given value is a conformant DNS_SUBDOMAIN.
See: https://www.ietf.org/rfc/rfc952.txt and https://www.ietf.org/rfc/rfc1123.txt (2.1) for more information.
Specifically a DNS_SUBDOMAIN must: - Be constituted of ([a-z0-9\-\.]) - It must start and end with ([a-z0-9]) - it must be less than 254 characters in length - Characters ('.', '-') cannot repeat
func CheckLabels ¶
CheckLabels validates all the keys and values for the label set.
func CheckName ¶ added in v1.20211016.2
CheckName checks the characters in a name but does not validate the length.
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.
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" // ErrLabelKeyEmpty indicates a key is empty. ErrLabelKeyEmpty Error = "label key empty" // ErrLabelKeyTooLong indicates a key is too long. ErrLabelKeyTooLong Error = "label key too long" // ErrLabelKeyDNSSubdomainEmpty indicates a key's "dns" subdomain is empty, i.e. it is in the form `/foo` ErrLabelKeyDNSSubdomainEmpty Error = "label key dns subdomain empty" // ErrLabelKeyDNSSubdomainTooLong indicates a key's "dns" subdomain is too long. ErrLabelKeyDNSSubdomainTooLong Error = "label key dns subdomain too long; must be less than 253 characters" // ErrLabelValueTooLong indicates a value is too long. ErrLabelValueTooLong Error = "label value too long; must be less than 63 characters" // ErrLabelInvalidCharacter indicates a value contains characters ErrLabelInvalidCharacter Error = `label contains invalid characters, regex used: ([A-Za-z0-9_-.])` // ErrLabelKeyInvalidDNSSubdomain indicates a key contains characters ErrLabelKeyInvalidDNSSubdomain Error = `label key dns subdomain contains invalid dns characters, regex used: ([a-z0-9-.])` // MaxLabelKeyDNSSubdomainLen is the maximum dns prefix length. MaxLabelKeyDNSSubdomainLen = 253 // MaxLabelKeyLen is the maximum key length. MaxLabelKeyLen = 63 // MaxLabelValueLen is the maximum value length. MaxLabelValueLen = 63 )
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 ParseError ¶ added in v1.20210103.1
ParseError is a specific parse error.
func (ParseError) Class ¶ added in v1.20210103.1
func (pe ParseError) Class() error
Class implements ex.ClassProvider.
func (ParseError) Error ¶ added in v1.20210103.1
func (pe ParseError) Error() string
String implements error.
func (ParseError) Unwrap ¶ added in v1.20210103.1
func (pe ParseError) Unwrap() error
Unwrap implements unwrap.
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.
- DNS_SUBDOMAIN is a sequence of one or more characters ([a-z0-9-.]), and must start and end with an alphanumeric ([a-z0-9]). Symbol characters ('.', '-') cannot repeat. Max length is 253 characters.
- DNS_LABEL is a sequence of one or more characters ([A-Za-z0-9_-.]). Max length is 63 characters.
VALUE is a sequence of zero or more characters ([A-Za-z0-9_-.]). Values must start and end with an alphanumeric ([a-z0-9A-Z]). 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.