wait for containerd to be ready

This commit is contained in:
Benjamin Elder
2025-01-22 15:16:40 -08:00
parent b594068ca9
commit 18f8445ad3
2 changed files with 28 additions and 1 deletions

View File

@@ -284,6 +284,11 @@ func (c *buildContext) prePullImagesAndWriteManifests(bits kube.Bits, parsedVers
})
}
}
// Wait for containerd socket to be ready, which may take 1s when running under emulation
if err := importer.WaitForReady(); err != nil {
c.logger.Errorf("Image build failed, containerd did not become ready %v", err)
return nil, err
}
if err := errors.AggregateConcurrent(fns); err != nil {
return nil, err
}

View File

@@ -19,6 +19,7 @@ package nodeimage
import (
"io"
"sigs.k8s.io/kind/pkg/errors"
"sigs.k8s.io/kind/pkg/exec"
)
@@ -38,7 +39,28 @@ func (c *containerdImporter) Prepare() error {
).Run(); err != nil {
return err
}
// TODO(bentheelder): some healthcheck?
return nil
}
func (c *containerdImporter) WaitForReady() error {
// ctr doesn't respect timeouts when the socket doesn't exist
// so we'll look for the socket to exist ourselves, THEN attempt ctr info
// TODO: we are assuming the socket path, and this is kind of hacky
if err := c.containerCmder.Command(
"bash", "-c", `set -e
# wait for socket to exist
for i in {0..3}; do
if [ -S /run/containerd/containerd.sock ]; then
break
fi
sleep "$i"
done
# check healthy
ctr info
`,
).Run(); err != nil {
return errors.Wrap(err, "failed to wait for containerd to become ready")
}
return nil
}