mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
Fix golint error in apimachinery/pkg/{fields,lables}
Also add these two packages to linted packages lists
This commit is contained in:
parent
b58c7ec456
commit
d7485de02a
@ -315,6 +315,8 @@ staging/src/k8s.io/apimachinery/pkg/api/errors
|
|||||||
staging/src/k8s.io/apimachinery/pkg/api/resource
|
staging/src/k8s.io/apimachinery/pkg/api/resource
|
||||||
staging/src/k8s.io/apimachinery/pkg/apimachinery
|
staging/src/k8s.io/apimachinery/pkg/apimachinery
|
||||||
staging/src/k8s.io/apimachinery/pkg/conversion/queryparams
|
staging/src/k8s.io/apimachinery/pkg/conversion/queryparams
|
||||||
|
staging/src/k8s.io/apimachinery/pkg/fields
|
||||||
|
staging/src/k8s.io/apimachinery/pkg/labels
|
||||||
staging/src/k8s.io/apimachinery/pkg/runtime
|
staging/src/k8s.io/apimachinery/pkg/runtime
|
||||||
staging/src/k8s.io/apimachinery/pkg/runtime/serializer/json
|
staging/src/k8s.io/apimachinery/pkg/runtime/serializer/json
|
||||||
staging/src/k8s.io/apimachinery/pkg/runtime/serializer/recognizer/testing
|
staging/src/k8s.io/apimachinery/pkg/runtime/serializer/recognizer/testing
|
||||||
|
@ -222,7 +222,7 @@ var valueEscaper = strings.NewReplacer(
|
|||||||
`=`, `\=`,
|
`=`, `\=`,
|
||||||
)
|
)
|
||||||
|
|
||||||
// Escapes an arbitrary literal string for use as a fieldSelector value
|
// EscapeValue escapes an arbitrary literal string for use as a fieldSelector value
|
||||||
func EscapeValue(s string) string {
|
func EscapeValue(s string) string {
|
||||||
return valueEscaper.Replace(s)
|
return valueEscaper.Replace(s)
|
||||||
}
|
}
|
||||||
@ -245,7 +245,7 @@ func (i UnescapedRune) Error() string {
|
|||||||
return fmt.Sprintf("invalid field selector: unescaped character in value: %v", i.r)
|
return fmt.Sprintf("invalid field selector: unescaped character in value: %v", i.r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unescapes a fieldSelector value and returns the original literal value.
|
// UnescapeValue unescapes a fieldSelector value and returns the original literal value.
|
||||||
// May return the original string if it contains no escaped or special characters.
|
// May return the original string if it contains no escaped or special characters.
|
||||||
func UnescapeValue(s string) (string, error) {
|
func UnescapeValue(s string) (string, error) {
|
||||||
// if there's no escaping or special characters, just return to avoid allocation
|
// if there's no escaping or special characters, just return to avoid allocation
|
||||||
@ -307,12 +307,12 @@ func ParseSelector(selector string) (Selector, error) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parses the selector and runs them through the given TransformFunc.
|
// ParseAndTransformSelector parses the selector and runs them through the given TransformFunc.
|
||||||
func ParseAndTransformSelector(selector string, fn TransformFunc) (Selector, error) {
|
func ParseAndTransformSelector(selector string, fn TransformFunc) (Selector, error) {
|
||||||
return parseSelector(selector, fn)
|
return parseSelector(selector, fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to transform selectors.
|
// TransformFunc transforms selectors.
|
||||||
type TransformFunc func(field, value string) (newField, newValue string, err error)
|
type TransformFunc func(field, value string) (newField, newValue string, err error)
|
||||||
|
|
||||||
// splitTerms returns the comma-separated terms contained in the given fieldSelector.
|
// splitTerms returns the comma-separated terms contained in the given fieldSelector.
|
||||||
|
@ -71,13 +71,14 @@ func Nothing() Selector {
|
|||||||
return nothingSelector{}
|
return nothingSelector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewSelector returns a nil selector
|
||||||
func NewSelector() Selector {
|
func NewSelector() Selector {
|
||||||
return internalSelector(nil)
|
return internalSelector(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
type internalSelector []Requirement
|
type internalSelector []Requirement
|
||||||
|
|
||||||
// Sort by key to obtain determisitic parser
|
// ByKey sorts requirements by key to obtain deterministic parser
|
||||||
type ByKey []Requirement
|
type ByKey []Requirement
|
||||||
|
|
||||||
func (a ByKey) Len() int { return len(a) }
|
func (a ByKey) Len() int { return len(a) }
|
||||||
@ -215,12 +216,17 @@ func (r *Requirement) Matches(ls Labels) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Key returns requirement key
|
||||||
func (r *Requirement) Key() string {
|
func (r *Requirement) Key() string {
|
||||||
return r.key
|
return r.key
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Operator returns requirement operator
|
||||||
func (r *Requirement) Operator() selection.Operator {
|
func (r *Requirement) Operator() selection.Operator {
|
||||||
return r.operator
|
return r.operator
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Values returns requirement values
|
||||||
func (r *Requirement) Values() sets.String {
|
func (r *Requirement) Values() sets.String {
|
||||||
ret := sets.String{}
|
ret := sets.String{}
|
||||||
for i := range r.strValues {
|
for i := range r.strValues {
|
||||||
@ -229,7 +235,7 @@ func (r *Requirement) Values() sets.String {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return true if the internalSelector doesn't restrict selection space
|
// Empty returns true if the internalSelector doesn't restrict selection space
|
||||||
func (lsel internalSelector) Empty() bool {
|
func (lsel internalSelector) Empty() bool {
|
||||||
if lsel == nil {
|
if lsel == nil {
|
||||||
return true
|
return true
|
||||||
@ -320,23 +326,37 @@ func (lsel internalSelector) String() string {
|
|||||||
return strings.Join(reqs, ",")
|
return strings.Join(reqs, ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
// constants definition for lexer token
|
// Token represents constant definition for lexer token
|
||||||
type Token int
|
type Token int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// ErrorToken represents scan error
|
||||||
ErrorToken Token = iota
|
ErrorToken Token = iota
|
||||||
|
// EndOfStringToken represents end of string
|
||||||
EndOfStringToken
|
EndOfStringToken
|
||||||
|
// ClosedParToken represents close parenthesis
|
||||||
ClosedParToken
|
ClosedParToken
|
||||||
|
// CommaToken represents the comma
|
||||||
CommaToken
|
CommaToken
|
||||||
|
// DoesNotExistToken represents logic not
|
||||||
DoesNotExistToken
|
DoesNotExistToken
|
||||||
|
// DoubleEqualsToken represents double equals
|
||||||
DoubleEqualsToken
|
DoubleEqualsToken
|
||||||
|
// EqualsToken represents equal
|
||||||
EqualsToken
|
EqualsToken
|
||||||
|
// GreaterThanToken represents greater than
|
||||||
GreaterThanToken
|
GreaterThanToken
|
||||||
IdentifierToken // to represent keys and values
|
// IdentifierToken represents identifier, e.g. keys and values
|
||||||
|
IdentifierToken
|
||||||
|
// InToken represents in
|
||||||
InToken
|
InToken
|
||||||
|
// LessThanToken represents less than
|
||||||
LessThanToken
|
LessThanToken
|
||||||
|
// NotEqualsToken represents not equal
|
||||||
NotEqualsToken
|
NotEqualsToken
|
||||||
|
// NotInToken represents not in
|
||||||
NotInToken
|
NotInToken
|
||||||
|
// OpenParToken represents open parenthesis
|
||||||
OpenParToken
|
OpenParToken
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -356,7 +376,7 @@ var string2token = map[string]Token{
|
|||||||
"(": OpenParToken,
|
"(": OpenParToken,
|
||||||
}
|
}
|
||||||
|
|
||||||
// The item produced by the lexer. It contains the Token and the literal.
|
// ScannedItem contains the Token and the literal produced by the lexer.
|
||||||
type ScannedItem struct {
|
type ScannedItem struct {
|
||||||
tok Token
|
tok Token
|
||||||
literal string
|
literal string
|
||||||
@ -401,8 +421,8 @@ func (l *Lexer) unread() {
|
|||||||
l.pos--
|
l.pos--
|
||||||
}
|
}
|
||||||
|
|
||||||
// scanIdOrKeyword scans string to recognize literal token (for example 'in') or an identifier.
|
// scanIDOrKeyword scans string to recognize literal token (for example 'in') or an identifier.
|
||||||
func (l *Lexer) scanIdOrKeyword() (tok Token, lit string) {
|
func (l *Lexer) scanIDOrKeyword() (tok Token, lit string) {
|
||||||
var buffer []byte
|
var buffer []byte
|
||||||
IdentifierLoop:
|
IdentifierLoop:
|
||||||
for {
|
for {
|
||||||
@ -474,7 +494,7 @@ func (l *Lexer) Lex() (tok Token, lit string) {
|
|||||||
return l.scanSpecialSymbol()
|
return l.scanSpecialSymbol()
|
||||||
default:
|
default:
|
||||||
l.unread()
|
l.unread()
|
||||||
return l.scanIdOrKeyword()
|
return l.scanIDOrKeyword()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -485,14 +505,16 @@ type Parser struct {
|
|||||||
position int
|
position int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parser context represents context during parsing:
|
// ParserContext represents context during parsing:
|
||||||
// some literal for example 'in' and 'notin' can be
|
// some literal for example 'in' and 'notin' can be
|
||||||
// recognized as operator for example 'x in (a)' but
|
// recognized as operator for example 'x in (a)' but
|
||||||
// it can be recognized as value for example 'value in (in)'
|
// it can be recognized as value for example 'value in (in)'
|
||||||
type ParserContext int
|
type ParserContext int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// KeyAndOperator represents key and operator
|
||||||
KeyAndOperator ParserContext = iota
|
KeyAndOperator ParserContext = iota
|
||||||
|
// Values represents values
|
||||||
Values
|
Values
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -798,11 +820,12 @@ func SelectorFromSet(ls Set) Selector {
|
|||||||
}
|
}
|
||||||
var requirements internalSelector
|
var requirements internalSelector
|
||||||
for label, value := range ls {
|
for label, value := range ls {
|
||||||
if r, err := NewRequirement(label, selection.Equals, []string{value}); err != nil {
|
r, err := NewRequirement(label, selection.Equals, []string{value})
|
||||||
|
if err == nil {
|
||||||
|
requirements = append(requirements, *r)
|
||||||
|
} else {
|
||||||
//TODO: double check errors when input comes from serialization?
|
//TODO: double check errors when input comes from serialization?
|
||||||
return internalSelector{}
|
return internalSelector{}
|
||||||
} else {
|
|
||||||
requirements = append(requirements, *r)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// sort to have deterministic string representation
|
// sort to have deterministic string representation
|
||||||
|
Loading…
Reference in New Issue
Block a user