Skip to content

Commit

Permalink
wait for containerd to be ready
Browse files Browse the repository at this point in the history
  • Loading branch information
BenTheElder committed Jan 22, 2025
1 parent b594068 commit 18f8445
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions pkg/build/nodeimage/buildcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
24 changes: 23 additions & 1 deletion pkg/build/nodeimage/imageimporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package nodeimage
import (
"io"

"sigs.k8s.io/kind/pkg/errors"
"sigs.k8s.io/kind/pkg/exec"
)

Expand All @@ -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
}

Expand Down

0 comments on commit 18f8445

Please sign in to comment.