Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Commit

Permalink
oci: Follow the OCI spec for cgroup paths
Browse files Browse the repository at this point in the history
Getting an absolute path while not having a cgroup mount
from the OCI spec is a valid case. In that case the path
should be interpreted as a relative one to the system
cgroup mount point.

Fixes #552

Signed-off-by: Samuel Ortiz <[email protected]>
  • Loading branch information
Samuel Ortiz committed Sep 14, 2017
1 parent d34cdad commit 17cdf23
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
10 changes: 3 additions & 7 deletions oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,9 @@ func processCgroupsPathForResource(ociSpec oci.CompatOCISpec, resource string, i
}

if !cgroupMountFound {
if isPod {
return "", fmt.Errorf("cgroupsPath %q is absolute, cgroup mount MUST exist",
ociSpec.Linux.CgroupsPath)
}

// In case of container (CRI-O), if the mount point is not
// provided, we assume this is a relative path.
// According to the OCI spec, an absolute path should be
// interpreted as relative to the system cgroup mount point
// when there is no cgroup mount point.
return filepath.Join(cgroupsDirPath, resource, ociSpec.Linux.CgroupsPath), nil
}

Expand Down
10 changes: 5 additions & 5 deletions oci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,9 @@ func TestProcessCgroupsPathRelativePathSuccessful(t *testing.T) {
}
}

func TestProcessCgroupsPathAbsoluteNoCgroupMountFailure(t *testing.T) {
assert := assert.New(t)
func TestProcessCgroupsPathAbsoluteNoCgroupMountSuccessful(t *testing.T) {
absoluteCgroupsPath := "/absolute/cgroups/path"
cgroupsDirPath = "/foo/runtime/base"

ociSpec := oci.CompatOCISpec{}

Expand All @@ -357,9 +357,9 @@ func TestProcessCgroupsPathAbsoluteNoCgroupMountFailure(t *testing.T) {
for _, d := range cgroupTestData {
ociSpec.Linux.Resources = d.linuxSpec

_, err := processCgroupsPath(ociSpec, true)
assert.Error(err, "This test should fail because no cgroup mount provided (%+v)", d)
assert.False(vcMock.IsMockError(err))
p := filepath.Join(cgroupsDirPath, d.resource, absoluteCgroupsPath)

testProcessCgroupsPath(t, ociSpec, []string{p})
}
}

Expand Down

0 comments on commit 17cdf23

Please sign in to comment.