X Tutup
Skip to content

Commit 807f4d2

Browse files
committed
expose exec-id on ctr task ps
Signed-off-by: Jess Valarezo <valarezo.jessica@gmail.com>
1 parent b4a65de commit 807f4d2

File tree

12 files changed

+319
-102
lines changed

12 files changed

+319
-102
lines changed

cmd/ctr/commands/tasks/ps.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"text/tabwriter"
77

88
"github.com/containerd/containerd/cmd/ctr/commands"
9-
"github.com/containerd/containerd/windows/hcsshimtypes"
9+
"github.com/containerd/typeurl"
1010
"github.com/pkg/errors"
1111
"github.com/urfave/cli"
1212
)
@@ -29,7 +29,6 @@ var psCommand = cli.Command{
2929
if err != nil {
3030
return err
3131
}
32-
3332
task, err := container.Task(ctx, nil)
3433
if err != nil {
3534
return err
@@ -38,21 +37,19 @@ var psCommand = cli.Command{
3837
if err != nil {
3938
return err
4039
}
41-
w := tabwriter.NewWriter(os.Stdout, 10, 1, 3, ' ', 0)
40+
w := tabwriter.NewWriter(os.Stdout, 1, 8, 4, ' ', 0)
4241
fmt.Fprintln(w, "PID\tINFO")
4342
for _, ps := range processes {
43+
var info interface{} = "-"
4444
if ps.Info != nil {
45-
var details hcsshimtypes.ProcessDetails
46-
if err := details.Unmarshal(ps.Info.Value); err == nil {
47-
if _, err := fmt.Fprintf(w, "%d\t%+v\n", ps.Pid, details); err != nil {
48-
return err
49-
}
50-
}
51-
} else {
52-
if _, err := fmt.Fprintf(w, "%d\t-\n", ps.Pid); err != nil {
45+
info, err = typeurl.UnmarshalAny(ps.Info)
46+
if err != nil {
5347
return err
5448
}
5549
}
50+
if _, err := fmt.Fprintf(w, "%d\t%+v\n", ps.Pid, info); err != nil {
51+
return err
52+
}
5653
}
5754
return w.Flush()
5855
},

linux/runcopts/next.pb.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,16 @@ file {
165165
json_name: "cgroupsMode"
166166
}
167167
}
168+
message_type {
169+
name: "ProcessDetails"
170+
field {
171+
name: "exec_id"
172+
number: 1
173+
label: LABEL_OPTIONAL
174+
type: TYPE_STRING
175+
json_name: "execId"
176+
}
177+
}
168178
options {
169179
go_package: "github.com/containerd/containerd/linux/runcopts;runcopts"
170180
}

linux/runcopts/runc.pb.go

Lines changed: 168 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

linux/runcopts/runc.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@ message CheckpointOptions {
3636
repeated string empty_namespaces = 6;
3737
string cgroups_mode = 7;
3838
}
39+
40+
message ProcessDetails {
41+
string exec_id = 1;
42+
}

linux/shim/service.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ import (
1515
"github.com/containerd/containerd/api/types/task"
1616
"github.com/containerd/containerd/errdefs"
1717
"github.com/containerd/containerd/events"
18+
"github.com/containerd/containerd/linux/runcopts"
1819
shimapi "github.com/containerd/containerd/linux/shim/v1"
1920
"github.com/containerd/containerd/log"
2021
"github.com/containerd/containerd/namespaces"
2122
"github.com/containerd/containerd/reaper"
2223
"github.com/containerd/containerd/runtime"
2324
runc "github.com/containerd/go-runc"
25+
"github.com/containerd/typeurl"
2426
google_protobuf "github.com/golang/protobuf/ptypes/empty"
2527
"github.com/pkg/errors"
2628
"github.com/sirupsen/logrus"
@@ -357,9 +359,23 @@ func (s *Service) ListPids(ctx context.Context, r *shimapi.ListPidsRequest) (*sh
357359
}
358360
var processes []*task.ProcessInfo
359361
for _, pid := range pids {
360-
processes = append(processes, &task.ProcessInfo{
362+
pInfo := task.ProcessInfo{
361363
Pid: pid,
362-
})
364+
}
365+
for _, p := range s.processes {
366+
if p.Pid() == int(pid) {
367+
d := &runcopts.ProcessDetails{
368+
ExecID: p.ID(),
369+
}
370+
a, err := typeurl.MarshalAny(d)
371+
if err != nil {
372+
return nil, errors.Wrapf(err, "failed to marshal process %d info", pid)
373+
}
374+
pInfo.Info = a
375+
break
376+
}
377+
}
378+
processes = append(processes, &pInfo)
363379
}
364380
return &shimapi.ListPidsResponse{
365381
Processes: processes,

linux/task.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ func (t *Task) Pids(ctx context.Context) ([]runtime.ProcessInfo, error) {
182182
var processList []runtime.ProcessInfo
183183
for _, p := range resp.Processes {
184184
processList = append(processList, runtime.ProcessInfo{
185-
Pid: p.Pid,
185+
Pid: p.Pid,
186+
Info: p.Info,
186187
})
187188
}
188189
return processList, nil

services/tasks/service.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,17 +348,17 @@ func (s *service) ListPids(ctx context.Context, r *api.ListPidsRequest) (*api.Li
348348
}
349349
var processes []*task.ProcessInfo
350350
for _, p := range processList {
351-
processInfo := task.ProcessInfo{
351+
pInfo := task.ProcessInfo{
352352
Pid: p.Pid,
353353
}
354354
if p.Info != nil {
355355
a, err := typeurl.MarshalAny(p.Info)
356356
if err != nil {
357357
return nil, errors.Wrapf(err, "failed to marshal process %d info", p.Pid)
358358
}
359-
processInfo.Info = a
359+
pInfo.Info = a
360360
}
361-
processes = append(processes, &processInfo)
361+
processes = append(processes, &pInfo)
362362
}
363363
return &api.ListPidsResponse{
364364
Processes: processes,

0 commit comments

Comments
 (0)
X Tutup