ContainerStatus inspects the docker container and returns the status.
( _ context.Context, req *v1.ContainerStatusRequest, )
| 29 | |
| 30 | // ContainerStatus inspects the docker container and returns the status. |
| 31 | func (ds *dockerService) ContainerStatus( |
| 32 | _ context.Context, |
| 33 | req *v1.ContainerStatusRequest, |
| 34 | ) (*v1.ContainerStatusResponse, error) { |
| 35 | containerID := req.ContainerId |
| 36 | r, err := ds.client.InspectContainer(containerID) |
| 37 | if err != nil { |
| 38 | return nil, err |
| 39 | } |
| 40 | |
| 41 | // Parse the timestamps. |
| 42 | createdAt, startedAt, finishedAt, err := getContainerTimestamps(r) |
| 43 | if err != nil { |
| 44 | return nil, fmt.Errorf("failed to parse timestamp for container %q: %v", containerID, err) |
| 45 | } |
| 46 | |
| 47 | // Convert the image id to a pullable id. |
| 48 | ir, err := ds.client.InspectImageByID(r.Image) |
| 49 | if err != nil { |
| 50 | if !libdocker.IsImageNotFoundError(err) { |
| 51 | return nil, fmt.Errorf( |
| 52 | "unable to inspect docker image %q while inspecting docker container %q: %v", |
| 53 | r.Image, |
| 54 | containerID, |
| 55 | err, |
| 56 | ) |
| 57 | } |
| 58 | logrus.Debugf("Image %s not found while inspecting docker container %s: %v", r.Image, containerID, err) |
| 59 | } |
| 60 | imageID := toPullableImageID(r.Image, ir) |
| 61 | |
| 62 | // Convert the mounts. |
| 63 | mounts := make([]*v1.Mount, 0, len(r.Mounts)) |
| 64 | for i := range r.Mounts { |
| 65 | m := r.Mounts[i] |
| 66 | readonly := !m.RW |
| 67 | var propagation v1.MountPropagation |
| 68 | switch m.Propagation { |
| 69 | case dockermounttypes.PropagationRPrivate: |
| 70 | propagation = v1.MountPropagation_PROPAGATION_PRIVATE |
| 71 | case dockermounttypes.PropagationRShared: |
| 72 | propagation = v1.MountPropagation_PROPAGATION_BIDIRECTIONAL |
| 73 | case dockermounttypes.PropagationRSlave: |
| 74 | propagation = v1.MountPropagation_PROPAGATION_HOST_TO_CONTAINER |
| 75 | } |
| 76 | mounts = append(mounts, &v1.Mount{ |
| 77 | HostPath: m.Source, |
| 78 | ContainerPath: m.Destination, |
| 79 | Readonly: readonly, |
| 80 | // Note: Can't set SeLinuxRelabel |
| 81 | Propagation: propagation, |
| 82 | }) |
| 83 | } |
| 84 | // Interpret container states. |
| 85 | var state v1.ContainerState |
| 86 | var reason, message string |
| 87 | if r.State.Running { |
| 88 | // Container is running. |