Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to latest base image with containerd 2.0.2, ensure containerd is ready before importing images #3848

Merged
merged 4 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/apis/config/defaults/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ limitations under the License.
package defaults

// Image is the default for the Config.Image field, aka the default node image.
const Image = "kindest/node:v1.32.0@sha256:c48c62eac5da28cdadcf560d1d8616cfa6783b58f0d94cf63ad1bf49600cb027"
const Image = "kindest/node:v1.32.1@sha256:6afef2b7f69d627ea7bf27ee6696b6868d18e03bf98167c420df486da4662db6"
21 changes: 15 additions & 6 deletions pkg/build/nodeimage/buildcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,18 +267,27 @@ func (c *buildContext) prePullImagesAndWriteManifests(bits kube.Bits, parsedVers
}()

fns := []func() error{}
osArch := dockerBuildOsAndArch(c.arch)
for _, image := range requiredImages {
image := image // https://golang.org/doc/faq#closures_and_goroutines
fns = append(fns, func() error {
if !builtImages.Has(image) {
if err = importer.Pull(image, dockerBuildOsAndArch(c.arch)); err != nil {
if !builtImages.Has(image) {
fns = append(fns, func() error {
if err = importer.Pull(image, osArch); err != nil {
c.logger.Warnf("Failed to pull %s with error: %v", image, err)
runE := exec.RunErrorForError(err)
c.logger.Warn(string(runE.Output))
c.logger.Warnf("Retrying %s pull after 1s ...", image)
time.Sleep(time.Second)
return importer.Pull(image, osArch)
}
}
return nil
})
return nil
})
}
}
// Wait for containerd socket to be ready, which may take 1s when running under emulation
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could also consider starting the image importer earlier on, but I would prefer to get the functional fix merged first over further micro-optimization. it won't make any meaningful difference in the 99% case of users building for their host architecture anyhow, and even when it does it will be negligible, basically one sleep in WaitForReady vs 0.

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
2 changes: 1 addition & 1 deletion pkg/build/nodeimage/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ const DefaultImage = "kindest/node:latest"
// DefaultBaseImage is the default base image used
// TODO: come up with a reasonable solution to digest pinning
// https://github.com/moby/moby/issues/43188
const DefaultBaseImage = "docker.io/kindest/base:v20241212-9f82dd49"
const DefaultBaseImage = "docker.io/kindest/base:v20250117-f528b021"
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
Loading