Skip to content

Commit

Permalink
Fix stress test for image config opt requirements
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
  • Loading branch information
crosbymichael committed Oct 15, 2018
1 parent d725ebe commit e86a068
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 35 deletions.
15 changes: 7 additions & 8 deletions cmd/containerd-stress/exec_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package main

import (
"context"
"path/filepath"
"strings"
"syscall"
"time"
Expand All @@ -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")
Expand All @@ -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 {
Expand Down
22 changes: 0 additions & 22 deletions cmd/containerd-stress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -241,26 +238,16 @@ 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
}
// 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,
Expand All @@ -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,
Expand Down
6 changes: 1 addition & 5 deletions cmd/containerd-stress/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ package main
import (
"context"
"fmt"
"path/filepath"
"strings"
"sync"
"time"

"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"
)

Expand All @@ -39,7 +37,6 @@ type worker struct {

client *containerd.Client
image containerd.Image
spec *specs.Spec
commit string
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e86a068

Please sign in to comment.