(ctx context.Context, container containerd.Container)
| 28 | ) |
| 29 | |
| 30 | func Inspect(ctx context.Context, container containerd.Container) (*native.Container, error) { |
| 31 | info, err := container.Info(ctx) |
| 32 | if err != nil { |
| 33 | return nil, err |
| 34 | } |
| 35 | n := &native.Container{ |
| 36 | Container: info, |
| 37 | } |
| 38 | id := container.ID() |
| 39 | |
| 40 | n.Spec, err = typeurl.UnmarshalAny(info.Spec) |
| 41 | if err != nil { |
| 42 | log.G(ctx).WithError(err).WithField("id", id).Warnf("failed to inspect Spec") |
| 43 | return n, nil |
| 44 | } |
| 45 | task, err := container.Task(ctx, nil) |
| 46 | if err != nil { |
| 47 | if !errdefs.IsNotFound(err) { |
| 48 | log.G(ctx).WithError(err).WithField("id", id).Warnf("failed to inspect Task") |
| 49 | } |
| 50 | return n, nil |
| 51 | } |
| 52 | n.Process = &native.Process{ |
| 53 | Pid: int(task.Pid()), |
| 54 | } |
| 55 | st, err := task.Status(ctx) |
| 56 | if err != nil { |
| 57 | log.G(ctx).WithError(err).WithField("id", id).Warnf("failed to inspect Status") |
| 58 | return n, nil |
| 59 | } |
| 60 | if st.Status == containerd.Stopped { |
| 61 | n.Process.Pid = 0 |
| 62 | } |
| 63 | n.Process.Status = st |
| 64 | if st.Status == containerd.Running || st.Status == containerd.Paused { |
| 65 | netNS, err := InspectNetNS(ctx, n.Process.Pid) |
| 66 | if err != nil { |
| 67 | log.G(ctx).WithError(err).WithField("id", id).Warnf("failed to inspect NetNS") |
| 68 | return n, nil |
| 69 | } |
| 70 | n.Process.NetNS = netNS |
| 71 | } |
| 72 | return n, nil |
| 73 | } |
no test coverage detected
searching dependent graphs…