-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Alternative to 148] go.mod: github.com/containerd/containerd/v2 v2.0…
….0-rc.0 Similar to PR 148, but does not bump up urfave/cli. - `cmd/ctr` is kept to use urfave/cli v1, but its containerd library is bumped up from v1.6 to v1.7 due to dependencies. typeurl is bumped up from v1 to v2 as a part of them. - `cmd/ctr/v2v1glue` and `cmd/ctr/v1v2glue` are added for using containerd v2-based encryption library from containerd v1-based CLI. - `cmd/ctr/commands/tasks` was copied from <https://github.com/containerd/containerd/tree/v1.7.14/cmd/ctr/commands/tasks>, but `metrics.go` was removed due to a dependency issue: containerd v1 depends on hcsshim v0.11, while containerd v2 depends on hcsshim v0.12. Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
- Loading branch information
1 parent
2db95f3
commit fa20237
Showing
31 changed files
with
1,892 additions
and
3,583 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
Copyright The containerd Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package tasks | ||
|
||
import ( | ||
"github.com/containerd/console" | ||
"github.com/containerd/containerd/cio" | ||
"github.com/containerd/containerd/cmd/ctr/commands" | ||
"github.com/sirupsen/logrus" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
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) | ||
if err != nil { | ||
return err | ||
} | ||
defer cancel() | ||
container, err := client.LoadContainer(ctx, context.Args().First()) | ||
if err != nil { | ||
return err | ||
} | ||
spec, err := container.Spec(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
var ( | ||
con console.Console | ||
tty = spec.Process.Terminal | ||
) | ||
if tty { | ||
con = console.Current() | ||
defer con.Reset() | ||
if err := con.SetRaw(); err != nil { | ||
return err | ||
} | ||
} | ||
task, err := container.Task(ctx, cio.NewAttach(cio.WithStdio)) | ||
if err != nil { | ||
return err | ||
} | ||
defer task.Delete(ctx) | ||
|
||
statusC, err := task.Wait(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if tty { | ||
if err := HandleConsoleResize(ctx, task, con); err != nil { | ||
logrus.WithError(err).Error("console resize") | ||
} | ||
} else { | ||
sigc := commands.ForwardAllSignals(ctx, task) | ||
defer commands.StopCatch(sigc) | ||
} | ||
|
||
ec := <-statusC | ||
code, _, err := ec.Result() | ||
if err != nil { | ||
return err | ||
} | ||
if code != 0 { | ||
return cli.NewExitError("", int(code)) | ||
} | ||
return nil | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
Copyright The containerd Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package tasks | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/containerd/containerd" | ||
"github.com/containerd/containerd/cmd/ctr/commands" | ||
"github.com/containerd/containerd/plugin" | ||
"github.com/containerd/containerd/runtime/linux/runctypes" | ||
"github.com/containerd/containerd/runtime/v2/runc/options" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
var checkpointCommand = cli.Command{ | ||
Name: "checkpoint", | ||
Usage: "Checkpoint a container", | ||
ArgsUsage: "[flags] CONTAINER", | ||
Flags: []cli.Flag{ | ||
cli.BoolFlag{ | ||
Name: "exit", | ||
Usage: "Stop the container after the checkpoint", | ||
}, | ||
cli.StringFlag{ | ||
Name: "image-path", | ||
Usage: "Path to criu image files", | ||
}, | ||
cli.StringFlag{ | ||
Name: "work-path", | ||
Usage: "Path to criu work files and logs", | ||
}, | ||
}, | ||
Action: func(context *cli.Context) error { | ||
id := context.Args().First() | ||
if id == "" { | ||
return errors.New("container id must be provided") | ||
} | ||
client, ctx, cancel, err := commands.NewClient(context, containerd.WithDefaultRuntime(context.String("runtime"))) | ||
if err != nil { | ||
return err | ||
} | ||
defer cancel() | ||
container, err := client.LoadContainer(ctx, id) | ||
if err != nil { | ||
return err | ||
} | ||
task, err := container.Task(ctx, nil) | ||
if err != nil { | ||
return err | ||
} | ||
info, err := container.Info(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
opts := []containerd.CheckpointTaskOpts{withCheckpointOpts(info.Runtime.Name, context)} | ||
checkpoint, err := task.Checkpoint(ctx, opts...) | ||
if err != nil { | ||
return err | ||
} | ||
if context.String("image-path") == "" { | ||
fmt.Println(checkpoint.Name()) | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
// withCheckpointOpts only suitable for runc runtime now | ||
func withCheckpointOpts(rt string, context *cli.Context) containerd.CheckpointTaskOpts { | ||
return func(r *containerd.CheckpointTaskInfo) error { | ||
imagePath := context.String("image-path") | ||
workPath := context.String("work-path") | ||
|
||
switch rt { | ||
case plugin.RuntimeRuncV1, plugin.RuntimeRuncV2: | ||
if r.Options == nil { | ||
r.Options = &options.CheckpointOptions{} | ||
} | ||
opts, _ := r.Options.(*options.CheckpointOptions) | ||
|
||
if context.Bool("exit") { | ||
opts.Exit = true | ||
} | ||
if imagePath != "" { | ||
opts.ImagePath = imagePath | ||
} | ||
if workPath != "" { | ||
opts.WorkPath = workPath | ||
} | ||
case plugin.RuntimeLinuxV1: | ||
if r.Options == nil { | ||
r.Options = &runctypes.CheckpointOptions{} | ||
} | ||
opts, _ := r.Options.(*runctypes.CheckpointOptions) | ||
|
||
if context.Bool("exit") { | ||
opts.Exit = true | ||
} | ||
if imagePath != "" { | ||
opts.ImagePath = imagePath | ||
} | ||
if workPath != "" { | ||
opts.WorkPath = workPath | ||
} | ||
} | ||
return nil | ||
} | ||
} |
Oops, something went wrong.