statusForFilter returns the status value to be matched with the 'status' filter
(ctx context.Context, c containerd.Container)
| 364 | |
| 365 | // statusForFilter returns the status value to be matched with the 'status' filter |
| 366 | func 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 | } |