Skip to content

Commit 984aa33

Browse files
authored
Merge pull request #5316 from alakesh/stress-snapshotter-cli-option
Add snapshotter cli option to containerd-stress utility
2 parents 68ee827 + 0550c32 commit 984aa33

4 files changed

Lines changed: 29 additions & 15 deletions

File tree

cmd/containerd-stress/density.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ var densityCommand = cli.Command{
5555
Exec: cliContext.GlobalBool("exec"),
5656
JSON: cliContext.GlobalBool("json"),
5757
Metrics: cliContext.GlobalString("metrics"),
58+
Snapshotter: cliContext.GlobalString("snapshotter"),
5859
}
5960
client, err := config.newClient()
6061
if err != nil {
@@ -66,7 +67,7 @@ var densityCommand = cli.Command{
6667
return err
6768
}
6869
logrus.Infof("pulling %s", imageName)
69-
image, err := client.Pull(ctx, imageName, containerd.WithPullUnpack)
70+
image, err := client.Pull(ctx, imageName, containerd.WithPullUnpack, containerd.WithPullSnapshotter(config.Snapshotter))
7071
if err != nil {
7172
return err
7273
}
@@ -91,6 +92,7 @@ var densityCommand = cli.Command{
9192
id := fmt.Sprintf("density-%d", i)
9293

9394
c, err := client.NewContainer(ctx, id,
95+
containerd.WithSnapshotter(config.Snapshotter),
9496
containerd.WithNewSnapshot(id, image),
9597
containerd.WithNewSpec(
9698
oci.WithImageConfig(image),

cmd/containerd-stress/exec_worker.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func (w *execWorker) exec(ctx, tctx context.Context) {
4242
id := fmt.Sprintf("exec-container-%d", w.id)
4343
c, err := w.client.NewContainer(ctx, id,
4444
containerd.WithNewSnapshot(id, w.image),
45+
containerd.WithSnapshotter(w.snapshotter),
4546
containerd.WithNewSpec(oci.WithImageConfig(w.image), oci.WithUsername("games"), oci.WithProcessArgs("sleep", "30d")),
4647
)
4748
if err != nil {

cmd/containerd-stress/main.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ func main() {
149149
Usage: "set the runtime to stress test",
150150
Value: plugin.RuntimeRuncV2,
151151
},
152+
cli.StringFlag{
153+
Name: "snapshotter",
154+
Usage: "set the snapshotter to use",
155+
Value: "overlayfs",
156+
},
152157
}
153158
app.Before = func(context *cli.Context) error {
154159
if context.GlobalBool("json") {
@@ -171,6 +176,7 @@ func main() {
171176
JSON: context.GlobalBool("json"),
172177
Metrics: context.GlobalString("metrics"),
173178
Runtime: context.GlobalString("runtime"),
179+
Snapshotter: context.GlobalString("snapshotter"),
174180
}
175181
if config.Metrics != "" {
176182
return serve(config)
@@ -191,6 +197,7 @@ type config struct {
191197
JSON bool
192198
Metrics string
193199
Runtime string
200+
Snapshotter string
194201
}
195202

196203
func (c config) newClient() (*containerd.Client, error) {
@@ -222,7 +229,7 @@ func test(c config) error {
222229
return err
223230
}
224231
logrus.Infof("pulling %s", imageName)
225-
image, err := client.Pull(ctx, imageName, containerd.WithPullUnpack)
232+
image, err := client.Pull(ctx, imageName, containerd.WithPullUnpack, containerd.WithPullSnapshotter(c.Snapshotter))
226233
if err != nil {
227234
return err
228235
}
@@ -247,11 +254,12 @@ func test(c config) error {
247254
for i := 0; i < c.Concurrency; i++ {
248255
wg.Add(1)
249256
w := &worker{
250-
id: i,
251-
wg: &wg,
252-
image: image,
253-
client: client,
254-
commit: v.Revision,
257+
id: i,
258+
wg: &wg,
259+
image: image,
260+
client: client,
261+
commit: v.Revision,
262+
snapshotter: c.Snapshotter,
255263
}
256264
workers = append(workers, w)
257265
}
@@ -261,11 +269,12 @@ func test(c config) error {
261269
wg.Add(1)
262270
exec = &execWorker{
263271
worker: worker{
264-
id: i,
265-
wg: &wg,
266-
image: image,
267-
client: client,
268-
commit: v.Revision,
272+
id: i,
273+
wg: &wg,
274+
image: image,
275+
client: client,
276+
commit: v.Revision,
277+
snapshotter: c.Snapshotter,
269278
},
270279
}
271280
go exec.exec(ctx, tctx)

cmd/containerd-stress/worker.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ type worker struct {
3535
count int
3636
failures int
3737

38-
client *containerd.Client
39-
image containerd.Image
40-
commit string
38+
client *containerd.Client
39+
image containerd.Image
40+
commit string
41+
snapshotter string
4142
}
4243

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

0 commit comments

Comments
 (0)