MCPcopy Create free account
hub / github.com/containerd/nerdctl / ContainerStatus

Function ContainerStatus

pkg/formatter/formatter.go:40–74  ·  view source on GitHub ↗
(ctx context.Context, c containerd.Container)

Source from the content-addressed store, hash-verified

38)
39
40func 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
76func InspectContainerCommand(spec *oci.Spec, trunc, quote bool) string {
77 if spec == nil || spec.Process == nil {

Callers 6

removeContainersMethod · 0.92
StartFunction · 0.92
StatsFunction · 0.92
filterContainersFunction · 0.92
updateContainerFunction · 0.92

Calls 3

TimeSinceInHumanFunction · 0.85
LabelsMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…