diff --git a/cmd/containerd-stress/exec_worker.go b/cmd/containerd-stress/exec_worker.go index 54ced023e..32c9a737e 100644 --- a/cmd/containerd-stress/exec_worker.go +++ b/cmd/containerd-stress/exec_worker.go @@ -18,7 +18,6 @@ package main import ( "context" - "path/filepath" "strings" "syscall" "time" @@ -39,14 +38,9 @@ func (w *execWorker) exec(ctx, tctx context.Context) { w.wg.Done() logrus.Infof("worker %d finished", w.id) }() - // create and start the exec container - w.spec.Linux.CgroupsPath = filepath.Join("/", "stress", "exec-container") - w.spec.Process.Args = []string{ - "sleep", "30d", - } c, err := w.client.NewContainer(ctx, "exec-container", containerd.WithNewSnapshot("exec-container", w.image), - containerd.WithSpec(w.spec, oci.WithUsername("games")), + containerd.WithNewSpec(oci.WithImageConfig(w.image), oci.WithUsername("games"), oci.WithProcessArgs("sleep", "30d")), ) if err != nil { logrus.WithError(err).Error("create exec container") @@ -66,8 +60,13 @@ func (w *execWorker) exec(ctx, tctx context.Context) { logrus.WithError(err).Error("wait exec container's task") return } + spec, err := c.Spec(ctx) + if err != nil { + logrus.WithError(err).Error("failed to get spec") + return + } - pspec := w.spec.Process + pspec := spec.Process pspec.Args = []string{"true"} for { diff --git a/cmd/containerd-stress/main.go b/cmd/containerd-stress/main.go index 4ff62599e..6d21ce2d9 100644 --- a/cmd/containerd-stress/main.go +++ b/cmd/containerd-stress/main.go @@ -29,9 +29,7 @@ import ( "time" "github.com/containerd/containerd" - "github.com/containerd/containerd/containers" "github.com/containerd/containerd/namespaces" - "github.com/containerd/containerd/oci" metrics "github.com/docker/go-metrics" "github.com/sirupsen/logrus" "github.com/urfave/cli" @@ -227,7 +225,6 @@ func test(c config) error { if err != nil { return err } - logrus.Info("generating spec from image") tctx, cancel := context.WithTimeout(ctx, c.Duration) go func() { s := make(chan os.Signal, 1) @@ -241,7 +238,6 @@ func test(c config) error { r = &run{} ) logrus.Info("starting stress test run...") - args := oci.WithProcessArgs("true") v, err := client.Version(ctx) if err != nil { return err @@ -249,18 +245,9 @@ func test(c config) error { // create the workers along with their spec for i := 0; i < c.Concurrency; i++ { wg.Add(1) - spec, err := oci.GenerateSpec(ctx, client, - &containers.Container{}, - oci.WithImageConfig(image), - args, - ) - if err != nil { - return err - } w := &worker{ id: i, wg: &wg, - spec: spec, image: image, client: client, commit: v.Revision, @@ -270,19 +257,10 @@ func test(c config) error { var exec *execWorker if c.Exec { wg.Add(1) - spec, err := oci.GenerateSpec(ctx, client, - &containers.Container{}, - oci.WithImageConfig(image), - args, - ) - if err != nil { - return err - } exec = &execWorker{ worker: worker{ id: c.Concurrency, wg: &wg, - spec: spec, image: image, client: client, commit: v.Revision, diff --git a/cmd/containerd-stress/worker.go b/cmd/containerd-stress/worker.go index ca6687d1c..0b9b2801a 100644 --- a/cmd/containerd-stress/worker.go +++ b/cmd/containerd-stress/worker.go @@ -19,7 +19,6 @@ package main import ( "context" "fmt" - "path/filepath" "strings" "sync" "time" @@ -27,7 +26,6 @@ import ( "github.com/containerd/containerd" "github.com/containerd/containerd/cio" "github.com/containerd/containerd/oci" - specs "github.com/opencontainers/runtime-spec/specs-go" "github.com/sirupsen/logrus" ) @@ -39,7 +37,6 @@ type worker struct { client *containerd.Client image containerd.Image - spec *specs.Spec commit string } @@ -76,10 +73,9 @@ 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 - w.spec.Linux.CgroupsPath = filepath.Join("/", "stress", id) c, err := w.client.NewContainer(ctx, id, containerd.WithNewSnapshot(id, w.image), - containerd.WithSpec(w.spec, oci.WithUsername("games")), + containerd.WithNewSpec(oci.WithImageConfig(w.image), oci.WithUsername("games"), oci.WithProcessArgs("true")), ) if err != nil { return err