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

Return the sandbox image status as "Pinned" #194

Merged
merged 3 commits into from
Jan 22, 2024
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 cmd/cri/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (f *DockerCRIFlags) AddFlags(mainfs *pflag.FlagSet) {

const (
defaultPodSandboxImageName = "registry.k8s.io/pause"
defaultPodSandboxImageVersion = "3.6"
defaultPodSandboxImageVersion = "3.9"
)

var (
Expand Down
6 changes: 4 additions & 2 deletions core/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
// This file contains helper functions to convert docker API types to runtime
// API types, or vice versa.

func imageToRuntimeAPIImage(image *dockertypes.ImageSummary) (*runtimeapi.Image, error) {
func imageToRuntimeAPIImage(image *dockertypes.ImageSummary, pinned bool) (*runtimeapi.Image, error) {
if image == nil {
return nil, fmt.Errorf("unable to convert a nil pointer to a runtime API image")
}
Expand All @@ -47,10 +47,11 @@ func imageToRuntimeAPIImage(image *dockertypes.ImageSummary) (*runtimeapi.Image,
RepoTags: image.RepoTags,
RepoDigests: image.RepoDigests,
Size_: uint64(image.Size),
Pinned: pinned,
}, nil
}

func imageInspectToRuntimeAPIImage(image *dockertypes.ImageInspect) (*runtimeapi.Image, error) {
func imageInspectToRuntimeAPIImage(image *dockertypes.ImageInspect, pinned bool) (*runtimeapi.Image, error) {
if image == nil || image.Config == nil {
return nil, fmt.Errorf("unable to convert a nil pointer to a runtime API image")
}
Expand All @@ -60,6 +61,7 @@ func imageInspectToRuntimeAPIImage(image *dockertypes.ImageInspect) (*runtimeapi
RepoTags: image.RepoTags,
RepoDigests: image.RepoDigests,
Size_: uint64(image.Size),
Pinned: pinned,
}

uid, username := getUserFromImageUser(image.Config.User)
Expand Down
27 changes: 25 additions & 2 deletions core/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,26 @@ import (

// This file implements methods in ImageManagerService.

func (ds *dockerService) sandboxImage() string {
image := defaultSandboxImage
podSandboxImage := ds.podSandboxImage
if len(podSandboxImage) != 0 {
image = podSandboxImage
}
return image
}

func isPinned(image string, tags []string) bool {
pinned := false
for _, tag := range tags {
if tag == image {
pinned = true
break
}
}
return pinned
}

// ListImages lists existing images.
func (ds *dockerService) ListImages(
_ context.Context,
Expand All @@ -53,10 +73,12 @@ func (ds *dockerService) ListImages(
if err != nil {
return nil, err
}
image := ds.sandboxImage()

result := make([]*runtimeapi.Image, 0, len(images))
for _, i := range images {
apiImage, err := imageToRuntimeAPIImage(&i)
pinned := isPinned(image, i.RepoTags)
apiImage, err := imageToRuntimeAPIImage(&i, pinned)
if err != nil {
logrus.Infof("Failed to convert docker API image %v to runtime API image: %v", i, err)
continue
Expand Down Expand Up @@ -87,7 +109,8 @@ func (ds *dockerService) ImageStatus(
}
}

imageStatus, err := imageInspectToRuntimeAPIImage(imageInspect)
pinned := isPinned(ds.sandboxImage(), imageInspect.RepoTags)
imageStatus, err := imageInspectToRuntimeAPIImage(imageInspect, pinned)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion core/sandbox_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
)

const (
defaultSandboxImage = "registry.k8s.io/pause:3.6"
defaultSandboxImage = "registry.k8s.io/pause:3.9"

// Various default sandbox resources requests/limits.
defaultSandboxCPUshares int64 = 2
Expand Down
Loading