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
2662ca30
Unverified
Commit
2662ca30
authored
Sep 27, 2018
by
k8s-ci-robot
Committed by
GitHub
Sep 27, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #69037 from shubheksha/fix/68964-simplify-run-method-kube-scheduler-server
Simplify kube-scheduler's run() method
parents
25607dea
564ee221
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
51 deletions
+54
-51
server.go
cmd/kube-scheduler/app/server.go
+54
-51
No files found.
cmd/kube-scheduler/app/server.go
View file @
2662ca30
...
...
@@ -81,35 +81,7 @@ constraints, affinity and anti-affinity specifications, data locality, inter-wor
interference, deadlines, and so on. Workload-specific requirements will be exposed
through the API as necessary.`
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
verflag
.
PrintAndExitIfRequested
()
utilflag
.
PrintFlags
(
cmd
.
Flags
())
if
len
(
args
)
!=
0
{
fmt
.
Fprint
(
os
.
Stderr
,
"arguments are not supported
\n
"
)
}
if
errs
:=
opts
.
Validate
();
len
(
errs
)
>
0
{
fmt
.
Fprintf
(
os
.
Stderr
,
"%v
\n
"
,
utilerrors
.
NewAggregate
(
errs
))
os
.
Exit
(
1
)
}
if
len
(
opts
.
WriteConfigTo
)
>
0
{
if
err
:=
options
.
WriteConfigFile
(
opts
.
WriteConfigTo
,
&
opts
.
ComponentConfig
);
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"%v
\n
"
,
err
)
os
.
Exit
(
1
)
}
glog
.
Infof
(
"Wrote configuration to: %s
\n
"
,
opts
.
WriteConfigTo
)
return
}
c
,
err
:=
opts
.
Config
()
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"%v
\n
"
,
err
)
os
.
Exit
(
1
)
}
stopCh
:=
make
(
chan
struct
{})
if
err
:=
Run
(
c
.
Complete
(),
stopCh
);
err
!=
nil
{
if
err
:=
run
(
cmd
,
args
,
opts
);
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"%v
\n
"
,
err
)
os
.
Exit
(
1
)
}
...
...
@@ -122,8 +94,39 @@ through the API as necessary.`,
return
cmd
}
// Run runs the Scheduler.
func
Run
(
c
schedulerserverconfig
.
CompletedConfig
,
stopCh
<-
chan
struct
{})
error
{
// run runs the scheduler.
func
run
(
cmd
*
cobra
.
Command
,
args
[]
string
,
opts
*
options
.
Options
)
error
{
verflag
.
PrintAndExitIfRequested
()
utilflag
.
PrintFlags
(
cmd
.
Flags
())
if
len
(
args
)
!=
0
{
fmt
.
Fprint
(
os
.
Stderr
,
"arguments are not supported
\n
"
)
}
if
errs
:=
opts
.
Validate
();
len
(
errs
)
>
0
{
fmt
.
Fprintf
(
os
.
Stderr
,
"%v
\n
"
,
utilerrors
.
NewAggregate
(
errs
))
os
.
Exit
(
1
)
}
if
len
(
opts
.
WriteConfigTo
)
>
0
{
if
err
:=
options
.
WriteConfigFile
(
opts
.
WriteConfigTo
,
&
opts
.
ComponentConfig
);
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"%v
\n
"
,
err
)
os
.
Exit
(
1
)
}
glog
.
Infof
(
"Wrote configuration to: %s
\n
"
,
opts
.
WriteConfigTo
)
}
c
,
err
:=
opts
.
Config
()
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"%v
\n
"
,
err
)
os
.
Exit
(
1
)
}
stopCh
:=
make
(
chan
struct
{})
// Get the completed config
cc
:=
c
.
Complete
()
// To help debugging, immediately log version
glog
.
Infof
(
"Version: %+v"
,
version
.
Get
())
...
...
@@ -139,7 +142,7 @@ func Run(c schedulerserverconfig.CompletedConfig, stopCh <-chan struct{}) error
}
// Build a scheduler config from the provided algorithm source.
schedulerConfig
,
err
:=
NewSchedulerConfig
(
c
)
schedulerConfig
,
err
:=
NewSchedulerConfig
(
c
c
)
if
err
!=
nil
{
return
err
}
...
...
@@ -148,39 +151,39 @@ func Run(c schedulerserverconfig.CompletedConfig, stopCh <-chan struct{}) error
sched
:=
scheduler
.
NewFromConfig
(
schedulerConfig
)
// Prepare the event broadcaster.
if
c
.
Broadcaster
!=
nil
&&
c
.
EventClient
!=
nil
{
c
.
Broadcaster
.
StartRecordingToSink
(
&
v1core
.
EventSinkImpl
{
Interface
:
c
.
EventClient
.
Events
(
""
)})
if
c
c
.
Broadcaster
!=
nil
&&
c
c
.
EventClient
!=
nil
{
c
c
.
Broadcaster
.
StartRecordingToSink
(
&
v1core
.
EventSinkImpl
{
Interface
:
c
c
.
EventClient
.
Events
(
""
)})
}
// Start up the healthz server.
if
c
.
InsecureServing
!=
nil
{
separateMetrics
:=
c
.
InsecureMetricsServing
!=
nil
handler
:=
buildHandlerChain
(
newHealthzHandler
(
&
c
.
ComponentConfig
,
separateMetrics
),
nil
,
nil
)
if
err
:=
c
.
InsecureServing
.
Serve
(
handler
,
0
,
stopCh
);
err
!=
nil
{
if
c
c
.
InsecureServing
!=
nil
{
separateMetrics
:=
c
c
.
InsecureMetricsServing
!=
nil
handler
:=
buildHandlerChain
(
newHealthzHandler
(
&
c
c
.
ComponentConfig
,
separateMetrics
),
nil
,
nil
)
if
err
:=
c
c
.
InsecureServing
.
Serve
(
handler
,
0
,
stopCh
);
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to start healthz server: %v"
,
err
)
}
}
if
c
.
InsecureMetricsServing
!=
nil
{
handler
:=
buildHandlerChain
(
newMetricsHandler
(
&
c
.
ComponentConfig
),
nil
,
nil
)
if
err
:=
c
.
InsecureMetricsServing
.
Serve
(
handler
,
0
,
stopCh
);
err
!=
nil
{
if
c
c
.
InsecureMetricsServing
!=
nil
{
handler
:=
buildHandlerChain
(
newMetricsHandler
(
&
c
c
.
ComponentConfig
),
nil
,
nil
)
if
err
:=
c
c
.
InsecureMetricsServing
.
Serve
(
handler
,
0
,
stopCh
);
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to start metrics server: %v"
,
err
)
}
}
if
c
.
SecureServing
!=
nil
{
handler
:=
buildHandlerChain
(
newHealthzHandler
(
&
c
.
ComponentConfig
,
false
),
c
.
Authentication
.
Authenticator
,
c
.
Authorization
.
Authorizer
)
if
err
:=
c
.
SecureServing
.
Serve
(
handler
,
0
,
stopCh
);
err
!=
nil
{
if
c
c
.
SecureServing
!=
nil
{
handler
:=
buildHandlerChain
(
newHealthzHandler
(
&
c
c
.
ComponentConfig
,
false
),
cc
.
Authentication
.
Authenticator
,
c
c
.
Authorization
.
Authorizer
)
if
err
:=
c
c
.
SecureServing
.
Serve
(
handler
,
0
,
stopCh
);
err
!=
nil
{
// fail early for secure handlers, removing the old error loop from above
return
fmt
.
Errorf
(
"failed to start healthz server: %v"
,
err
)
}
}
// Start all informers.
go
c
.
PodInformer
.
Informer
()
.
Run
(
stopCh
)
c
.
InformerFactory
.
Start
(
stopCh
)
go
c
c
.
PodInformer
.
Informer
()
.
Run
(
stopCh
)
c
c
.
InformerFactory
.
Start
(
stopCh
)
// Wait for all caches to sync before scheduling.
c
.
InformerFactory
.
WaitForCacheSync
(
stopCh
)
controller
.
WaitForCacheSync
(
"scheduler"
,
stopCh
,
c
.
PodInformer
.
Informer
()
.
HasSynced
)
c
c
.
InformerFactory
.
WaitForCacheSync
(
stopCh
)
controller
.
WaitForCacheSync
(
"scheduler"
,
stopCh
,
c
c
.
PodInformer
.
Informer
()
.
HasSynced
)
// Prepare a reusable run function.
run
:=
func
(
ctx
context
.
Context
)
{
...
...
@@ -200,14 +203,14 @@ func Run(c schedulerserverconfig.CompletedConfig, stopCh <-chan struct{}) error
}()
// If leader election is enabled, run via LeaderElector until done and exit.
if
c
.
LeaderElection
!=
nil
{
c
.
LeaderElection
.
Callbacks
=
leaderelection
.
LeaderCallbacks
{
if
c
c
.
LeaderElection
!=
nil
{
c
c
.
LeaderElection
.
Callbacks
=
leaderelection
.
LeaderCallbacks
{
OnStartedLeading
:
run
,
OnStoppedLeading
:
func
()
{
utilruntime
.
HandleError
(
fmt
.
Errorf
(
"lost master"
))
},
}
leaderElector
,
err
:=
leaderelection
.
NewLeaderElector
(
*
c
.
LeaderElection
)
leaderElector
,
err
:=
leaderelection
.
NewLeaderElector
(
*
c
c
.
LeaderElection
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"couldn't create leader elector: %v"
,
err
)
}
...
...
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