Skip to content

Commit

Permalink
bugfix: we should get image ID from containerd
Browse files Browse the repository at this point in the history
Signed-off-by: YaoZengzeng <yaozengzeng@zju.edu.cn>
  • Loading branch information
YaoZengzeng committed Apr 12, 2018
1 parent 204c39c commit a19f92f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
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
4 changes: 1 addition & 3 deletions daemon/mgr/spec_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ func setupProcessCwd(ctx context.Context, c *ContainerMeta, spec *SpecWrapper) e
func setupProcessTTY(ctx context.Context, c *ContainerMeta, spec *SpecWrapper) error {
s := spec.s
s.Process.Terminal = c.Config.Tty
if s.Process.Env != nil {
if c.Config.Tty {
s.Process.Env = append(s.Process.Env, "TERM=xterm")
} else {
s.Process.Env = []string{"TERM=xterm"}
}
return nil
}
Expand Down

0 comments on commit a19f92f

Please sign in to comment.