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
2792f1a2
Unverified
Commit
2792f1a2
authored
Mar 31, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
Mar 31, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #75857 from danielqsj/sc1
support both JSON and YAML for scheduler configuration
parents
d0c0883a
412adb8c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
162 additions
and
2 deletions
+162
-2
BUILD
pkg/scheduler/api/latest/BUILD
+1
-0
latest.go
pkg/scheduler/api/latest/latest.go
+4
-2
scheduler_test.go
pkg/scheduler/scheduler_test.go
+93
-0
scheduler_test.go
test/integration/scheduler/scheduler_test.go
+64
-0
No files found.
pkg/scheduler/api/latest/BUILD
View file @
2792f1a2
...
...
@@ -16,6 +16,7 @@ go_library(
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer/json:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer/versioning:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer/yaml:go_default_library",
],
)
...
...
pkg/scheduler/api/latest/latest.go
View file @
2792f1a2
...
...
@@ -21,6 +21,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer/json"
"k8s.io/apimachinery/pkg/runtime/serializer/versioning"
"k8s.io/apimachinery/pkg/runtime/serializer/yaml"
schedulerapi
"k8s.io/kubernetes/pkg/scheduler/api"
// Init the api v1 package
_
"k8s.io/kubernetes/pkg/scheduler/api/v1"
...
...
@@ -44,10 +45,11 @@ var Codec runtime.Codec
func
init
()
{
jsonSerializer
:=
json
.
NewSerializer
(
json
.
DefaultMetaFactory
,
schedulerapi
.
Scheme
,
schedulerapi
.
Scheme
,
true
)
serializer
:=
yaml
.
NewDecodingSerializer
(
jsonSerializer
)
Codec
=
versioning
.
NewDefaultingCodecForScheme
(
schedulerapi
.
Scheme
,
jsonS
erializer
,
jsonS
erializer
,
s
erializer
,
s
erializer
,
schema
.
GroupVersion
{
Version
:
Version
},
runtime
.
InternalGroupVersioner
,
)
...
...
pkg/scheduler/scheduler_test.go
View file @
2792f1a2
...
...
@@ -19,6 +19,9 @@ package scheduler
import
(
"errors"
"fmt"
"io/ioutil"
"os"
"path"
"reflect"
"testing"
"time"
...
...
@@ -43,6 +46,7 @@ import (
"k8s.io/kubernetes/pkg/scheduler/algorithm/predicates"
"k8s.io/kubernetes/pkg/scheduler/algorithm/priorities"
"k8s.io/kubernetes/pkg/scheduler/api"
schedulerapi
"k8s.io/kubernetes/pkg/scheduler/api"
kubeschedulerconfig
"k8s.io/kubernetes/pkg/scheduler/apis/config"
"k8s.io/kubernetes/pkg/scheduler/core"
"k8s.io/kubernetes/pkg/scheduler/factory"
...
...
@@ -935,3 +939,92 @@ func TestSchedulerWithVolumeBinding(t *testing.T) {
})
}
}
func
TestInitPolicyFromFile
(
t
*
testing
.
T
)
{
dir
,
err
:=
ioutil
.
TempDir
(
os
.
TempDir
(),
"policy"
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
defer
os
.
RemoveAll
(
dir
)
for
i
,
test
:=
range
[]
struct
{
policy
string
expectedPredicates
sets
.
String
expectedPrioritizers
sets
.
String
}{
// Test json format policy file
{
policy
:
`{
"kind" : "Policy",
"apiVersion" : "v1",
"predicates" : [
{"name" : "PredicateOne"},
{"name" : "PredicateTwo"}
],
"priorities" : [
{"name" : "PriorityOne", "weight" : 1},
{"name" : "PriorityTwo", "weight" : 5}
]
}`
,
expectedPredicates
:
sets
.
NewString
(
"PredicateOne"
,
"PredicateTwo"
,
),
expectedPrioritizers
:
sets
.
NewString
(
"PriorityOne"
,
"PriorityTwo"
,
),
},
// Test yaml format policy file
{
policy
:
`apiVersion: v1
kind: Policy
predicates:
- name: PredicateOne
- name: PredicateTwo
priorities:
- name: PriorityOne
weight: 1
- name: PriorityTwo
weight: 5
`
,
expectedPredicates
:
sets
.
NewString
(
"PredicateOne"
,
"PredicateTwo"
,
),
expectedPrioritizers
:
sets
.
NewString
(
"PriorityOne"
,
"PriorityTwo"
,
),
},
}
{
file
:=
fmt
.
Sprintf
(
"scheduler-policy-config-file-%d"
,
i
)
fullPath
:=
path
.
Join
(
dir
,
file
)
if
err
:=
ioutil
.
WriteFile
(
fullPath
,
[]
byte
(
test
.
policy
),
0644
);
err
!=
nil
{
t
.
Fatalf
(
"Failed writing a policy config file: %v"
,
err
)
}
policy
:=
&
schedulerapi
.
Policy
{}
if
err
:=
initPolicyFromFile
(
fullPath
,
policy
);
err
!=
nil
{
t
.
Fatalf
(
"Failed writing a policy config file: %v"
,
err
)
}
// Verify that the policy is initialized correctly.
schedPredicates
:=
sets
.
NewString
()
for
_
,
p
:=
range
policy
.
Predicates
{
schedPredicates
.
Insert
(
p
.
Name
)
}
schedPrioritizers
:=
sets
.
NewString
()
for
_
,
p
:=
range
policy
.
Priorities
{
schedPrioritizers
.
Insert
(
p
.
Name
)
}
if
!
schedPredicates
.
Equal
(
test
.
expectedPredicates
)
{
t
.
Errorf
(
"Expected predicates %v, got %v"
,
test
.
expectedPredicates
,
schedPredicates
)
}
if
!
schedPrioritizers
.
Equal
(
test
.
expectedPrioritizers
)
{
t
.
Errorf
(
"Expected priority functions %v, got %v"
,
test
.
expectedPrioritizers
,
schedPrioritizers
)
}
}
}
test/integration/scheduler/scheduler_test.go
View file @
2792f1a2
...
...
@@ -162,6 +162,70 @@ func TestSchedulerCreationFromConfigMap(t *testing.T) {
),
expectedPrioritizers
:
sets
.
NewString
(),
},
{
policy
:
`apiVersion: v1
kind: Policy
predicates:
- name: PredicateOne
- name: PredicateTwo
priorities:
- name: PriorityOne
weight: 1
- name: PriorityTwo
weight: 5
`
,
expectedPredicates
:
sets
.
NewString
(
"CheckNodeCondition"
,
// mandatory predicate
"PredicateOne"
,
"PredicateTwo"
,
),
expectedPrioritizers
:
sets
.
NewString
(
"PriorityOne"
,
"PriorityTwo"
,
),
},
{
policy
:
`apiVersion: v1
kind: Policy
`
,
expectedPredicates
:
sets
.
NewString
(
"CheckNodeCondition"
,
// mandatory predicate
"CheckNodeDiskPressure"
,
"CheckNodeMemoryPressure"
,
"CheckNodePIDPressure"
,
"CheckVolumeBinding"
,
"GeneralPredicates"
,
"MatchInterPodAffinity"
,
"MaxAzureDiskVolumeCount"
,
"MaxCSIVolumeCountPred"
,
"MaxEBSVolumeCount"
,
"MaxGCEPDVolumeCount"
,
"NoDiskConflict"
,
"NoVolumeZoneConflict"
,
"PodToleratesNodeTaints"
,
),
expectedPrioritizers
:
sets
.
NewString
(
"BalancedResourceAllocation"
,
"InterPodAffinityPriority"
,
"LeastRequestedPriority"
,
"NodeAffinityPriority"
,
"NodePreferAvoidPodsPriority"
,
"SelectorSpreadPriority"
,
"TaintTolerationPriority"
,
"ImageLocalityPriority"
,
),
},
{
policy
:
`apiVersion: v1
kind: Policy
predicates: []
priorities: []
`
,
expectedPredicates
:
sets
.
NewString
(
"CheckNodeCondition"
,
// mandatory predicate
),
expectedPrioritizers
:
sets
.
NewString
(),
},
}
{
// Add a ConfigMap object.
configPolicyName
:=
fmt
.
Sprintf
(
"scheduler-custom-policy-config-%d"
,
i
)
...
...
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