(ctx context.Context, c containerd.Container)
| 38 | ) |
| 39 | |
| 40 | func ContainerStatus(ctx context.Context, c containerd.Container) string { |
| 41 | titleCaser := cases.Title(language.English) |
| 42 | task, err := c.Task(ctx, nil) |
| 43 | if err != nil { |
| 44 | // NOTE: NotFound doesn't mean that container hasn't started. |
| 45 | // In docker/CRI-containerd plugin, the task will be deleted |
| 46 | // when it exits. So, the status will be "created" for this |
| 47 | // case. |
| 48 | if errdefs.IsNotFound(err) { |
| 49 | return titleCaser.String(string(containerd.Created)) |
| 50 | } |
| 51 | return titleCaser.String(string(containerd.Unknown)) |
| 52 | } |
| 53 | |
| 54 | status, err := task.Status(ctx) |
| 55 | if err != nil { |
| 56 | return titleCaser.String(string(containerd.Unknown)) |
| 57 | } |
| 58 | labels, err := c.Labels(ctx) |
| 59 | if err != nil { |
| 60 | return titleCaser.String(string(containerd.Unknown)) |
| 61 | } |
| 62 | |
| 63 | switch s := status.Status; s { |
| 64 | case containerd.Stopped: |
| 65 | if labels[restart.StatusLabel] == string(containerd.Running) && restart.Reconcile(status, labels) { |
| 66 | return fmt.Sprintf("Restarting (%v) %s", status.ExitStatus, TimeSinceInHuman(status.ExitTime)) |
| 67 | } |
| 68 | return fmt.Sprintf("Exited (%v) %s", status.ExitStatus, TimeSinceInHuman(status.ExitTime)) |
| 69 | case containerd.Running: |
| 70 | return "Up" // TODO: print "status.UpTime" (inexistent yet) |
| 71 | default: |
| 72 | return titleCaser.String(string(s)) |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | func InspectContainerCommand(spec *oci.Spec, trunc, quote bool) string { |
| 77 | if spec == nil || spec.Process == nil { |
no test coverage detected
searching dependent graphs…