open-nomad/client/fingerprint/cgroup_linux.go
Tim Gross e5454362dc
CI: make make check clean on macOS (#14528)
Running `make check` on macOS identifies some dead code because the code is used
only with the Linux build tag. Move this code into appropriately-tagged code
files.
2022-09-09 12:26:34 -04:00

45 lines
1 KiB
Go

//go:build linux
package fingerprint
import (
"fmt"
)
const (
cgroupAvailable = "available"
)
// Fingerprint tries to find a valid cgroup mount point and the version of cgroups
// if a mount-point is present.
func (f *CGroupFingerprint) Fingerprint(req *FingerprintRequest, resp *FingerprintResponse) error {
mount, err := f.mountPointDetector.MountPoint()
if err != nil {
f.clearCGroupAttributes(resp)
return fmt.Errorf("failed to discover cgroup mount point: %s", err)
}
// Check if a cgroup mount point was found.
if mount == "" {
f.clearCGroupAttributes(resp)
if f.lastState == cgroupAvailable {
f.logger.Warn("cgroups are now unavailable")
}
f.lastState = cgroupUnavailable
return nil
}
// Check the version in use.
version := f.versionDetector.CgroupVersion()
resp.AddAttribute(cgroupMountPointAttribute, mount)
resp.AddAttribute(cgroupVersionAttribute, version)
resp.Detected = true
if f.lastState == cgroupUnavailable {
f.logger.Info("cgroups are available")
}
f.lastState = cgroupAvailable
return nil
}