Skip to content

Commit 8743ab9

Browse files
authored
Merge pull request #304 from alexei-led/fix/containerd-inject-cgroup
fix: support --inject-cgroup and sidecar stress modes on containerd
2 parents e4ebe5a + 9134310 commit 8743ab9

File tree

7 files changed

+852
-42
lines changed

7 files changed

+852
-42
lines changed

pkg/runtime/containerd/client.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,16 +321,30 @@ func (c *containerdClient) runIPTablesCommands(ctx context.Context, containerID
321321
return nil
322322
}
323323

324-
// StressContainer runs stress-ng inside a container.
324+
// StressContainer runs stress-ng to stress a container.
325+
// Mode selection:
326+
// - image == "": direct exec inside the target container
327+
// - image != "" && !injectCgroup: sidecar with /stress-ng in target's cgroup parent
328+
// - image != "" && injectCgroup: sidecar with /cg-inject injecting into target's cgroup
325329
func (c *containerdClient) StressContainer(ctx context.Context, container *ctr.Container,
326330
stressors []string, image string, pull bool, duration time.Duration, injectCgroup, dryrun bool) (string, <-chan string, <-chan error, error) {
327-
log.WithField("id", container.ID()).Debug("stress on containerd container")
328-
if image != "" || pull || injectCgroup {
329-
log.WithField("id", container.ID()).Warn("containerd runtime: sidecar/inject-cgroup stress modes not supported, using direct exec")
330-
}
331+
log.WithFields(log.Fields{
332+
"id": container.ID(),
333+
"image": image,
334+
"inject-cgroup": injectCgroup,
335+
}).Debug("stress on containerd container")
331336
if dryrun {
332337
return "", nil, nil, nil
333338
}
339+
if image != "" {
340+
return c.stressSidecar(ctx, container, image, stressors, injectCgroup, pull)
341+
}
342+
return c.stressDirectExec(ctx, container, stressors, duration)
343+
}
344+
345+
// stressDirectExec runs stress-ng directly inside the target container via exec.
346+
func (c *containerdClient) stressDirectExec(ctx context.Context, container *ctr.Container,
347+
stressors []string, duration time.Duration) (string, <-chan string, <-chan error, error) {
334348
errCh := make(chan error, 1)
335349
outCh := make(chan string, 1)
336350
go func() {

0 commit comments

Comments
 (0)