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
cb4b3476
Unverified
Commit
cb4b3476
authored
May 06, 2020
by
Darren Shepherd
Committed by
GitHub
May 06, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1759 from ibuildthecloud/background
Start kube-apiserver in the background
parents
e5fe184a
072396f7
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
63 additions
and
25 deletions
+63
-25
server.go
pkg/cli/server/server.go
+8
-5
types.go
pkg/daemons/config/types.go
+2
-1
server.go
pkg/daemons/control/server.go
+25
-11
embed.go
pkg/daemons/executor/embed.go
+4
-2
executor.go
pkg/daemons/executor/executor.go
+6
-6
server.go
pkg/server/server.go
+18
-0
No files found.
pkg/cli/server/server.go
View file @
cb4b3476
...
...
@@ -192,11 +192,14 @@ func run(app *cli.Context, cfg *cmds.Server) error {
return
err
}
logrus
.
Info
(
"k3s is up and running"
)
if
notifySocket
!=
""
{
os
.
Setenv
(
"NOTIFY_SOCKET"
,
notifySocket
)
systemd
.
SdNotify
(
true
,
"READY=1
\n
"
)
}
go
func
()
{
<-
serverConfig
.
ControlConfig
.
Runtime
.
APIServerReady
logrus
.
Info
(
"k3s is up and running"
)
if
notifySocket
!=
""
{
os
.
Setenv
(
"NOTIFY_SOCKET"
,
notifySocket
)
systemd
.
SdNotify
(
true
,
"READY=1
\n
"
)
}
}()
if
cfg
.
DisableAgent
{
<-
ctx
.
Done
()
...
...
pkg/daemons/config/types.go
View file @
cb4b3476
...
...
@@ -145,7 +145,8 @@ type ControlRuntimeBootstrap struct {
type
ControlRuntime
struct
{
ControlRuntimeBootstrap
HTTPBootstrap
bool
HTTPBootstrap
bool
APIServerReady
<-
chan
struct
{}
ClientKubeAPICert
string
ClientKubeAPIKey
string
...
...
pkg/daemons/control/server.go
View file @
cb4b3476
...
...
@@ -73,7 +73,6 @@ users:
)
const
(
userTokenSize
=
8
ipsecTokenSize
=
48
aescbcKeySize
=
32
)
...
...
@@ -96,7 +95,7 @@ func Server(ctx context.Context, cfg *config.Control) error {
return
err
}
if
err
:=
waitForAPIServer
(
ctx
,
runtime
);
err
!=
nil
{
if
err
:=
waitForAPIServer
InBackground
(
ctx
,
runtime
);
err
!=
nil
{
return
err
}
...
...
@@ -141,7 +140,7 @@ func controllerManager(cfg *config.Control, runtime *config.ControlRuntime) erro
args
:=
config
.
GetArgsList
(
argsMap
,
cfg
.
ExtraControllerArgs
)
logrus
.
Infof
(
"Running kube-controller-manager %s"
,
config
.
ArgString
(
args
))
return
executor
.
ControllerManager
(
args
)
return
executor
.
ControllerManager
(
runtime
.
APIServerReady
,
args
)
}
func
scheduler
(
cfg
*
config
.
Control
,
runtime
*
config
.
ControlRuntime
)
error
{
...
...
@@ -157,7 +156,7 @@ func scheduler(cfg *config.Control, runtime *config.ControlRuntime) error {
args
:=
config
.
GetArgsList
(
argsMap
,
cfg
.
ExtraSchedulerAPIArgs
)
logrus
.
Infof
(
"Running kube-scheduler %s"
,
config
.
ArgString
(
args
))
return
executor
.
Scheduler
(
args
)
return
executor
.
Scheduler
(
runtime
.
APIServerReady
,
args
)
}
func
apiServer
(
ctx
context
.
Context
,
cfg
*
config
.
Control
,
runtime
*
config
.
ControlRuntime
)
(
authenticator
.
Request
,
http
.
Handler
,
error
)
{
...
...
@@ -830,7 +829,7 @@ func checkForCloudControllerPrivileges(runtime *config.ControlRuntime) error {
return
nil
}
func
waitForAPIServer
(
ctx
context
.
Context
,
runtime
*
config
.
ControlRuntime
)
error
{
func
waitForAPIServer
InBackground
(
ctx
context
.
Context
,
runtime
*
config
.
ControlRuntime
)
error
{
restConfig
,
err
:=
clientcmd
.
BuildConfigFromFlags
(
""
,
runtime
.
KubeConfigAdmin
)
if
err
!=
nil
{
return
err
...
...
@@ -841,12 +840,27 @@ func waitForAPIServer(ctx context.Context, runtime *config.ControlRuntime) error
return
err
}
select
{
case
<-
ctx
.
Done
()
:
return
ctx
.
Err
()
case
err
:=
<-
promise
(
func
()
error
{
return
app2
.
WaitForAPIServer
(
k8sClient
,
5
*
time
.
Minute
)
})
:
return
err
}
done
:=
make
(
chan
struct
{})
runtime
.
APIServerReady
=
done
go
func
()
{
defer
close
(
done
)
logrus
.
Infof
(
"Waiting for API server to become available"
)
for
{
select
{
case
<-
ctx
.
Done
()
:
return
case
err
:=
<-
promise
(
func
()
error
{
return
app2
.
WaitForAPIServer
(
k8sClient
,
30
*
time
.
Second
)
})
:
if
err
!=
nil
{
logrus
.
Infof
(
"Waiting for API server to become available"
)
continue
}
return
}
}
}()
return
nil
}
func
promise
(
f
func
()
error
)
<-
chan
error
{
...
...
pkg/daemons/executor/embed.go
View file @
cb4b3476
...
...
@@ -57,22 +57,24 @@ func (Embedded) APIServer(ctx context.Context, args []string) (authenticator.Req
return
startupConfig
.
Authenticator
,
startupConfig
.
Handler
,
nil
}
func
(
Embedded
)
Scheduler
(
args
[]
string
)
error
{
func
(
Embedded
)
Scheduler
(
a
piReady
<-
chan
struct
{},
a
rgs
[]
string
)
error
{
command
:=
sapp
.
NewSchedulerCommand
()
command
.
SetArgs
(
args
)
go
func
()
{
<-
apiReady
logrus
.
Fatalf
(
"scheduler exited: %v"
,
command
.
Execute
())
}()
return
nil
}
func
(
Embedded
)
ControllerManager
(
args
[]
string
)
error
{
func
(
Embedded
)
ControllerManager
(
a
piReady
<-
chan
struct
{},
a
rgs
[]
string
)
error
{
command
:=
cmapp
.
NewControllerManagerCommand
()
command
.
SetArgs
(
args
)
go
func
()
{
<-
apiReady
logrus
.
Fatalf
(
"controller-manager exited: %v"
,
command
.
Execute
())
}()
...
...
pkg/daemons/executor/executor.go
View file @
cb4b3476
...
...
@@ -11,8 +11,8 @@ type Executor interface {
Kubelet
(
args
[]
string
)
error
KubeProxy
(
args
[]
string
)
error
APIServer
(
ctx
context
.
Context
,
args
[]
string
)
(
authenticator
.
Request
,
http
.
Handler
,
error
)
Scheduler
(
args
[]
string
)
error
ControllerManager
(
args
[]
string
)
error
Scheduler
(
a
piReady
<-
chan
struct
{},
a
rgs
[]
string
)
error
ControllerManager
(
a
piReady
<-
chan
struct
{},
a
rgs
[]
string
)
error
}
var
(
...
...
@@ -35,10 +35,10 @@ func APIServer(ctx context.Context, args []string) (authenticator.Request, http.
return
executor
.
APIServer
(
ctx
,
args
)
}
func
Scheduler
(
args
[]
string
)
error
{
return
executor
.
Scheduler
(
args
)
func
Scheduler
(
a
piReady
<-
chan
struct
{},
a
rgs
[]
string
)
error
{
return
executor
.
Scheduler
(
a
piReady
,
a
rgs
)
}
func
ControllerManager
(
args
[]
string
)
error
{
return
executor
.
ControllerManager
(
args
)
func
ControllerManager
(
a
piReady
<-
chan
struct
{},
a
rgs
[]
string
)
error
{
return
executor
.
ControllerManager
(
a
piReady
,
a
rgs
)
}
pkg/server/server.go
View file @
cb4b3476
...
...
@@ -87,6 +87,24 @@ func startWrangler(ctx context.Context, config *Config) error {
controlConfig
.
Runtime
.
Handler
=
router
(
controlConfig
,
controlConfig
.
Runtime
.
Tunnel
,
ca
)
// Start in background
go
func
()
{
select
{
case
<-
ctx
.
Done
()
:
return
case
<-
config
.
ControlConfig
.
Runtime
.
APIServerReady
:
if
err
:=
runControllers
(
ctx
,
config
);
err
!=
nil
{
logrus
.
Fatal
(
"failed to start controllers: %v"
,
err
)
}
}
}()
return
nil
}
func
runControllers
(
ctx
context
.
Context
,
config
*
Config
)
error
{
controlConfig
:=
&
config
.
ControlConfig
sc
,
err
:=
newContext
(
ctx
,
controlConfig
.
Runtime
.
KubeConfigAdmin
)
if
err
!=
nil
{
return
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