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
c78faec4
Commit
c78faec4
authored
May 07, 2017
by
Klaus Ma
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initialize scheduler cache with assigned non-terminated pods before scheduling.
parent
20fa30e4
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
40 additions
and
1 deletion
+40
-1
factory.go
cmd/libs/go2idl/informer-gen/generators/factory.go
+23
-0
server.go
plugin/cmd/kube-scheduler/app/server.go
+2
-0
factory.go
plugin/pkg/scheduler/factory/factory.go
+3
-0
scheduler.go
plugin/pkg/scheduler/scheduler.go
+9
-1
scheduler_test.go
plugin/pkg/scheduler/scheduler_test.go
+3
-0
No files found.
cmd/libs/go2idl/informer-gen/generators/factory.go
View file @
c78faec4
...
@@ -127,6 +127,28 @@ func (f *sharedInformerFactory) Start(stopCh <-chan struct{}) {
...
@@ -127,6 +127,28 @@ func (f *sharedInformerFactory) Start(stopCh <-chan struct{}) {
}
}
}
}
// WaitForCacheSync waits for all started informers' cache were synced.
func (f *sharedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool {
informers := func()map[reflect.Type]cache.SharedIndexInformer{
f.lock.Lock()
defer f.lock.Unlock()
informers := map[reflect.Type]cache.SharedIndexInformer{}
for informerType, informer := range f.informers {
if f.startedInformers[informerType] {
informers[informerType] = informer
}
}
return informers
}()
res := map[reflect.Type]bool{}
for informType, informer := range informers {
res[informType] = cache.WaitForCacheSync(stopCh, informer.HasSynced)
}
return res
}
// InternalInformerFor returns the SharedIndexInformer for obj using an internal
// InternalInformerFor returns the SharedIndexInformer for obj using an internal
// client.
// client.
func (f *sharedInformerFactory) InformerFor(obj {{.runtimeObject|raw}}, newFunc {{.interfacesNewInformerFunc|raw}}) {{.cacheSharedIndexInformer|raw}} {
func (f *sharedInformerFactory) InformerFor(obj {{.runtimeObject|raw}}, newFunc {{.interfacesNewInformerFunc|raw}}) {{.cacheSharedIndexInformer|raw}} {
...
@@ -152,6 +174,7 @@ var sharedInformerFactoryInterface = `
...
@@ -152,6 +174,7 @@ var sharedInformerFactoryInterface = `
type SharedInformerFactory interface {
type SharedInformerFactory interface {
{{.informerFactoryInterface|raw}}
{{.informerFactoryInterface|raw}}
ForResource(resource {{.schemaGroupVersionResource|raw}}) (GenericInformer, error)
ForResource(resource {{.schemaGroupVersionResource|raw}}) (GenericInformer, error)
WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool
{{$gvInterfaces := .gvInterfaces}}
{{$gvInterfaces := .gvInterfaces}}
{{range $groupName, $group := .groupVersions}}{{$groupName}}() {{index $gvInterfaces $groupName|raw}}
{{range $groupName, $group := .groupVersions}}{{$groupName}}() {{index $gvInterfaces $groupName|raw}}
...
...
plugin/cmd/kube-scheduler/app/server.go
View file @
c78faec4
...
@@ -94,6 +94,8 @@ func Run(s *options.SchedulerServer) error {
...
@@ -94,6 +94,8 @@ func Run(s *options.SchedulerServer) error {
stop
:=
make
(
chan
struct
{})
stop
:=
make
(
chan
struct
{})
defer
close
(
stop
)
defer
close
(
stop
)
informerFactory
.
Start
(
stop
)
informerFactory
.
Start
(
stop
)
// Waiting for all cache to sync before scheduling.
informerFactory
.
WaitForCacheSync
(
stop
)
run
:=
func
(
_
<-
chan
struct
{})
{
run
:=
func
(
_
<-
chan
struct
{})
{
sched
.
Run
()
sched
.
Run
()
...
...
plugin/pkg/scheduler/factory/factory.go
View file @
c78faec4
...
@@ -380,6 +380,9 @@ func (f *ConfigFactory) CreateFromKeys(predicateKeys, priorityKeys sets.String,
...
@@ -380,6 +380,9 @@ func (f *ConfigFactory) CreateFromKeys(predicateKeys, priorityKeys sets.String,
Algorithm
:
algo
,
Algorithm
:
algo
,
Binder
:
&
binder
{
f
.
client
},
Binder
:
&
binder
{
f
.
client
},
PodConditionUpdater
:
&
podConditionUpdater
{
f
.
client
},
PodConditionUpdater
:
&
podConditionUpdater
{
f
.
client
},
WaitForCacheSync
:
func
()
bool
{
return
cache
.
WaitForCacheSync
(
f
.
StopEverything
,
f
.
scheduledPodPopulator
.
HasSynced
)
},
NextPod
:
func
()
*
v1
.
Pod
{
NextPod
:
func
()
*
v1
.
Pod
{
return
f
.
getNextPod
()
return
f
.
getNextPod
()
},
},
...
...
plugin/pkg/scheduler/scheduler.go
View file @
c78faec4
...
@@ -110,6 +110,10 @@ type Config struct {
...
@@ -110,6 +110,10 @@ type Config struct {
// stale while they sit in a channel.
// stale while they sit in a channel.
NextPod
func
()
*
v1
.
Pod
NextPod
func
()
*
v1
.
Pod
// WaitForCacheSync waits for scheduler cache to populate.
// It returns true if it was successful, false if the controller should shutdown.
WaitForCacheSync
func
()
bool
// Error is called if there is an error. It is passed the pod in
// Error is called if there is an error. It is passed the pod in
// question, and the error
// question, and the error
Error
func
(
*
v1
.
Pod
,
error
)
Error
func
(
*
v1
.
Pod
,
error
)
...
@@ -140,8 +144,12 @@ func NewFromConfigurator(c Configurator, modifiers ...func(c *Config)) (*Schedul
...
@@ -140,8 +144,12 @@ func NewFromConfigurator(c Configurator, modifiers ...func(c *Config)) (*Schedul
return
s
,
nil
return
s
,
nil
}
}
// Run begins watching and scheduling. It starts a goroutine and returns immediately.
// Run begins watching and scheduling. It
waits for cache to be synced, then
starts a goroutine and returns immediately.
func
(
sched
*
Scheduler
)
Run
()
{
func
(
sched
*
Scheduler
)
Run
()
{
if
!
sched
.
config
.
WaitForCacheSync
()
{
return
}
go
wait
.
Until
(
sched
.
scheduleOne
,
0
,
sched
.
config
.
StopEverything
)
go
wait
.
Until
(
sched
.
scheduleOne
,
0
,
sched
.
config
.
StopEverything
)
}
}
...
...
plugin/pkg/scheduler/scheduler_test.go
View file @
c78faec4
...
@@ -543,6 +543,9 @@ func setupTestSchedulerLongBindingWithRetry(queuedPodStore *clientcache.FIFO, sc
...
@@ -543,6 +543,9 @@ func setupTestSchedulerLongBindingWithRetry(queuedPodStore *clientcache.FIFO, sc
bindingChan
<-
b
bindingChan
<-
b
return
nil
return
nil
}},
}},
WaitForCacheSync
:
func
()
bool
{
return
true
},
NextPod
:
func
()
*
v1
.
Pod
{
NextPod
:
func
()
*
v1
.
Pod
{
return
clientcache
.
Pop
(
queuedPodStore
)
.
(
*
v1
.
Pod
)
return
clientcache
.
Pop
(
queuedPodStore
)
.
(
*
v1
.
Pod
)
},
},
...
...
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