Skip to content

Commit

Permalink
Merge pull request #1718 from jessvalarezo/ctr-task-ps
Browse files Browse the repository at this point in the history
ctr: update task ps command
  • Loading branch information
mlaventure committed Nov 10, 2017
2 parents b4a65de + 0961807 commit 17093c2
Show file tree
Hide file tree
Showing 18 changed files with 351 additions and 134 deletions.
4 changes: 2 additions & 2 deletions Protobuild.toml
Expand Up @@ -41,8 +41,8 @@ ignore_files = [

# Lock down runc config
[[descriptors]]
prefix = "github.com/containerd/containerd/linux/runcopts"
target = "linux/runcopts/next.pb.txt"
prefix = "github.com/containerd/containerd/linux/runctypes"
target = "linux/runctypes/next.pb.txt"
ignore_files = [
"google/protobuf/descriptor.proto",
"gogoproto/gogo.proto"
Expand Down
19 changes: 8 additions & 11 deletions cmd/ctr/commands/tasks/ps.go
Expand Up @@ -6,7 +6,7 @@ import (
"text/tabwriter"

"github.com/containerd/containerd/cmd/ctr/commands"
"github.com/containerd/containerd/windows/hcsshimtypes"
"github.com/containerd/typeurl"
"github.com/pkg/errors"
"github.com/urfave/cli"
)
Expand All @@ -29,7 +29,6 @@ var psCommand = cli.Command{
if err != nil {
return err
}

task, err := container.Task(ctx, nil)
if err != nil {
return err
Expand All @@ -38,21 +37,19 @@ var psCommand = cli.Command{
if err != nil {
return err
}
w := tabwriter.NewWriter(os.Stdout, 10, 1, 3, ' ', 0)
w := tabwriter.NewWriter(os.Stdout, 1, 8, 4, ' ', 0)
fmt.Fprintln(w, "PID\tINFO")
for _, ps := range processes {
var info interface{} = "-"
if ps.Info != nil {
var details hcsshimtypes.ProcessDetails
if err := details.Unmarshal(ps.Info.Value); err == nil {
if _, err := fmt.Fprintf(w, "%d\t%+v\n", ps.Pid, details); err != nil {
return err
}
}
} else {
if _, err := fmt.Fprintf(w, "%d\t-\n", ps.Pid); err != nil {
info, err = typeurl.UnmarshalAny(ps.Info)
if err != nil {
return err
}
}
if _, err := fmt.Fprintf(w, "%d\t%+v\n", ps.Pid, info); err != nil {
return err
}
}
return w.Flush()
},
Expand Down
8 changes: 4 additions & 4 deletions container_linux_test.go
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/containerd/cgroups"
"github.com/containerd/containerd/containers"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/linux/runcopts"
"github.com/containerd/containerd/linux/runctypes"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
"golang.org/x/sys/unix"
Expand Down Expand Up @@ -146,7 +146,7 @@ func TestShimInCgroup(t *testing.T) {
defer cg.Delete()

task, err := container.NewTask(ctx, empty(), func(_ context.Context, client *Client, r *TaskInfo) error {
r.Options = &runcopts.CreateOptions{
r.Options = &runctypes.CreateOptions{
ShimCgroup: path,
}
return nil
Expand Down Expand Up @@ -887,7 +887,7 @@ func TestContainerRuntimeOptions(t *testing.T) {
ctx, id,
WithNewSpec(withImageConfig(image), withExitStatus(7)),
withNewSnapshot(id, image),
WithRuntime("io.containerd.runtime.v1.linux", &runcopts.RuncOptions{Runtime: "no-runc"}),
WithRuntime("io.containerd.runtime.v1.linux", &runctypes.RuncOptions{Runtime: "no-runc"}),
)
if err != nil {
t.Error(err)
Expand Down Expand Up @@ -1040,7 +1040,7 @@ func testUserNamespaces(t *testing.T, readonlyRootFS bool) {
defer container.Delete(ctx, WithSnapshotCleanup)

task, err := container.NewTask(ctx, Stdio, func(_ context.Context, client *Client, r *TaskInfo) error {
r.Options = &runcopts.CreateOptions{
r.Options = &runctypes.CreateOptions{
IoUid: 1000,
IoGid: 1000,
}
Expand Down
14 changes: 7 additions & 7 deletions linux/bundle.go
Expand Up @@ -10,7 +10,7 @@ import (
"path/filepath"

"github.com/containerd/containerd/events/exchange"
"github.com/containerd/containerd/linux/runcopts"
"github.com/containerd/containerd/linux/runctypes"
"github.com/containerd/containerd/linux/shim"
"github.com/containerd/containerd/linux/shim/client"
"github.com/pkg/errors"
Expand Down Expand Up @@ -72,32 +72,32 @@ type bundle struct {
}

// ShimOpt specifies shim options for initialization and connection
type ShimOpt func(*bundle, string, *runcopts.RuncOptions) (shim.Config, client.Opt)
type ShimOpt func(*bundle, string, *runctypes.RuncOptions) (shim.Config, client.Opt)

// ShimRemote is a ShimOpt for connecting and starting a remote shim
func ShimRemote(shimBinary, daemonAddress, cgroup string, nonewns, debug bool, exitHandler func()) ShimOpt {
return func(b *bundle, ns string, ropts *runcopts.RuncOptions) (shim.Config, client.Opt) {
return func(b *bundle, ns string, ropts *runctypes.RuncOptions) (shim.Config, client.Opt) {
return b.shimConfig(ns, ropts),
client.WithStart(shimBinary, b.shimAddress(ns), daemonAddress, cgroup, nonewns, debug, exitHandler)
}
}

// ShimLocal is a ShimOpt for using an in process shim implementation
func ShimLocal(exchange *exchange.Exchange) ShimOpt {
return func(b *bundle, ns string, ropts *runcopts.RuncOptions) (shim.Config, client.Opt) {
return func(b *bundle, ns string, ropts *runctypes.RuncOptions) (shim.Config, client.Opt) {
return b.shimConfig(ns, ropts), client.WithLocal(exchange)
}
}

// ShimConnect is a ShimOpt for connecting to an existing remote shim
func ShimConnect() ShimOpt {
return func(b *bundle, ns string, ropts *runcopts.RuncOptions) (shim.Config, client.Opt) {
return func(b *bundle, ns string, ropts *runctypes.RuncOptions) (shim.Config, client.Opt) {
return b.shimConfig(ns, ropts), client.WithConnect(b.shimAddress(ns))
}
}

// NewShimClient connects to the shim managing the bundle and tasks creating it if needed
func (b *bundle) NewShimClient(ctx context.Context, namespace string, getClientOpts ShimOpt, runcOpts *runcopts.RuncOptions) (*client.Client, error) {
func (b *bundle) NewShimClient(ctx context.Context, namespace string, getClientOpts ShimOpt, runcOpts *runctypes.RuncOptions) (*client.Client, error) {
cfg, opt := getClientOpts(b, namespace, runcOpts)
return client.New(ctx, cfg, opt)
}
Expand All @@ -120,7 +120,7 @@ func (b *bundle) shimAddress(namespace string) string {
return filepath.Join(string(filepath.Separator), "containerd-shim", namespace, b.id, "shim.sock")
}

func (b *bundle) shimConfig(namespace string, runcOptions *runcopts.RuncOptions) shim.Config {
func (b *bundle) shimConfig(namespace string, runcOptions *runctypes.RuncOptions) shim.Config {
var (
criuPath string
runtimeRoot string
Expand Down
14 changes: 12 additions & 2 deletions linux/runcopts/next.pb.txt → linux/runctypes/next.pb.txt
@@ -1,5 +1,5 @@
file {
name: "github.com/containerd/containerd/linux/runcopts/runc.proto"
name: "github.com/containerd/containerd/linux/runctypes/runc.proto"
package: "containerd.linux.runc"
dependency: "gogoproto/gogo.proto"
message_type {
Expand Down Expand Up @@ -165,8 +165,18 @@ file {
json_name: "cgroupsMode"
}
}
message_type {
name: "ProcessDetails"
field {
name: "exec_id"
number: 1
label: LABEL_OPTIONAL
type: TYPE_STRING
json_name: "execId"
}
}
options {
go_package: "github.com/containerd/containerd/linux/runcopts;runcopts"
go_package: "github.com/containerd/containerd/linux/runctypes;runctypes"
}
syntax: "proto3"
}

0 comments on commit 17093c2

Please sign in to comment.