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

Function statusForFilter

cmd/nerdctl/compose/compose_ps.go:366–397  ·  view source on GitHub ↗

statusForFilter returns the status value to be matched with the 'status' filter

(ctx context.Context, c containerd.Container)

Source from the content-addressed store, hash-verified

364
365// statusForFilter returns the status value to be matched with the 'status' filter
366func statusForFilter(ctx context.Context, c containerd.Container) string {
367 task, err := c.Task(ctx, nil)
368 if err != nil {
369 // NOTE: NotFound doesn't mean that container hasn't started.
370 // In docker/CRI-containerd plugin, the task will be deleted
371 // when it exits. So, the status will be "created" for this
372 // case.
373 if errdefs.IsNotFound(err) {
374 return string(containerd.Created)
375 }
376 return string(containerd.Unknown)
377 }
378
379 status, err := task.Status(ctx)
380 if err != nil {
381 return string(containerd.Unknown)
382 }
383 labels, err := c.Labels(ctx)
384 if err != nil {
385 return string(containerd.Unknown)
386 }
387
388 switch s := status.Status; s {
389 case containerd.Stopped:
390 if labels[restart.StatusLabel] == string(containerd.Running) && restart.Reconcile(status, labels) {
391 return "restarting"
392 }
393 return "exited"
394 default:
395 return string(s)
396 }
397}

Callers 1

psActionFunction · 0.85

Calls 1

LabelsMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…