Skip to content
This repository was archived by the owner on Sep 24, 2021. It is now read-only.

Commit 9568db0

Browse files
author
Harry Zhang
committed
Fix full docker image
1 parent 74116d3 commit 9568db0

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

pkg/hyper/client.go

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,10 @@ func (c *Client) StopContainer(containerID string, timeout int64) error {
259259
ctx, cancel := getContextWithTimeout(ctxTimeout)
260260
defer cancel()
261261

262-
_, err = c.client.ContainerStop(ctx, &types.ContainerStopRequest{ContainerID: containerID, Timeout: timeout})
262+
_, err = c.client.ContainerStop(ctx, &types.ContainerStopRequest{
263+
ContainerID: containerID,
264+
Timeout: timeout,
265+
})
263266

264267
return err
265268
}
@@ -282,23 +285,38 @@ func (c *Client) GetImageInfo(image, tag string) (*types.ImageInfo, error) {
282285
return nil, err
283286
}
284287

285-
// change `docker.io/library/imageName` to `imageName`
286-
if split := strings.Split(image, "/"); len(split) == 3 &&
287-
split[0] == defaultDomain &&
288-
split[1] == officialRepoName {
289-
image = split[2]
288+
// kuberuntime relies on docker/distribution to parse image name to
289+
// full image path and pass it to runtime.GetImageInfo():
290+
// e.g.
291+
// nginx -> docker.io/library/nginx
292+
// alexellis/echo -> docker.io/alexellis/echo
293+
//
294+
// But hyper only returns alexellis/echo in imageList, so we
295+
// need to fix the inconsistency here before doing filter.
296+
split := strings.Split(image, "/")
297+
// 1. docker.io
298+
if len(split) == 3 && split[0] == defaultDomain {
299+
// 2. docker.io/library
300+
if split[1] == officialRepoName {
301+
image = split[2]
302+
} else {
303+
// 3. docker.io/xxx
304+
image = split[1] + "/" + split[2]
305+
}
306+
290307
}
291308

309+
// filter images
292310
fullImageName := fmt.Sprintf("%s%s%s", image, repoSep, tag)
293-
for _, image := range imageList.ImageList {
294-
for _, i := range image.RepoDigests {
311+
for _, hyperImage := range imageList.ImageList {
312+
for _, i := range hyperImage.RepoDigests {
295313
if i == fullImageName {
296-
return image, nil
314+
return hyperImage, nil
297315
}
298316
}
299-
for _, i := range image.RepoTags {
317+
for _, i := range hyperImage.RepoTags {
300318
if i == fullImageName {
301-
return image, nil
319+
return hyperImage, nil
302320
}
303321
}
304322
}

0 commit comments

Comments
 (0)