github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/client/fingerprint/cgroup_linux.go (about)

     1  //go:build linux
     2  
     3  package fingerprint
     4  
     5  import (
     6  	"fmt"
     7  )
     8  
     9  const (
    10  	cgroupAvailable = "available"
    11  )
    12  
    13  // Fingerprint tries to find a valid cgroup mount point and the version of cgroups
    14  // if a mount-point is present.
    15  func (f *CGroupFingerprint) Fingerprint(req *FingerprintRequest, resp *FingerprintResponse) error {
    16  	mount, err := f.mountPointDetector.MountPoint()
    17  	if err != nil {
    18  		f.clearCGroupAttributes(resp)
    19  		return fmt.Errorf("failed to discover cgroup mount point: %s", err)
    20  	}
    21  
    22  	// Check if a cgroup mount point was found.
    23  	if mount == "" {
    24  		f.clearCGroupAttributes(resp)
    25  		if f.lastState == cgroupAvailable {
    26  			f.logger.Warn("cgroups are now unavailable")
    27  		}
    28  		f.lastState = cgroupUnavailable
    29  		return nil
    30  	}
    31  
    32  	// Check the version in use.
    33  	version := f.versionDetector.CgroupVersion()
    34  
    35  	resp.AddAttribute(cgroupMountPointAttribute, mount)
    36  	resp.AddAttribute(cgroupVersionAttribute, version)
    37  	resp.Detected = true
    38  
    39  	if f.lastState == cgroupUnavailable {
    40  		f.logger.Info("cgroups are available")
    41  	}
    42  	f.lastState = cgroupAvailable
    43  	return nil
    44  }