Merge pull request #13661 from akerouanton/default-unix-spec

oci: use path.Join to fill CgroupsPath
This commit is contained in:
Derek McGowan
2026-06-25 14:18:19 +00:00
committed by GitHub
2 changed files with 9 additions and 2 deletions

View File

@@ -20,7 +20,7 @@ import (
"context"
"encoding/json"
"os"
"path/filepath"
"path"
"runtime"
"github.com/opencontainers/go-digest"
@@ -206,7 +206,7 @@ func populateDefaultUnixSpec(ctx context.Context, s *Spec, id string) error {
"/proc/sys",
"/proc/sysrq-trigger",
},
CgroupsPath: filepath.Join("/", ns, id),
CgroupsPath: path.Join("/", ns, id),
Resources: &specs.LinuxResources{
Devices: []specs.LinuxDeviceCgroup{
{

View File

@@ -23,6 +23,7 @@ import (
"os"
"path/filepath"
"runtime"
"strings"
"testing"
"github.com/containerd/containerd/v2/core/containers"
@@ -253,6 +254,12 @@ func TestPopulateDefaultUnixSpec(t *testing.T) {
if expected.Linux == nil {
t.Error("Cannot populate Unix Spec")
}
// CgroupsPath should never contain backslashes when the spec is generated
// on Windows.
if strings.Contains(expected.Linux.CgroupsPath, "\\") {
t.Errorf("CgroupsPath contains backslashes: %s", expected.Linux.CgroupsPath)
}
}
func TestWithPrivileged(t *testing.T) {