Skip to content

Commit

Permalink
add label pinned at the import action
Browse files Browse the repository at this point in the history
Signed-off-by: roman-kiselenko <roman.kiselenko.dev@gmail.com>
  • Loading branch information
roman-kiselenko committed Dec 8, 2023
1 parent 847bbcf commit 76a2096
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 29 deletions.
20 changes: 0 additions & 20 deletions pkg/build/nodeimage/buildcontext.go
Expand Up @@ -303,26 +303,6 @@ func (c *buildContext) prePullImagesAndWriteManifests(bits kube.Bits, parsedVers
return nil, err
}

pinFns := []func() error{}
for _, image := range requiredImages {
image := image
pinFns = append(pinFns, func() error {
// pin core bundled images in order to prevent GC-ing
if err := importer.Pin(image, dockerBuildOsAndArch(c.arch)); err != nil {
c.logger.Warnf("Failed to pin %s with error: %v", image, err)
runE := exec.RunErrorForError(err)
c.logger.Warn(string(runE.Output))
return err
}
return nil
})
}
// pin all image concurrently and log error if any
if err := errors.UntilErrorConcurrent(pinFns); err != nil {
c.logger.Errorf("Image pin Failed! Failed to pin images %v", err)
// Ignore errors, and don't prevent image building.
}

return importer.ListImported()
}

Expand Down
10 changes: 1 addition & 9 deletions pkg/build/nodeimage/imageimporter.go
Expand Up @@ -52,18 +52,10 @@ func (c *containerdImporter) Pull(image, platform string) error {
).SetStdout(io.Discard).SetStderr(io.Discard).Run()
}

// kubelet can determine what images to skip while doing image garbage collection
// by checking the pinned attribute of the images through CRI
func (c *containerdImporter) Pin(image, platform string) error {
return c.containerCmder.Command(
"ctr", "--namespace=k8s.io", "images", "label", image, "--platform="+platform, "io.cri-containerd.pinned=pinned",
).SetStdout(io.Discard).SetStderr(io.Discard).Run()
}

func (c *containerdImporter) LoadCommand() exec.Cmd {
return c.containerCmder.Command(
// TODO: ideally we do not need this in the future. we have fixed at least one image
"ctr", "--namespace=k8s.io", "images", "import", "--all-platforms", "--no-unpack", "--digests", "-",
"ctr", "--namespace=k8s.io", "images", "import", "--label=io.cri-containerd.pinned=pinned", "--all-platforms", "--no-unpack", "--digests", "-",
)
}

Expand Down

0 comments on commit 76a2096

Please sign in to comment.