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
4a3b1a2b
Commit
4a3b1a2b
authored
Apr 02, 2015
by
Daniel Smith
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6375 from abhgupta/abhgupta-dev
Validating against negative weights for priority functions
parents
414be101
8deedf8e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
8 deletions
+7
-8
validation.go
plugin/pkg/scheduler/api/validation/validation.go
+2
-2
validation_test.go
plugin/pkg/scheduler/api/validation/validation_test.go
+5
-6
No files found.
plugin/pkg/scheduler/api/validation/validation.go
View file @
4a3b1a2b
...
@@ -29,8 +29,8 @@ func ValidatePolicy(policy schedulerapi.Policy) error {
...
@@ -29,8 +29,8 @@ func ValidatePolicy(policy schedulerapi.Policy) error {
validationErrors
:=
make
([]
error
,
0
)
validationErrors
:=
make
([]
error
,
0
)
for
_
,
priority
:=
range
policy
.
Priorities
{
for
_
,
priority
:=
range
policy
.
Priorities
{
if
priority
.
Weight
=
=
0
{
if
priority
.
Weight
<
=
0
{
validationErrors
=
append
(
validationErrors
,
fmt
.
Errorf
(
"Priority %s should have a
non-zero
weight applied to it"
,
priority
.
Name
))
validationErrors
=
append
(
validationErrors
,
fmt
.
Errorf
(
"Priority %s should have a
positive
weight applied to it"
,
priority
.
Name
))
}
}
}
}
...
...
plugin/pkg/scheduler/api/validation/validation_test.go
View file @
4a3b1a2b
...
@@ -25,29 +25,28 @@ import (
...
@@ -25,29 +25,28 @@ import (
func
TestValidatePriorityWithNoWeight
(
t
*
testing
.
T
)
{
func
TestValidatePriorityWithNoWeight
(
t
*
testing
.
T
)
{
policy
:=
api
.
Policy
{
Priorities
:
[]
api
.
PriorityPolicy
{{
Name
:
"NoWeightPriority"
}}}
policy
:=
api
.
Policy
{
Priorities
:
[]
api
.
PriorityPolicy
{{
Name
:
"NoWeightPriority"
}}}
if
ValidatePolicy
(
policy
)
==
nil
{
if
ValidatePolicy
(
policy
)
==
nil
{
t
.
Errorf
(
"Expected error about priority weight
being zero
"
)
t
.
Errorf
(
"Expected error about priority weight
not being positive
"
)
}
}
}
}
func
TestValidatePriorityWithZeroWeight
(
t
*
testing
.
T
)
{
func
TestValidatePriorityWithZeroWeight
(
t
*
testing
.
T
)
{
policy
:=
api
.
Policy
{
Priorities
:
[]
api
.
PriorityPolicy
{{
Name
:
"NoWeightPriority"
,
Weight
:
0
}}}
policy
:=
api
.
Policy
{
Priorities
:
[]
api
.
PriorityPolicy
{{
Name
:
"NoWeightPriority"
,
Weight
:
0
}}}
if
ValidatePolicy
(
policy
)
==
nil
{
if
ValidatePolicy
(
policy
)
==
nil
{
t
.
Errorf
(
"Expected error about priority weight
being zero
"
)
t
.
Errorf
(
"Expected error about priority weight
not being positive
"
)
}
}
}
}
func
TestValidatePriorityWithNonZeroWeight
(
t
*
testing
.
T
)
{
func
TestValidatePriorityWithNonZeroWeight
(
t
*
testing
.
T
)
{
policy
:=
api
.
Policy
{
Priorities
:
[]
api
.
PriorityPolicy
{{
Name
:
"WeightPriority"
,
Weight
:
2
}}}
policy
:=
api
.
Policy
{
Priorities
:
[]
api
.
PriorityPolicy
{{
Name
:
"WeightPriority"
,
Weight
:
2
}}}
errs
:=
ValidatePolicy
(
policy
)
errs
:=
ValidatePolicy
(
policy
)
if
ValidatePolicy
(
policy
)
!=
nil
{
if
errs
!=
nil
{
t
.
Errorf
(
"Unexpected errors %v"
,
errs
)
t
.
Errorf
(
"Unexpected errors %v"
,
errs
)
}
}
}
}
func
TestValidatePriorityWithNegativeWeight
(
t
*
testing
.
T
)
{
func
TestValidatePriorityWithNegativeWeight
(
t
*
testing
.
T
)
{
policy
:=
api
.
Policy
{
Priorities
:
[]
api
.
PriorityPolicy
{{
Name
:
"WeightPriority"
,
Weight
:
-
2
}}}
policy
:=
api
.
Policy
{
Priorities
:
[]
api
.
PriorityPolicy
{{
Name
:
"WeightPriority"
,
Weight
:
-
2
}}}
errs
:=
ValidatePolicy
(
policy
)
if
ValidatePolicy
(
policy
)
==
nil
{
if
ValidatePolicy
(
policy
)
!=
nil
{
t
.
Errorf
(
"Expected error about priority weight not being positive"
)
t
.
Errorf
(
"Unexpected errors %v"
,
errs
)
}
}
}
}
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