Files
nomad/client/lib/proclib/wrangler_cg2_linux.go
Luiz Aoqui db5ffde2b7 client: prevent start on cgroups init error (#19915)
The Nomad client expects certain cgroups paths to exist in order to
manage tasks. These paths are created when the agent first starts, but
if process fails the agent would just log the error and proceed with its
initialization, despite not being able to run tasks.

This commit surfaces the errors back to the client initialization so the
process can stop early and make clear to operators that something went
wrong.
2024-02-09 13:45:29 -05:00

53 lines
1.2 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
//go:build linux
package proclib
import (
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/nomad/client/lib/cgroupslib"
)
// LinuxWranglerCG2 is an implementation of ProcessWrangler that leverages
// cgroups v2 on modern Linux systems.
//
// e.g. Ubuntu 22.04 / RHEL 9 and later versions.
type LinuxWranglerCG2 struct {
task Task
log hclog.Logger
cg cgroupslib.Lifecycle
}
func newCG2(c *Configs) (create, error) {
logger := c.Logger.Named("cg2")
err := cgroupslib.Init(logger, c.UsableCores.String())
if err != nil {
return nil, err
}
return func(task Task) ProcessWrangler {
return &LinuxWranglerCG2{
task: task,
log: c.Logger,
cg: cgroupslib.Factory(task.AllocID, task.Task, task.Cores),
}
}, nil
}
func (w LinuxWranglerCG2) Initialize() error {
w.log.Trace("initialize cgroup", "task", w.task)
return w.cg.Setup()
}
func (w *LinuxWranglerCG2) Kill() error {
w.log.Trace("force kill processes in cgroup", "task", w.task)
return w.cg.Kill()
}
func (w *LinuxWranglerCG2) Cleanup() error {
w.log.Trace("remove cgroup", "task", w.task)
return w.cg.Teardown()
}