diff --git a/cmd/crioctl/container.go b/cmd/crioctl/container.go index 20ba367b..7788d547 100644 --- a/cmd/crioctl/container.go +++ b/cmd/crioctl/container.go @@ -463,6 +463,10 @@ func ContainerStatus(client pb.RuntimeServiceClient, ID string) error { if r.Status.Image != nil { fmt.Printf("Image: %v\n", r.Status.Image.Image) } + // + // TODO: https://github.com/kubernetes-incubator/cri-o/issues/531 + // + //fmt.Printf("ImageRef: %v\n", r.Status.ImageRef) return nil } diff --git a/server/container_status.go b/server/container_status.go index 5e7b2b22..d2a500d3 100644 --- a/server/container_status.go +++ b/server/container_status.go @@ -47,9 +47,21 @@ func (s *Server) ContainerStatus(ctx context.Context, req *pb.ContainerStatusReq 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 + imageRef := status.ID + // + // TODO: https://github.com/kubernetes-incubator/cri-o/issues/531 + // + //for _, n := range status.Names { + //r, err := reference.ParseNormalizedNamed(n) + //if err != nil { + //return nil, fmt.Errorf("failed to normalize image name for ImageRef: %v", err) + //} + //if digested, isDigested := r.(reference.Canonical); isDigested { + //imageRef = reference.FamiliarString(digested) + //break + //} + //} + resp.Status.ImageRef = imageRef for _, n := range status.Names { r, err := reference.ParseNormalizedNamed(n) diff --git a/server/image_status.go b/server/image_status.go index d2cf9d4f..0841c702 100644 --- a/server/image_status.go +++ b/server/image_status.go @@ -32,6 +32,7 @@ func (s *Server) ImageStatus(ctx context.Context, req *pb.ImageStatusRequest) (* Id: status.ID, RepoTags: status.Names, Size_: *status.Size, + // TODO: https://github.com/kubernetes-incubator/cri-o/issues/531 }, } logrus.Debugf("ImageStatusResponse: %+v", resp) diff --git a/test/helpers.bash b/test/helpers.bash index 873c2f67..7658357a 100644 --- a/test/helpers.bash +++ b/test/helpers.bash @@ -147,7 +147,7 @@ function start_crio() { if ! [ "$3" = "--no-pause-image" ] ; then "$BIN2IMG_BINARY" --root "$TESTDIR/crio" $STORAGE_OPTS --runroot "$TESTDIR/crio-run" --source-binary "$PAUSE_BINARY" fi - "$COPYIMG_BINARY" --root "$TESTDIR/crio" $STORAGE_OPTS --runroot "$TESTDIR/crio-run" --image-name=redis:alpine --import-from=dir:"$ARTIFACTS_PATH"/redis-image --add-name=docker://docker.io/library/redis:alpine --signature-policy="$INTEGRATION_ROOT"/policy.json + "$COPYIMG_BINARY" --root "$TESTDIR/crio" $STORAGE_OPTS --runroot "$TESTDIR/crio-run" --image-name=redis:alpine --import-from=dir:"$ARTIFACTS_PATH"/redis-image --add-name=docker.io/library/redis:alpine --signature-policy="$INTEGRATION_ROOT"/policy.json "$CRIO_BINARY" --conmon "$CONMON_BINARY" --listen "$CRIO_SOCKET" --cgroup-manager "$CGROUP_MANAGER" --runtime "$RUNTIME_BINARY" --root "$TESTDIR/crio" --runroot "$TESTDIR/crio-run" $STORAGE_OPTS --seccomp-profile "$seccomp" --apparmor-profile "$apparmor" --cni-config-dir "$CRIO_CNI_CONFIG" --signature-policy "$INTEGRATION_ROOT"/policy.json --config /dev/null config >$CRIO_CONFIG # Prepare the CNI configuration files, we're running with non host networking by default @@ -170,6 +170,24 @@ function start_crio() { if [ "$status" -ne 0 ] ; then crioctl image pull busybox:latest fi + # + # + # + # TODO: remove the code below for redis digested image id when + # https://github.com/kubernetes-incubator/cri-o/issues/531 is complete + # as the digested reference will be auto-stored when pulling the tag + # above + # + # + # + REDIS_IMAGEID_DIGESTED="redis@sha256:03789f402b2ecfb98184bf128d180f398f81c63364948ff1454583b02442f73b" + run crioctl image status --id $REDIS_IMAGEID_DIGESTED + if [ "$status" -ne 0 ]; then + crioctl image pull $REDIS_IMAGEID_DIGESTED + fi + # + # + # BUSYBOX_IMAGEID=$(crioctl image status --id=busybox | head -1 | sed -e "s/ID: //g") } diff --git a/test/image.bats b/test/image.bats index 3dc50416..cb2bc155 100644 --- a/test/image.bats +++ b/test/image.bats @@ -48,6 +48,33 @@ function teardown() { stop_crio } +@test "container status return image@digest if created by image ID and digest available" { + skip "depends on https://github.com/kubernetes-incubator/cri-o/issues/531" + + 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_DIGESTED/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" =~ "ImageRef: redis@sha256:03789f402b2ecfb98184bf128d180f398f81c63364948ff1454583b02442f73b" ]] + + cleanup_ctrs + cleanup_pods + stop_crio +} + @test "image pull" { start_crio "" "" --no-pause-image run crioctl image pull "$IMAGE"