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
9abf4b1d
Commit
9abf4b1d
authored
Oct 31, 2017
by
xiangpengzhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test case for validateIPVSSchedulerMethod.
parent
36a3193c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
13 deletions
+55
-13
validation.go
cmd/kube-proxy/app/validation.go
+13
-13
validation_test.go
cmd/kube-proxy/app/validation_test.go
+42
-0
No files found.
cmd/kube-proxy/app/validation.go
View file @
9abf4b1d
...
...
@@ -38,7 +38,7 @@ func Validate(config *componentconfig.KubeProxyConfiguration) field.ErrorList {
allErrs
=
append
(
allErrs
,
validateKubeProxyConntrackConfiguration
(
config
.
Conntrack
,
newPath
.
Child
(
"KubeProxyConntrackConfiguration"
))
...
)
allErrs
=
append
(
allErrs
,
validateProxyMode
(
config
.
Mode
,
newPath
.
Child
(
"Mode"
))
...
)
allErrs
=
append
(
allErrs
,
validateClientConnectionConfiguration
(
config
.
ClientConnection
,
newPath
.
Child
(
"ClientConnection"
))
...
)
allErrs
=
append
(
allErrs
,
validateIPVSSchedulerMethod
(
co
nfig
.
IPVS
.
Scheduler
,
newPath
.
Child
(
"KubeProxyIPVSConfiguration"
)
.
Child
(
"Scheduler"
))
...
)
allErrs
=
append
(
allErrs
,
validateIPVSSchedulerMethod
(
co
mponentconfig
.
IPVSSchedulerMethod
(
config
.
IPVS
.
Scheduler
)
,
newPath
.
Child
(
"KubeProxyIPVSConfiguration"
)
.
Child
(
"Scheduler"
))
...
)
if
config
.
OOMScoreAdj
!=
nil
&&
(
*
config
.
OOMScoreAdj
<
-
1000
||
*
config
.
OOMScoreAdj
>
1000
)
{
allErrs
=
append
(
allErrs
,
field
.
Invalid
(
newPath
.
Child
(
"OOMScoreAdj"
),
*
config
.
OOMScoreAdj
,
"must be within the range [-1000, 1000]"
))
...
...
@@ -159,18 +159,18 @@ func validateHostPort(input string, fldPath *field.Path) field.ErrorList {
return
allErrs
}
func
validateIPVSSchedulerMethod
(
scheduler
string
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
supportedMethod
:=
[]
string
{
string
(
componentconfig
.
RoundRobin
)
,
string
(
componentconfig
.
WeightedRoundRobin
)
,
string
(
componentconfig
.
LeastConnection
)
,
string
(
componentconfig
.
WeightedLeastConnection
)
,
string
(
componentconfig
.
LocalityBasedLeastConnection
)
,
string
(
componentconfig
.
LocalityBasedLeastConnectionWithReplication
)
,
string
(
componentconfig
.
SourceHashing
)
,
string
(
componentconfig
.
DestinationHashing
)
,
string
(
componentconfig
.
ShortestExpectedDelay
)
,
string
(
componentconfig
.
NeverQueue
)
,
func
validateIPVSSchedulerMethod
(
scheduler
componentconfig
.
IPVSSchedulerMethod
,
fldPath
*
field
.
Path
)
field
.
ErrorList
{
supportedMethod
:=
[]
componentconfig
.
IPVSSchedulerMethod
{
componentconfig
.
RoundRobin
,
componentconfig
.
WeightedRoundRobin
,
componentconfig
.
LeastConnection
,
componentconfig
.
WeightedLeastConnection
,
componentconfig
.
LocalityBasedLeastConnection
,
componentconfig
.
LocalityBasedLeastConnectionWithReplication
,
componentconfig
.
SourceHashing
,
componentconfig
.
DestinationHashing
,
componentconfig
.
ShortestExpectedDelay
,
componentconfig
.
NeverQueue
,
""
,
}
allErrs
:=
field
.
ErrorList
{}
...
...
cmd/kube-proxy/app/validation_test.go
View file @
9abf4b1d
...
...
@@ -489,3 +489,45 @@ func TestValidateHostPort(t *testing.T) {
}
}
}
func
TestValidateIPVSSchedulerMethod
(
t
*
testing
.
T
)
{
newPath
:=
field
.
NewPath
(
"KubeProxyConfiguration"
)
successCases
:=
[]
componentconfig
.
IPVSSchedulerMethod
{
componentconfig
.
RoundRobin
,
componentconfig
.
WeightedRoundRobin
,
componentconfig
.
LeastConnection
,
componentconfig
.
WeightedLeastConnection
,
componentconfig
.
LocalityBasedLeastConnection
,
componentconfig
.
LocalityBasedLeastConnectionWithReplication
,
componentconfig
.
SourceHashing
,
componentconfig
.
DestinationHashing
,
componentconfig
.
ShortestExpectedDelay
,
componentconfig
.
NeverQueue
,
""
,
}
for
_
,
successCase
:=
range
successCases
{
if
errs
:=
validateIPVSSchedulerMethod
(
successCase
,
newPath
.
Child
(
"Scheduler"
));
len
(
errs
)
!=
0
{
t
.
Errorf
(
"expected success: %v"
,
errs
)
}
}
errorCases
:=
[]
struct
{
mode
componentconfig
.
IPVSSchedulerMethod
msg
string
}{
{
mode
:
componentconfig
.
IPVSSchedulerMethod
(
"non-existing"
),
msg
:
"blank means the default algorithm method (currently rr)"
,
},
}
for
_
,
errorCase
:=
range
errorCases
{
if
errs
:=
validateIPVSSchedulerMethod
(
errorCase
.
mode
,
newPath
.
Child
(
"ProxyMode"
));
len
(
errs
)
==
0
{
t
.
Errorf
(
"expected failure for %s"
,
errorCase
.
msg
)
}
else
if
!
strings
.
Contains
(
errs
[
0
]
.
Error
(),
errorCase
.
msg
)
{
t
.
Errorf
(
"unexpected error: %v, expected: %s"
,
errs
[
0
],
errorCase
.
msg
)
}
}
}
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