Return image tag as image spec.
Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
parent
8a1a2f2713
commit
050ee1de95
@ -32,10 +32,21 @@ func (c *criContainerdService) ContainerStatus(ctx context.Context, r *runtime.C
|
|||||||
return nil, fmt.Errorf("an error occurred when try to find container %q: %v", r.GetContainerId(), err)
|
return nil, fmt.Errorf("an error occurred when try to find container %q: %v", r.GetContainerId(), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(random-liu): Clean up the following logic in CRI.
|
||||||
|
// Current assumption:
|
||||||
|
// * ImageSpec in container config is image ID.
|
||||||
|
// * ImageSpec in container status is image tag.
|
||||||
|
// * ImageRef in container status is repo digest.
|
||||||
|
spec := container.Metadata.Config.GetImage()
|
||||||
imageRef := container.ImageRef
|
imageRef := container.ImageRef
|
||||||
image, err := c.imageStore.Get(imageRef)
|
image, err := c.imageStore.Get(imageRef)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get image %q: %v", container.ImageRef, err)
|
return nil, fmt.Errorf("failed to get image %q: %v", imageRef, err)
|
||||||
|
}
|
||||||
|
if len(image.RepoTags) > 0 {
|
||||||
|
// Based on current behavior of dockershim, this field should be
|
||||||
|
// image tag.
|
||||||
|
spec = &runtime.ImageSpec{Image: image.RepoTags[0]}
|
||||||
}
|
}
|
||||||
if len(image.RepoDigests) > 0 {
|
if len(image.RepoDigests) > 0 {
|
||||||
// Based on the CRI definition, this field will be consumed by user.
|
// Based on the CRI definition, this field will be consumed by user.
|
||||||
@ -43,12 +54,12 @@ func (c *criContainerdService) ContainerStatus(ctx context.Context, r *runtime.C
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &runtime.ContainerStatusResponse{
|
return &runtime.ContainerStatusResponse{
|
||||||
Status: toCRIContainerStatus(container, imageRef),
|
Status: toCRIContainerStatus(container, spec, imageRef),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// toCRIContainerStatus converts internal container object to CRI container status.
|
// toCRIContainerStatus converts internal container object to CRI container status.
|
||||||
func toCRIContainerStatus(container containerstore.Container, imageRef string) *runtime.ContainerStatus {
|
func toCRIContainerStatus(container containerstore.Container, spec *runtime.ImageSpec, imageRef string) *runtime.ContainerStatus {
|
||||||
meta := container.Metadata
|
meta := container.Metadata
|
||||||
status := container.Status.Get()
|
status := container.Status.Get()
|
||||||
reason := status.Reason
|
reason := status.Reason
|
||||||
@ -67,7 +78,7 @@ func toCRIContainerStatus(container containerstore.Container, imageRef string) *
|
|||||||
StartedAt: status.StartedAt,
|
StartedAt: status.StartedAt,
|
||||||
FinishedAt: status.FinishedAt,
|
FinishedAt: status.FinishedAt,
|
||||||
ExitCode: status.ExitCode,
|
ExitCode: status.ExitCode,
|
||||||
Image: meta.Config.GetImage(),
|
Image: spec,
|
||||||
ImageRef: imageRef,
|
ImageRef: imageRef,
|
||||||
Reason: reason,
|
Reason: reason,
|
||||||
Message: status.Message,
|
Message: status.Message,
|
||||||
|
@ -63,6 +63,7 @@ func getContainerStatusTestData() (*containerstore.Metadata, *containerstore.Sta
|
|||||||
}
|
}
|
||||||
image := &imagestore.Image{
|
image := &imagestore.Image{
|
||||||
ID: "test-image-id",
|
ID: "test-image-id",
|
||||||
|
RepoTags: []string{"test-image-repo-tag"},
|
||||||
RepoDigests: []string{"test-image-repo-digest"},
|
RepoDigests: []string{"test-image-repo-digest"},
|
||||||
}
|
}
|
||||||
expected := &runtime.ContainerStatus{
|
expected := &runtime.ContainerStatus{
|
||||||
@ -71,7 +72,7 @@ func getContainerStatusTestData() (*containerstore.Metadata, *containerstore.Sta
|
|||||||
State: runtime.ContainerState_CONTAINER_RUNNING,
|
State: runtime.ContainerState_CONTAINER_RUNNING,
|
||||||
CreatedAt: createdAt,
|
CreatedAt: createdAt,
|
||||||
StartedAt: startedAt,
|
StartedAt: startedAt,
|
||||||
Image: config.GetImage(),
|
Image: &runtime.ImageSpec{Image: "test-image-repo-tag"},
|
||||||
ImageRef: "test-image-repo-digest",
|
ImageRef: "test-image-repo-digest",
|
||||||
Reason: completeExitReason,
|
Reason: completeExitReason,
|
||||||
Labels: config.GetLabels(),
|
Labels: config.GetLabels(),
|
||||||
@ -135,7 +136,9 @@ func TestToCRIContainerStatus(t *testing.T) {
|
|||||||
expected.FinishedAt = test.finishedAt
|
expected.FinishedAt = test.finishedAt
|
||||||
expected.ExitCode = test.exitCode
|
expected.ExitCode = test.exitCode
|
||||||
expected.Message = test.message
|
expected.Message = test.message
|
||||||
assert.Equal(t, expected, toCRIContainerStatus(container, image.RepoDigests[0]), desc)
|
assert.Equal(t, expected, toCRIContainerStatus(container,
|
||||||
|
&runtime.ImageSpec{Image: image.RepoTags[0]},
|
||||||
|
image.RepoDigests[0]), desc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user