Move containerd wait into exported function

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
pull/5054/head
Brad Davidson 2022-01-25 10:02:54 -08:00 committed by Brad Davidson
parent 101917b0c4
commit 03bba66760
1 changed files with 13 additions and 3 deletions

View File

@ -93,9 +93,20 @@ func Run(ctx context.Context, cfg *config.Node) error {
os.Exit(1)
}()
if err := WaitForContainerd(ctx, cfg.Containerd.Address); err != nil {
return err
}
return preloadImages(ctx, cfg)
}
// WaitForContainerd blocks in a retry loop until the Containerd CRI service
// is functional at the provided socket address. It will return only on success,
// or when the context is cancelled.
func WaitForContainerd(ctx context.Context, address string) error {
first := true
for {
conn, err := CriConnection(ctx, cfg.Containerd.Address)
conn, err := CriConnection(ctx, address)
if err == nil {
conn.Close()
break
@ -112,8 +123,7 @@ func Run(ctx context.Context, cfg *config.Node) error {
}
}
logrus.Info("Containerd is now running")
return preloadImages(ctx, cfg)
return nil
}
// criConnection connects to a CRI socket at the given path.