cmd: don't alias context package, and use cliContext for cli.Context
Unfortunately, this is a rather large diff, but perhaps worth a one-time "rip off the bandaid" for v2. This patch removes the use of "gocontext" as alias for stdLib's "context", and uses "cliContext" for uses of cli.context. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -28,13 +28,13 @@ var attachCommand = &cli.Command{
|
||||
Name: "attach",
|
||||
Usage: "Attach to the IO of a running container",
|
||||
ArgsUsage: "CONTAINER",
|
||||
Action: func(context *cli.Context) error {
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cancel()
|
||||
container, err := client.LoadContainer(ctx, context.Args().First())
|
||||
container, err := client.LoadContainer(ctx, cliContext.Args().First())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -44,12 +44,12 @@ var checkpointCommand = &cli.Command{
|
||||
Usage: "Path to criu work files and logs",
|
||||
},
|
||||
},
|
||||
Action: func(context *cli.Context) error {
|
||||
id := context.Args().First()
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
id := cliContext.Args().First()
|
||||
if id == "" {
|
||||
return errors.New("container id must be provided")
|
||||
}
|
||||
client, ctx, cancel, err := commands.NewClient(context, containerd.WithDefaultRuntime(context.String("runtime")))
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext, containerd.WithDefaultRuntime(cliContext.String("runtime")))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -66,12 +66,12 @@ var checkpointCommand = &cli.Command{
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := []containerd.CheckpointTaskOpts{withCheckpointOpts(info.Runtime.Name, context)}
|
||||
opts := []containerd.CheckpointTaskOpts{withCheckpointOpts(info.Runtime.Name, cliContext)}
|
||||
checkpoint, err := task.Checkpoint(ctx, opts...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if context.String("image-path") == "" {
|
||||
if cliContext.String("image-path") == "" {
|
||||
fmt.Println(checkpoint.Name())
|
||||
}
|
||||
return nil
|
||||
@@ -79,17 +79,17 @@ var checkpointCommand = &cli.Command{
|
||||
}
|
||||
|
||||
// withCheckpointOpts only suitable for runc runtime now
|
||||
func withCheckpointOpts(rt string, context *cli.Context) containerd.CheckpointTaskOpts {
|
||||
func withCheckpointOpts(rt string, cliContext *cli.Context) containerd.CheckpointTaskOpts {
|
||||
return func(r *containerd.CheckpointTaskInfo) error {
|
||||
imagePath := context.String("image-path")
|
||||
workPath := context.String("work-path")
|
||||
imagePath := cliContext.String("image-path")
|
||||
workPath := cliContext.String("work-path")
|
||||
|
||||
if r.Options == nil {
|
||||
r.Options = &options.CheckpointOptions{}
|
||||
}
|
||||
opts, _ := r.Options.(*options.CheckpointOptions)
|
||||
|
||||
if context.Bool("exit") {
|
||||
if cliContext.Bool("exit") {
|
||||
opts.Exit = true
|
||||
}
|
||||
if imagePath != "" {
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package tasks
|
||||
|
||||
import (
|
||||
gocontext "context"
|
||||
"context"
|
||||
|
||||
containerd "github.com/containerd/containerd/v2/client"
|
||||
"github.com/containerd/containerd/v2/cmd/ctr/commands"
|
||||
@@ -42,12 +42,12 @@ var deleteCommand = &cli.Command{
|
||||
Usage: "Process ID to kill",
|
||||
},
|
||||
},
|
||||
Action: func(context *cli.Context) error {
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
var (
|
||||
execID = context.String("exec-id")
|
||||
force = context.Bool("force")
|
||||
execID = cliContext.String("exec-id")
|
||||
force = cliContext.Bool("force")
|
||||
)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -58,7 +58,7 @@ var deleteCommand = &cli.Command{
|
||||
}
|
||||
var exitErr error
|
||||
if execID != "" {
|
||||
task, err := loadTask(ctx, client, context.Args().First())
|
||||
task, err := loadTask(ctx, client, cliContext.Args().First())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -74,7 +74,7 @@ var deleteCommand = &cli.Command{
|
||||
return cli.Exit("", int(ec))
|
||||
}
|
||||
} else {
|
||||
for _, target := range context.Args().Slice() {
|
||||
for _, target := range cliContext.Args().Slice() {
|
||||
task, err := loadTask(ctx, client, target)
|
||||
if err != nil {
|
||||
if exitErr == nil {
|
||||
@@ -100,7 +100,7 @@ var deleteCommand = &cli.Command{
|
||||
},
|
||||
}
|
||||
|
||||
func loadTask(ctx gocontext.Context, client *containerd.Client, containerID string) (containerd.Task, error) {
|
||||
func loadTask(ctx context.Context, client *containerd.Client, containerID string) (containerd.Task, error) {
|
||||
container, err := client.LoadContainer(ctx, containerID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -68,17 +68,17 @@ var execCommand = &cli.Command{
|
||||
Usage: "User id or name",
|
||||
},
|
||||
},
|
||||
Action: func(context *cli.Context) error {
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
var (
|
||||
id = context.Args().First()
|
||||
args = context.Args().Tail()
|
||||
tty = context.Bool("tty")
|
||||
detach = context.Bool("detach")
|
||||
id = cliContext.Args().First()
|
||||
args = cliContext.Args().Tail()
|
||||
tty = cliContext.Bool("tty")
|
||||
detach = cliContext.Bool("detach")
|
||||
)
|
||||
if id == "" {
|
||||
return errors.New("container id must be provided")
|
||||
}
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -91,7 +91,7 @@ var execCommand = &cli.Command{
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if user := context.String("user"); user != "" {
|
||||
if user := cliContext.String("user"); user != "" {
|
||||
c, err := container.Info(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -105,7 +105,7 @@ var execCommand = &cli.Command{
|
||||
pspec.Terminal = tty
|
||||
pspec.Args = args
|
||||
|
||||
if cwd := context.String("cwd"); cwd != "" {
|
||||
if cwd := cliContext.String("cwd"); cwd != "" {
|
||||
pspec.Cwd = cwd
|
||||
}
|
||||
|
||||
@@ -122,8 +122,8 @@ var execCommand = &cli.Command{
|
||||
con console.Console
|
||||
)
|
||||
|
||||
fifoDir := context.String("fifo-dir")
|
||||
logURI := context.String("log-uri")
|
||||
fifoDir := cliContext.String("fifo-dir")
|
||||
logURI := cliContext.String("log-uri")
|
||||
ioOpts := []cio.Opt{cio.WithFIFODir(fifoDir)}
|
||||
switch {
|
||||
case tty && logURI != "":
|
||||
@@ -150,7 +150,7 @@ var execCommand = &cli.Command{
|
||||
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStreams(stdinC, os.Stdout, os.Stderr)}, ioOpts...)...)
|
||||
}
|
||||
|
||||
process, err := task.Exec(ctx, context.String("exec-id"), pspec, ioCreator)
|
||||
process, err := task.Exec(ctx, cliContext.String("exec-id"), pspec, ioCreator)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -82,8 +82,8 @@ var killCommand = &cli.Command{
|
||||
Usage: "Send signal to all processes inside the container",
|
||||
},
|
||||
},
|
||||
Action: func(context *cli.Context) error {
|
||||
id := context.Args().First()
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
id := cliContext.Args().First()
|
||||
if id == "" {
|
||||
return errors.New("container id must be provided")
|
||||
}
|
||||
@@ -92,14 +92,14 @@ var killCommand = &cli.Command{
|
||||
return err
|
||||
}
|
||||
var (
|
||||
all = context.Bool("all")
|
||||
execID = context.String("exec-id")
|
||||
all = cliContext.Bool("all")
|
||||
execID = cliContext.String("exec-id")
|
||||
opts []containerd.KillOpts
|
||||
)
|
||||
if all && execID != "" {
|
||||
return errors.New("specify an exec-id or all; not both")
|
||||
}
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -114,8 +114,8 @@ var killCommand = &cli.Command{
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if context.String("signal") != "" {
|
||||
sig, err = signal.ParseSignal(context.String("signal"))
|
||||
if cliContext.String("signal") != "" {
|
||||
sig, err = signal.ParseSignal(cliContext.String("signal"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -38,9 +38,9 @@ var listCommand = &cli.Command{
|
||||
Usage: "Print only the task id",
|
||||
},
|
||||
},
|
||||
Action: func(context *cli.Context) error {
|
||||
quiet := context.Bool("quiet")
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
quiet := cliContext.Bool("quiet")
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -49,13 +49,13 @@ var metricsCommand = &cli.Command{
|
||||
Value: formatTable,
|
||||
},
|
||||
},
|
||||
Action: func(context *cli.Context) error {
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cancel()
|
||||
container, err := client.LoadContainer(ctx, context.Args().First())
|
||||
container, err := client.LoadContainer(ctx, cliContext.Args().First())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -83,7 +83,7 @@ var metricsCommand = &cli.Command{
|
||||
return err
|
||||
}
|
||||
|
||||
switch context.String(formatFlag) {
|
||||
switch cliContext.String(formatFlag) {
|
||||
case formatTable:
|
||||
w := tabwriter.NewWriter(os.Stdout, 1, 8, 4, ' ', 0)
|
||||
fmt.Fprintf(w, "ID\tTIMESTAMP\t\n")
|
||||
|
||||
@@ -25,13 +25,13 @@ var pauseCommand = &cli.Command{
|
||||
Name: "pause",
|
||||
Usage: "Pause an existing container",
|
||||
ArgsUsage: "CONTAINER",
|
||||
Action: func(context *cli.Context) error {
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cancel()
|
||||
container, err := client.LoadContainer(ctx, context.Args().First())
|
||||
container, err := client.LoadContainer(ctx, cliContext.Args().First())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -31,12 +31,12 @@ var psCommand = &cli.Command{
|
||||
Name: "ps",
|
||||
Usage: "List processes for container",
|
||||
ArgsUsage: "CONTAINER",
|
||||
Action: func(context *cli.Context) error {
|
||||
id := context.Args().First()
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
id := cliContext.Args().First()
|
||||
if id == "" {
|
||||
return errors.New("container id must be provided")
|
||||
}
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -25,13 +25,13 @@ var resumeCommand = &cli.Command{
|
||||
Name: "resume",
|
||||
Usage: "Resume a paused container",
|
||||
ArgsUsage: "CONTAINER",
|
||||
Action: func(context *cli.Context) error {
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cancel()
|
||||
container, err := client.LoadContainer(ctx, context.Args().First())
|
||||
container, err := client.LoadContainer(ctx, cliContext.Args().First())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -55,16 +55,16 @@ var startCommand = &cli.Command{
|
||||
Usage: "Detach from the task after it has started execution",
|
||||
},
|
||||
}...),
|
||||
Action: func(context *cli.Context) error {
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
var (
|
||||
err error
|
||||
id = context.Args().Get(0)
|
||||
detach = context.Bool("detach")
|
||||
id = cliContext.Args().Get(0)
|
||||
detach = cliContext.Bool("detach")
|
||||
)
|
||||
if id == "" {
|
||||
return errors.New("container id must be provided")
|
||||
}
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -80,8 +80,8 @@ var startCommand = &cli.Command{
|
||||
}
|
||||
var (
|
||||
tty = spec.Process.Terminal
|
||||
opts = GetNewTaskOpts(context)
|
||||
ioOpts = []cio.Opt{cio.WithFIFODir(context.String("fifo-dir"))}
|
||||
opts = GetNewTaskOpts(cliContext)
|
||||
ioOpts = []cio.Opt{cio.WithFIFODir(cliContext.String("fifo-dir"))}
|
||||
)
|
||||
var con console.Console
|
||||
if tty {
|
||||
@@ -92,7 +92,7 @@ var startCommand = &cli.Command{
|
||||
}
|
||||
}
|
||||
|
||||
task, err := NewTask(ctx, client, container, "", con, context.Bool("null-io"), context.String("log-uri"), ioOpts, opts...)
|
||||
task, err := NewTask(ctx, client, container, "", con, cliContext.Bool("null-io"), cliContext.String("log-uri"), ioOpts, opts...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -108,8 +108,8 @@ var startCommand = &cli.Command{
|
||||
return err
|
||||
}
|
||||
}
|
||||
if context.IsSet("pid-file") {
|
||||
if err := commands.WritePidFile(context.String("pid-file"), int(task.Pid())); err != nil {
|
||||
if cliContext.IsSet("pid-file") {
|
||||
if err := commands.WritePidFile(cliContext.String("pid-file"), int(task.Pid())); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
package tasks
|
||||
|
||||
import (
|
||||
gocontext "context"
|
||||
"context"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
type resizer interface {
|
||||
Resize(ctx gocontext.Context, w, h uint32) error
|
||||
Resize(ctx context.Context, w, h uint32) error
|
||||
}
|
||||
|
||||
// Command is the cli command for managing tasks
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
package tasks
|
||||
|
||||
import (
|
||||
gocontext "context"
|
||||
"context"
|
||||
"errors"
|
||||
"net/url"
|
||||
"os"
|
||||
@@ -41,7 +41,7 @@ var platformStartFlags = []cli.Flag{
|
||||
}
|
||||
|
||||
// HandleConsoleResize resizes the console
|
||||
func HandleConsoleResize(ctx gocontext.Context, task resizer, con console.Console) error {
|
||||
func HandleConsoleResize(ctx context.Context, task resizer, con console.Console) error {
|
||||
// do an initial resize of the console
|
||||
size, err := con.Size()
|
||||
if err != nil {
|
||||
@@ -68,7 +68,7 @@ func HandleConsoleResize(ctx gocontext.Context, task resizer, con console.Consol
|
||||
}
|
||||
|
||||
// NewTask creates a new task
|
||||
func NewTask(ctx gocontext.Context, client *containerd.Client, container containerd.Container, checkpoint string, con console.Console, nullIO bool, logURI string, ioOpts []cio.Opt, opts ...containerd.NewTaskOpts) (containerd.Task, error) {
|
||||
func NewTask(ctx context.Context, client *containerd.Client, container containerd.Container, checkpoint string, con console.Console, nullIO bool, logURI string, ioOpts []cio.Opt, opts ...containerd.NewTaskOpts) (containerd.Task, error) {
|
||||
stdinC := &stdinCloser{
|
||||
stdin: os.Stdin,
|
||||
}
|
||||
@@ -121,8 +121,8 @@ func NewTask(ctx gocontext.Context, client *containerd.Client, container contain
|
||||
}
|
||||
|
||||
// GetNewTaskOpts resolves containerd.NewTaskOpts from cli.Context
|
||||
func GetNewTaskOpts(context *cli.Context) []containerd.NewTaskOpts {
|
||||
if context.Bool("no-pivot") {
|
||||
func GetNewTaskOpts(cliContext *cli.Context) []containerd.NewTaskOpts {
|
||||
if cliContext.Bool("no-pivot") {
|
||||
return []containerd.NewTaskOpts{containerd.WithNoPivotRoot}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package tasks
|
||||
|
||||
import (
|
||||
gocontext "context"
|
||||
"context"
|
||||
"errors"
|
||||
"net/url"
|
||||
"time"
|
||||
@@ -32,7 +32,7 @@ import (
|
||||
var platformStartFlags = []cli.Flag{}
|
||||
|
||||
// HandleConsoleResize resizes the console
|
||||
func HandleConsoleResize(ctx gocontext.Context, task resizer, con console.Console) error {
|
||||
func HandleConsoleResize(ctx context.Context, task resizer, con console.Console) error {
|
||||
// do an initial resize of the console
|
||||
size, err := con.Size()
|
||||
if err != nil {
|
||||
@@ -61,7 +61,7 @@ func HandleConsoleResize(ctx gocontext.Context, task resizer, con console.Consol
|
||||
}
|
||||
|
||||
// NewTask creates a new task
|
||||
func NewTask(ctx gocontext.Context, client *containerd.Client, container containerd.Container, _ string, con console.Console, nullIO bool, logURI string, ioOpts []cio.Opt, opts ...containerd.NewTaskOpts) (containerd.Task, error) {
|
||||
func NewTask(ctx context.Context, client *containerd.Client, container containerd.Container, _ string, con console.Console, nullIO bool, logURI string, ioOpts []cio.Opt, opts ...containerd.NewTaskOpts) (containerd.Task, error) {
|
||||
var ioCreator cio.Creator
|
||||
if con != nil {
|
||||
if nullIO {
|
||||
|
||||
Reference in New Issue
Block a user