Skip to content
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
36 changes: 20 additions & 16 deletions ctrd/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ func (c *Client) ListImages(ctx context.Context, filter ...string) ([]types.Imag
continue
}

desc, err := image.Config(ctx, wrapperCli.client.ContentStore(), platforms.Default())
if err != nil {
logrus.Errorf("failed to get image id %s: %v", image.Name, err)
continue
}
id := desc.Digest.String()

refNamed, err := reference.ParseNamedReference(image.Name)
// occur error, skip it
if err != nil {
Expand All @@ -118,13 +125,7 @@ func (c *Client) ListImages(ctx context.Context, filter ...string) ([]types.Imag
continue
}
imageInfo.Size = size

// generate image ID by imageInfo JSON.
imageID, err := generateID(&imageInfo)
if err != nil {
return nil, err
}
imageInfo.ID = imageID.String()
imageInfo.ID = id

if refDigest, ok := refNamed.(reference.Digested); ok {
imageInfo.RepoDigests = append(imageInfo.RepoDigests, refDigest.String())
Expand Down Expand Up @@ -206,6 +207,12 @@ func (c *Client) PullImage(ctx context.Context, ref string, authConfig *types.Au
return types.ImageInfo{}, err
}

desc, err := img.Config(ctx)
if err != nil {
return types.ImageInfo{}, err
}
id := desc.Digest.String()

logrus.Infof("success to pull image: %s", img.Name())

ociImage, err := c.GetOciImage(ctx, ref)
Expand All @@ -217,24 +224,21 @@ func (c *Client) PullImage(ctx context.Context, ref string, authConfig *types.Au
// fill struct ImageInfo
{
imageInfo.Size = size
// generate image ID by imageInfo JSON.
imageID, err := generateID(&imageInfo)
imageInfo.ID = id

refNamed, err := reference.ParseNamedReference(ref)
if err != nil {
return types.ImageInfo{}, err
}
imageInfo.ID = imageID.String()

refNamed, err := reference.ParseNamedReference(img.Name())
if err != nil {
return types.ImageInfo{}, err
if refTag, ok := refNamed.(reference.Tagged); ok {
imageInfo.RepoTags = append(imageInfo.RepoTags, refTag.String())
}

if refDigest, ok := refNamed.(reference.Digested); ok {
imageInfo.RepoDigests = append(imageInfo.RepoDigests, refDigest.String())
} else {
refTagged := reference.WithDefaultTagIfMissing(refNamed).(reference.Tagged)
imageInfo.RepoTags = append(imageInfo.RepoTags, refTagged.String())
imageInfo.RepoDigests = append(imageInfo.RepoDigests, refTagged.Name()+"@"+img.Target().Digest.String())
imageInfo.RepoDigests = append(imageInfo.RepoDigests, refNamed.Name()+"@"+img.Target().Digest.String())
}
}

Expand Down
8 changes: 8 additions & 0 deletions daemon/mgr/cri.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,8 +761,15 @@ func (c *CriManager) ListImages(ctx context.Context, r *runtime.ListImagesReques
return nil, err
}

// We may get images with same id and different repoTag or repoDigest,
// so we need idExist to de-dup.
idExist := make(map[string]bool)

images := make([]*runtime.Image, 0, len(imageList))
for _, i := range imageList {
if _, ok := idExist[i.ID]; ok {
continue
}
// NOTE: we should query image cache to get the correct image info.
imageInfo, err := c.ImageMgr.GetImage(ctx, strings.TrimPrefix(i.ID, "sha256:"))
if err != nil {
Expand All @@ -774,6 +781,7 @@ func (c *CriManager) ListImages(ctx context.Context, r *runtime.ListImagesReques
continue
}
images = append(images, image)
idExist[i.ID] = true
}

return &runtime.ListImagesResponse{Images: images}, nil
Expand Down
2 changes: 1 addition & 1 deletion hack/cri-test/test-cri.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ POUCH_SOCK="/var/run/pouchcri.sock"
CRI_FOCUS=${CRI_FOCUS:-}

# CRI_SKIP skips the test to skip.
CRI_SKIP=${CRI_SKIP:-"RunAsUserName|seccomp localhost|should error on create with wrong options|listImage should get exactly 2 repoTags"}
CRI_SKIP=${CRI_SKIP:-"RunAsUserName|seccomp localhost|should error on create with wrong options"}
# REPORT_DIR is the the directory to store test logs.
REPORT_DIR=${REPORT_DIR:-"/tmp/test-cri"}

Expand Down