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
7ae3136f
Commit
7ae3136f
authored
Apr 28, 2017
by
ravisantoshgudimetla
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Total priority buffer overflow check
parent
dbce213e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
75 additions
and
5 deletions
+75
-5
types.go
plugin/pkg/scheduler/api/types.go
+8
-0
validation.go
plugin/pkg/scheduler/api/validation/validation.go
+2
-2
validation_test.go
plugin/pkg/scheduler/api/validation/validation_test.go
+7
-0
plugins.go
plugin/pkg/scheduler/factory/plugins.go
+17
-2
plugins_test.go
plugin/pkg/scheduler/factory/plugins_test.go
+41
-1
No files found.
plugin/pkg/scheduler/api/types.go
View file @
7ae3136f
...
...
@@ -24,6 +24,14 @@ import (
"k8s.io/kubernetes/pkg/api/v1"
)
const
(
MaxUint
=
^
uint
(
0
)
MaxInt
=
int
(
MaxUint
>>
1
)
MaxTotalPriority
=
MaxInt
MaxPriority
=
10
MaxWeight
=
MaxInt
/
MaxPriority
)
type
Policy
struct
{
metav1
.
TypeMeta
// Holds the information to configure the fit predicate functions
...
...
plugin/pkg/scheduler/api/validation/validation.go
View file @
7ae3136f
...
...
@@ -29,8 +29,8 @@ func ValidatePolicy(policy schedulerapi.Policy) error {
var
validationErrors
[]
error
for
_
,
priority
:=
range
policy
.
Priorities
{
if
priority
.
Weight
<=
0
{
validationErrors
=
append
(
validationErrors
,
fmt
.
Errorf
(
"Priority %s should have a positive weight applied to it"
,
priority
.
Name
))
if
priority
.
Weight
<=
0
||
priority
.
Weight
>=
schedulerapi
.
MaxWeight
{
validationErrors
=
append
(
validationErrors
,
fmt
.
Errorf
(
"Priority %s should have a positive weight applied to it
or it has overflown
"
,
priority
.
Name
))
}
}
...
...
plugin/pkg/scheduler/api/validation/validation_test.go
View file @
7ae3136f
...
...
@@ -51,6 +51,13 @@ func TestValidatePriorityWithNegativeWeight(t *testing.T) {
}
}
func
TestValidatePriorityWithOverFlowWeight
(
t
*
testing
.
T
)
{
policy
:=
api
.
Policy
{
Priorities
:
[]
api
.
PriorityPolicy
{{
Name
:
"WeightPriority"
,
Weight
:
api
.
MaxWeight
}}}
if
ValidatePolicy
(
policy
)
==
nil
{
t
.
Errorf
(
"Expected error about priority weight not being overflown."
)
}
}
func
TestValidateExtenderWithNonNegativeWeight
(
t
*
testing
.
T
)
{
extenderPolicy
:=
api
.
Policy
{
ExtenderConfigs
:
[]
api
.
ExtenderConfig
{{
URLPrefix
:
"http://127.0.0.1:8081/extender"
,
FilterVerb
:
"filter"
,
Weight
:
2
}}}
errs
:=
ValidatePolicy
(
extenderPolicy
)
...
...
plugin/pkg/scheduler/factory/plugins.go
View file @
7ae3136f
...
...
@@ -23,13 +23,12 @@ import (
"strings"
"sync"
"github.com/golang/glog"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/kubernetes/plugin/pkg/scheduler/algorithm"
"k8s.io/kubernetes/plugin/pkg/scheduler/algorithm/predicates"
"k8s.io/kubernetes/plugin/pkg/scheduler/algorithm/priorities"
schedulerapi
"k8s.io/kubernetes/plugin/pkg/scheduler/api"
"github.com/golang/glog"
)
// PluginFactoryArgs are passed to all plugin factory functions.
...
...
@@ -356,9 +355,25 @@ func getPriorityFunctionConfigs(names sets.String, args PluginFactoryArgs) ([]al
})
}
}
if
err
:=
validateSelectedConfigs
(
configs
);
err
!=
nil
{
return
nil
,
err
}
return
configs
,
nil
}
// validateSelectedConfigs validates the config weights to avoid the overflow.
func
validateSelectedConfigs
(
configs
[]
algorithm
.
PriorityConfig
)
error
{
var
totalPriority
int
for
_
,
config
:=
range
configs
{
// Checks totalPriority against MaxTotalPriority to avoid overflow
if
config
.
Weight
*
schedulerapi
.
MaxPriority
>
schedulerapi
.
MaxTotalPriority
-
totalPriority
{
return
fmt
.
Errorf
(
"Total priority of priority functions has overflown"
)
}
totalPriority
+=
config
.
Weight
*
schedulerapi
.
MaxPriority
}
return
nil
}
var
validName
=
regexp
.
MustCompile
(
"^[a-zA-Z0-9]([-a-zA-Z0-9]*[a-zA-Z0-9])$"
)
func
validateAlgorithmNameOrDie
(
name
string
)
{
...
...
plugin/pkg/scheduler/factory/plugins_test.go
View file @
7ae3136f
...
...
@@ -16,7 +16,11 @@ limitations under the License.
package
factory
import
"testing"
import
(
"k8s.io/kubernetes/plugin/pkg/scheduler/algorithm"
"k8s.io/kubernetes/plugin/pkg/scheduler/api"
"testing"
)
func
TestAlgorithmNameValidation
(
t
*
testing
.
T
)
{
algorithmNamesShouldValidate
:=
[]
string
{
...
...
@@ -39,3 +43,39 @@ func TestAlgorithmNameValidation(t *testing.T) {
}
}
}
func
TestValidatePriorityConfigOverFlow
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
description
string
configs
[]
algorithm
.
PriorityConfig
expected
bool
}{
{
description
:
"one of the weights is MaxInt"
,
configs
:
[]
algorithm
.
PriorityConfig
{{
Weight
:
api
.
MaxInt
},
{
Weight
:
5
}},
expected
:
true
,
},
{
description
:
"after multiplication with MaxPriority the weight is larger than MaxWeight"
,
configs
:
[]
algorithm
.
PriorityConfig
{{
Weight
:
api
.
MaxInt
/
api
.
MaxPriority
+
api
.
MaxPriority
},
{
Weight
:
5
}},
expected
:
true
,
},
{
description
:
"normal weights"
,
configs
:
[]
algorithm
.
PriorityConfig
{{
Weight
:
10000
},
{
Weight
:
5
}},
expected
:
false
,
},
}
for
_
,
test
:=
range
tests
{
err
:=
validateSelectedConfigs
(
test
.
configs
)
if
test
.
expected
{
if
err
==
nil
{
t
.
Errorf
(
"Expected Overflow for %s"
,
test
.
description
)
}
}
else
{
if
err
!=
nil
{
t
.
Errorf
(
"Did not expect an overflow for %s"
,
test
.
description
)
}
}
}
}
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