server: container_status: return image name if available
If we create a container using the image ID like
771cd5947d5ea4bf8e8f4900dd357dbb67e7b16486c270f8274087d182d457c6, then
a call to container_status will return that same ID for the "Image"
field in ContainerStatusResponse.
This patch matches dockershim behavior and return the first tagged name
if available from the image store.
This is also needed to fix a failure in k8s e2d tests.
Reference:
https://github.com/kubernetes/kubernetes/pull/39298/files#diff-c7dd39479fd733354254e70845075db5R369
Reference:
67a5bf8454/test/e2e/framework/util.go (L1941)
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
parent
a0916b1044
commit
22d055869d
3 changed files with 46 additions and 3 deletions
|
@ -460,6 +460,9 @@ func ContainerStatus(client pb.RuntimeServiceClient, ID string) error {
|
|||
ftm := time.Unix(0, r.Status.FinishedAt)
|
||||
fmt.Printf("Finished: %v\n", ftm)
|
||||
fmt.Printf("Exit Code: %v\n", r.Status.ExitCode)
|
||||
if r.Status.Image != nil {
|
||||
fmt.Printf("Image: %v\n", r.Status.Image.Image)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -2,8 +2,10 @@ package server
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/distribution/reference"
|
||||
"github.com/kubernetes-incubator/cri-o/oci"
|
||||
rspec "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"golang.org/x/net/context"
|
||||
|
@ -24,14 +26,12 @@ func (s *Server) ContainerStatus(ctx context.Context, req *pb.ContainerStatusReq
|
|||
s.containerStateToDisk(c)
|
||||
|
||||
containerID := c.ID()
|
||||
image := c.Image()
|
||||
resp := &pb.ContainerStatusResponse{
|
||||
Status: &pb.ContainerStatus{
|
||||
Id: containerID,
|
||||
Metadata: c.Metadata(),
|
||||
Labels: c.Labels(),
|
||||
Annotations: c.Annotations(),
|
||||
Image: image,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -41,13 +41,28 @@ func (s *Server) ContainerStatus(ctx context.Context, req *pb.ContainerStatusReq
|
|||
}
|
||||
resp.Status.Mounts = mounts
|
||||
|
||||
status, err := s.storageImageServer.ImageStatus(s.imageContext, image.Image)
|
||||
imageName := c.Image().Image
|
||||
status, err := s.storageImageServer.ImageStatus(s.imageContext, imageName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO: use status.ID only if no digested names!!!
|
||||
// need to modify ImageStatus to split tagged and digested!
|
||||
resp.Status.ImageRef = status.ID
|
||||
|
||||
for _, n := range status.Names {
|
||||
r, err := reference.ParseNormalizedNamed(n)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to normalize image name for Image: %v", err)
|
||||
}
|
||||
if tagged, isTagged := r.(reference.Tagged); isTagged {
|
||||
imageName = reference.FamiliarString(tagged)
|
||||
break
|
||||
}
|
||||
}
|
||||
resp.Status.Image = &pb.ImageSpec{Image: imageName}
|
||||
|
||||
cState := s.runtime.ContainerStatus(c)
|
||||
rStatus := pb.ContainerState_CONTAINER_UNKNOWN
|
||||
|
||||
|
|
|
@ -23,6 +23,31 @@ function teardown() {
|
|||
stop_crio
|
||||
}
|
||||
|
||||
@test "container status return image:tag if created by image ID" {
|
||||
start_crio
|
||||
|
||||
run crioctl pod run --config "$TESTDATA"/sandbox_config.json
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
pod_id="$output"
|
||||
|
||||
sed -e "s/%VALUE%/$REDIS_IMAGEID/g" "$TESTDATA"/container_config_by_imageid.json > "$TESTDIR"/ctr_by_imageid.json
|
||||
|
||||
run crioctl ctr create --config "$TESTDIR"/ctr_by_imageid.json --pod "$pod_id"
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
ctr_id="$output"
|
||||
|
||||
run crioctl ctr status --id "$ctr_id"
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "Image: redis:alpine" ]]
|
||||
|
||||
cleanup_ctrs
|
||||
cleanup_pods
|
||||
stop_crio
|
||||
}
|
||||
|
||||
@test "image pull" {
|
||||
start_crio "" "" --no-pause-image
|
||||
run crioctl image pull "$IMAGE"
|
||||
|
|
Loading…
Reference in a new issue