Skip to content

Commit 263a604

Browse files
committed
Support cgroups v2
Some of our tests are assuming cgroups v1, but our BuildKite hosts are now using cgroups v2. Signed-off-by: Kazuyoshi Kato <[email protected]>
1 parent c02f65a commit 263a604

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

runtime/integ_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
package main
1414

1515
import (
16+
"os"
17+
"path/filepath"
1618
"strings"
1719

1820
"github.com/firecracker-microvm/firecracker-containerd/internal"
@@ -38,3 +40,15 @@ var testNameToVMIDReplacer = strings.NewReplacer("/", "-", "_", "-")
3840
func testNameToVMID(s string) string {
3941
return testNameToVMIDReplacer.Replace(s)
4042
}
43+
44+
func cgroupExists(name string) bool {
45+
// cgroups v1
46+
_, err := os.Stat(filepath.Join("/sys/fs/cgroup/cpu", name))
47+
if err == nil {
48+
return true
49+
}
50+
51+
// cgroups v2
52+
_, err = os.Stat(filepath.Join("/sys/fs/cgroup", name))
53+
return err == nil
54+
}

runtime/jailer_integ_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,13 @@ func testJailer(t *testing.T, jailerConfig *proto.JailerConfig) {
140140
fcClient, err := integtest.NewFCControlClient(integtest.ContainerdSockPath)
141141
require.NoError(t, err)
142142

143-
_, err = fcClient.CreateVM(ctx, &request)
143+
resp, err := fcClient.CreateVM(ctx, &request)
144144
require.NoError(t, err)
145145

146+
if jailerConfig != nil {
147+
assert.True(t, cgroupExists(resp.CgroupPath))
148+
}
149+
146150
c, err := client.NewContainer(ctx,
147151
vmID+"-container",
148152
containerd.WithSnapshotter(defaultSnapshotterName),

runtime/service_integ_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -612,9 +612,8 @@ func testMultipleExecs(
612612
if err != nil {
613613
return err
614614
}
615-
_, err = os.Stat(filepath.Join("/sys/fs/cgroup/cpu", cgroupPath))
616-
if err != nil {
617-
return err
615+
if !cgroupExists(cgroupPath) {
616+
return fmt.Errorf("failed to find %q", cgroupPath)
618617
}
619618

620619
ok, err := regexp.Match(".+/"+vmIDStr, []byte(cgroupPath))

0 commit comments

Comments
 (0)