open-nomad/client/allocrunner/cgroup_hook.go
2021-04-13 13:28:36 -04:00

33 lines
622 B
Go

package allocrunner
import (
"github.com/hashicorp/nomad/client/lib/cgutil"
"github.com/hashicorp/nomad/nomad/structs"
)
func newCgroupHook(alloc *structs.Allocation, man cgutil.CpusetManager) *cgroupHook {
return &cgroupHook{
alloc: alloc,
cpusetManager: man,
}
}
type cgroupHook struct {
alloc *structs.Allocation
cpusetManager cgutil.CpusetManager
}
func (c *cgroupHook) Name() string {
return "cgroup"
}
func (c *cgroupHook) Prerun() error {
c.cpusetManager.AddAlloc(c.alloc)
return nil
}
func (c *cgroupHook) Postrun() error {
c.cpusetManager.RemoveAlloc(c.alloc.ID)
return nil
}