Skip to content

Commit

Permalink
Merge pull request #5266 from Ace-Tang/ace
Browse files Browse the repository at this point in the history
ctr: add --user for task exec
  • Loading branch information
estesp committed Mar 25, 2021
2 parents 80fa9fe + 5e94745 commit f2d8403
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions cmd/ctr/commands/tasks/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/containerd/containerd"
"github.com/containerd/containerd/cio"
"github.com/containerd/containerd/cmd/ctr/commands"
"github.com/containerd/containerd/oci"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
Expand Down Expand Up @@ -61,6 +62,10 @@ var execCommand = cli.Command{
Name: "log-uri",
Usage: "log uri for custom shim logging",
},
cli.StringFlag{
Name: "user",
Usage: "user id or name",
},
},
Action: func(context *cli.Context) error {
var (
Expand All @@ -85,15 +90,25 @@ var execCommand = cli.Command{
if err != nil {
return err
}
task, err := container.Task(ctx, nil)
if err != nil {
return err
if user := context.String("user"); user != "" {
c, err := container.Info(ctx)
if err != nil {
return err
}
if err := oci.WithUser(user)(ctx, client, &c, spec); err != nil {
return err
}
}

pspec := spec.Process
pspec.Terminal = tty
pspec.Args = args

task, err := container.Task(ctx, nil)
if err != nil {
return err
}

var (
ioCreator cio.Creator
stdinC = &stdinCloser{
Expand Down

0 comments on commit f2d8403

Please sign in to comment.