Skip to content

Commit c0ec0f1

Browse files
authored
add functional tests for cgorup in gcs (#2664)
Signed-off-by: Jie Chen <jiechen3@microsoft.com>
1 parent c03ae0f commit c0ec0f1

File tree

3 files changed

+567
-6
lines changed

3 files changed

+567
-6
lines changed

internal/guest/cgroup/cgroup.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,24 @@ func LoadAndStat(cgroupPath string) (*cgroups1stats.Metrics, error) {
343343
return cg.Stat(cgroups1.IgnoreNotExist)
344344
}
345345

346+
// LoadManager loads an existing cgroup (created by the runtime) and returns a Manager.
347+
// Unlike NewManager, this does not create the cgroup — it wraps one that already exists.
348+
func LoadManager(cgroupPath string) (Manager, error) {
349+
if IsCgroupV2() {
350+
mgr, err := cgroups2.Load(cgroupPath)
351+
if err != nil {
352+
return nil, errors.Wrapf(err, "failed to load v2 cgroup %s", cgroupPath)
353+
}
354+
return &V2Mgr{mgr: mgr, path: cgroupPath, done: make(chan struct{})}, nil
355+
}
356+
357+
cg, err := cgroups1.Load(cgroups1.StaticPath(cgroupPath))
358+
if err != nil {
359+
return nil, errors.Wrapf(err, "failed to load v1 cgroup %s", cgroupPath)
360+
}
361+
return &V1Mgr{cg: cg}, nil
362+
}
363+
346364
// Compile-time interface satisfaction checks.
347365
var (
348366
_ Manager = &V1Mgr{}

0 commit comments

Comments
 (0)