Skip to content

Commit

Permalink
Merge pull request #5316 from alakesh/stress-snapshotter-cli-option
Browse files Browse the repository at this point in the history
Add snapshotter cli option to containerd-stress utility
  • Loading branch information
estesp committed Apr 13, 2021
2 parents 68ee827 + 0550c32 commit 984aa33
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
4 changes: 3 additions & 1 deletion cmd/containerd-stress/density.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ var densityCommand = cli.Command{
Exec: cliContext.GlobalBool("exec"),
JSON: cliContext.GlobalBool("json"),
Metrics: cliContext.GlobalString("metrics"),
Snapshotter: cliContext.GlobalString("snapshotter"),
}
client, err := config.newClient()
if err != nil {
Expand All @@ -66,7 +67,7 @@ var densityCommand = cli.Command{
return err
}
logrus.Infof("pulling %s", imageName)
image, err := client.Pull(ctx, imageName, containerd.WithPullUnpack)
image, err := client.Pull(ctx, imageName, containerd.WithPullUnpack, containerd.WithPullSnapshotter(config.Snapshotter))
if err != nil {
return err
}
Expand All @@ -91,6 +92,7 @@ var densityCommand = cli.Command{
id := fmt.Sprintf("density-%d", i)

c, err := client.NewContainer(ctx, id,
containerd.WithSnapshotter(config.Snapshotter),
containerd.WithNewSnapshot(id, image),
containerd.WithNewSpec(
oci.WithImageConfig(image),
Expand Down
1 change: 1 addition & 0 deletions cmd/containerd-stress/exec_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func (w *execWorker) exec(ctx, tctx context.Context) {
id := fmt.Sprintf("exec-container-%d", w.id)
c, err := w.client.NewContainer(ctx, id,
containerd.WithNewSnapshot(id, w.image),
containerd.WithSnapshotter(w.snapshotter),
containerd.WithNewSpec(oci.WithImageConfig(w.image), oci.WithUsername("games"), oci.WithProcessArgs("sleep", "30d")),
)
if err != nil {
Expand Down
31 changes: 20 additions & 11 deletions cmd/containerd-stress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ func main() {
Usage: "set the runtime to stress test",
Value: plugin.RuntimeRuncV2,
},
cli.StringFlag{
Name: "snapshotter",
Usage: "set the snapshotter to use",
Value: "overlayfs",
},
}
app.Before = func(context *cli.Context) error {
if context.GlobalBool("json") {
Expand All @@ -171,6 +176,7 @@ func main() {
JSON: context.GlobalBool("json"),
Metrics: context.GlobalString("metrics"),
Runtime: context.GlobalString("runtime"),
Snapshotter: context.GlobalString("snapshotter"),
}
if config.Metrics != "" {
return serve(config)
Expand All @@ -191,6 +197,7 @@ type config struct {
JSON bool
Metrics string
Runtime string
Snapshotter string
}

func (c config) newClient() (*containerd.Client, error) {
Expand Down Expand Up @@ -222,7 +229,7 @@ func test(c config) error {
return err
}
logrus.Infof("pulling %s", imageName)
image, err := client.Pull(ctx, imageName, containerd.WithPullUnpack)
image, err := client.Pull(ctx, imageName, containerd.WithPullUnpack, containerd.WithPullSnapshotter(c.Snapshotter))
if err != nil {
return err
}
Expand All @@ -247,11 +254,12 @@ func test(c config) error {
for i := 0; i < c.Concurrency; i++ {
wg.Add(1)
w := &worker{
id: i,
wg: &wg,
image: image,
client: client,
commit: v.Revision,
id: i,
wg: &wg,
image: image,
client: client,
commit: v.Revision,
snapshotter: c.Snapshotter,
}
workers = append(workers, w)
}
Expand All @@ -261,11 +269,12 @@ func test(c config) error {
wg.Add(1)
exec = &execWorker{
worker: worker{
id: i,
wg: &wg,
image: image,
client: client,
commit: v.Revision,
id: i,
wg: &wg,
image: image,
client: client,
commit: v.Revision,
snapshotter: c.Snapshotter,
},
}
go exec.exec(ctx, tctx)
Expand Down
8 changes: 5 additions & 3 deletions cmd/containerd-stress/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ type worker struct {
count int
failures int

client *containerd.Client
image containerd.Image
commit string
client *containerd.Client
image containerd.Image
commit string
snapshotter string
}

func (w *worker) run(ctx, tctx context.Context) {
Expand Down Expand Up @@ -74,6 +75,7 @@ func (w *worker) run(ctx, tctx context.Context) {
func (w *worker) runContainer(ctx context.Context, id string) (err error) {
// fix up cgroups path for a default config
c, err := w.client.NewContainer(ctx, id,
containerd.WithSnapshotter(w.snapshotter),
containerd.WithNewSnapshot(id, w.image),
containerd.WithNewSpec(oci.WithImageConfig(w.image), oci.WithUsername("games"), oci.WithProcessArgs("true")),
)
Expand Down

0 comments on commit 984aa33

Please sign in to comment.