Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
d7485de0
Commit
d7485de0
authored
May 27, 2017
by
Ethan Chu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix golint error in apimachinery/pkg/{fields,lables}
Also add these two packages to linted packages lists
parent
b58c7ec4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
16 deletions
+41
-16
.linted_packages
hack/.linted_packages
+2
-0
selector.go
staging/src/k8s.io/apimachinery/pkg/fields/selector.go
+4
-4
selector.go
staging/src/k8s.io/apimachinery/pkg/labels/selector.go
+35
-12
No files found.
hack/.linted_packages
View file @
d7485de0
...
...
@@ -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/apimachinery
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/serializer/json
staging/src/k8s.io/apimachinery/pkg/runtime/serializer/recognizer/testing
...
...
staging/src/k8s.io/apimachinery/pkg/fields/selector.go
View file @
d7485de0
...
...
@@ -222,7 +222,7 @@ var valueEscaper = strings.NewReplacer(
`=`
,
`\=`
,
)
// Escapes an arbitrary literal string for use as a fieldSelector value
// Escape
Value escape
s an arbitrary literal string for use as a fieldSelector value
func
EscapeValue
(
s
string
)
string
{
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
)
}
// Unescapes a fieldSelector value and returns the original literal value.
// Unescape
Value unescape
s a fieldSelector value and returns the original literal value.
// May return the original string if it contains no escaped or special characters.
func
UnescapeValue
(
s
string
)
(
string
,
error
)
{
// 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.
// Parse
AndTransformSelector parse
s the selector and runs them through the given TransformFunc.
func
ParseAndTransformSelector
(
selector
string
,
fn
TransformFunc
)
(
Selector
,
error
)
{
return
parseSelector
(
selector
,
fn
)
}
//
Function to transform
selectors.
//
TransformFunc transforms
selectors.
type
TransformFunc
func
(
field
,
value
string
)
(
newField
,
newValue
string
,
err
error
)
// splitTerms returns the comma-separated terms contained in the given fieldSelector.
...
...
staging/src/k8s.io/apimachinery/pkg/labels/selector.go
View file @
d7485de0
...
...
@@ -71,13 +71,14 @@ func Nothing() Selector {
return
nothingSelector
{}
}
// NewSelector returns a nil selector
func
NewSelector
()
Selector
{
return
internalSelector
(
nil
)
}
type
internalSelector
[]
Requirement
//
Sort by key to obtain determisi
tic parser
//
ByKey sorts requirements by key to obtain determinis
tic parser
type
ByKey
[]
Requirement
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
{
return
r
.
key
}
// Operator returns requirement operator
func
(
r
*
Requirement
)
Operator
()
selection
.
Operator
{
return
r
.
operator
}
// Values returns requirement values
func
(
r
*
Requirement
)
Values
()
sets
.
String
{
ret
:=
sets
.
String
{}
for
i
:=
range
r
.
strValues
{
...
...
@@ -229,7 +235,7 @@ func (r *Requirement) Values() sets.String {
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
{
if
lsel
==
nil
{
return
true
...
...
@@ -320,23 +326,37 @@ func (lsel internalSelector) String() string {
return
strings
.
Join
(
reqs
,
","
)
}
//
constants
definition for lexer token
//
Token represents constant
definition for lexer token
type
Token
int
const
(
// ErrorToken represents scan error
ErrorToken
Token
=
iota
// EndOfStringToken represents end of string
EndOfStringToken
// ClosedParToken represents close parenthesis
ClosedParToken
// CommaToken represents the comma
CommaToken
// DoesNotExistToken represents logic not
DoesNotExistToken
// DoubleEqualsToken represents double equals
DoubleEqualsToken
// EqualsToken represents equal
EqualsToken
// GreaterThanToken represents greater than
GreaterThanToken
IdentifierToken
// to represent keys and values
// IdentifierToken represents identifier, e.g. keys and values
IdentifierToken
// InToken represents in
InToken
// LessThanToken represents less than
LessThanToken
// NotEqualsToken represents not equal
NotEqualsToken
// NotInToken represents not in
NotInToken
// OpenParToken represents open parenthesis
OpenParToken
)
...
...
@@ -356,7 +376,7 @@ var string2token = map[string]Token{
"("
:
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
{
tok
Token
literal
string
...
...
@@ -401,8 +421,8 @@ func (l *Lexer) unread() {
l
.
pos
--
}
// scanI
d
OrKeyword scans string to recognize literal token (for example 'in') or an identifier.
func
(
l
*
Lexer
)
scanI
d
OrKeyword
()
(
tok
Token
,
lit
string
)
{
// scanI
D
OrKeyword scans string to recognize literal token (for example 'in') or an identifier.
func
(
l
*
Lexer
)
scanI
D
OrKeyword
()
(
tok
Token
,
lit
string
)
{
var
buffer
[]
byte
IdentifierLoop
:
for
{
...
...
@@ -474,7 +494,7 @@ func (l *Lexer) Lex() (tok Token, lit string) {
return
l
.
scanSpecialSymbol
()
default
:
l
.
unread
()
return
l
.
scanI
d
OrKeyword
()
return
l
.
scanI
D
OrKeyword
()
}
}
...
...
@@ -485,14 +505,16 @@ type Parser struct {
position
int
}
// Parser
c
ontext represents context during parsing:
// Parser
C
ontext 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)'
type
ParserContext
int
const
(
// KeyAndOperator represents key and operator
KeyAndOperator
ParserContext
=
iota
// Values represents values
Values
)
...
...
@@ -798,11 +820,12 @@ func SelectorFromSet(ls Set) Selector {
}
var
requirements
internalSelector
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?
return
internalSelector
{}
}
else
{
requirements
=
append
(
requirements
,
*
r
)
}
}
// sort to have deterministic string representation
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment