Skip to content

Commit 2963b82

Browse files
committed
Improve embedded executor agent startup time
Start CRIs and Kubelet in goroutine, and wait for CRI startup before running kubelet Signed-off-by: Brad Davidson <[email protected]>
1 parent f8bc197 commit 2963b82

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

pkg/agent/containerd/watcher.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,7 @@ func importAndWatchImages(ctx context.Context, cfg *config.Node) error {
259259

260260
// wait for the workqueue to empty before returning
261261
for w.workqueue.Len() > 0 {
262-
logrus.Debugf("Waiting for initial import of images from %s", cfg.Images)
263-
time.Sleep(time.Second * 2)
262+
time.Sleep(500 * time.Millisecond)
264263
}
265264

266265
// prune unseen entries from last run once all existing files have been processed

pkg/daemons/executor/embed.go

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ func (e *Embedded) Kubelet(ctx context.Context, args []string) error {
8080
command.SetArgs(args)
8181

8282
go func() {
83+
<-e.CRIReadyChan()
8384
<-e.APIServerReadyChan()
8485
defer func() {
8586
if err := recover(); err != nil {
@@ -227,7 +228,6 @@ func (*Embedded) CloudControllerManager(ctx context.Context, ccmRBACReady <-chan
227228
}
228229
signals.RequestShutdown(nil)
229230
}()
230-
231231
return nil
232232
}
233233

@@ -236,19 +236,40 @@ func (e *Embedded) CurrentETCDOptions() (InitialOptions, error) {
236236
}
237237

238238
func (e *Embedded) Containerd(ctx context.Context, cfg *daemonconfig.Node) error {
239-
return closeIfNilErr(containerd.Run(ctx, cfg), e.criReady)
239+
go func() {
240+
if err := containerd.Run(ctx, cfg); err != nil {
241+
signals.RequestShutdown(pkgerrors.WithMessage(err, "failed to start containerd"))
242+
} else {
243+
close(e.criReady)
244+
}
245+
}()
246+
return nil
240247
}
241248

242249
func (e *Embedded) Docker(ctx context.Context, cfg *daemonconfig.Node) error {
243-
return closeIfNilErr(cridockerd.Run(ctx, cfg), e.criReady)
250+
go func() {
251+
if err := cridockerd.Run(ctx, cfg); err != nil {
252+
signals.RequestShutdown(pkgerrors.WithMessage(err, "failed to start containerd"))
253+
} else {
254+
close(e.criReady)
255+
}
256+
}()
257+
return nil
244258
}
245259

246260
func (e *Embedded) CRI(ctx context.Context, cfg *daemonconfig.Node) error {
247261
// agentless sets cri socket path to /dev/null to indicate no CRI is needed
248262
if cfg.ContainerRuntimeEndpoint != "/dev/null" {
249-
return closeIfNilErr(cri.WaitForService(ctx, cfg.ContainerRuntimeEndpoint, "CRI"), e.criReady)
263+
go func() {
264+
if err := cri.WaitForService(ctx, cfg.ContainerRuntimeEndpoint, "CRI"); err != nil {
265+
signals.RequestShutdown(pkgerrors.WithMessage(err, "failed to wait for CRI startup"))
266+
} else {
267+
close(e.criReady)
268+
}
269+
}()
250270
}
251-
return closeIfNilErr(nil, e.criReady)
271+
close(e.criReady)
272+
return nil
252273
}
253274

254275
func (e *Embedded) APIServerReadyChan() <-chan struct{} {
@@ -271,10 +292,3 @@ func (e *Embedded) CRIReadyChan() <-chan struct{} {
271292
}
272293
return e.criReady
273294
}
274-
275-
func closeIfNilErr(err error, ch chan struct{}) error {
276-
if err == nil {
277-
close(ch)
278-
}
279-
return err
280-
}

0 commit comments

Comments
 (0)