mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 10:25:42 +03:00
client/fingerprint: move existing cgroup concerns to cgutil
This commit is contained in:
@@ -3,6 +3,8 @@ package fingerprint
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/nomad/client/lib/cgutil"
|
||||
|
||||
log "github.com/hashicorp/go-hclog"
|
||||
)
|
||||
|
||||
@@ -30,7 +32,7 @@ type DefaultMountPointDetector struct {
|
||||
|
||||
// Call out to the default cgroup library
|
||||
func (b *DefaultMountPointDetector) MountPoint() (string, error) {
|
||||
return FindCgroupMountpointDir()
|
||||
return cgutil.FindCgroupMountpointDir()
|
||||
}
|
||||
|
||||
// NewCGroupFingerprint returns a new cgroup fingerprinter
|
||||
|
||||
@@ -2,12 +2,6 @@
|
||||
|
||||
package fingerprint
|
||||
|
||||
// FindCgroupMountpointDir is used to find the cgroup mount point on a Linux
|
||||
// system. Here it is a no-op implemtation
|
||||
func FindCgroupMountpointDir() (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (f *CGroupFingerprint) Fingerprint(*FingerprintRequest, *FingerprintResponse) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -4,28 +4,12 @@ package fingerprint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/opencontainers/runc/libcontainer/cgroups"
|
||||
)
|
||||
|
||||
const (
|
||||
cgroupAvailable = "available"
|
||||
)
|
||||
|
||||
// FindCgroupMountpointDir is used to find the cgroup mount point on a Linux
|
||||
// system.
|
||||
func FindCgroupMountpointDir() (string, error) {
|
||||
mount, err := cgroups.GetCgroupMounts(false)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
// It's okay if the mount point is not discovered
|
||||
if len(mount) == 0 {
|
||||
return "", nil
|
||||
}
|
||||
return mount[0].Mountpoint, nil
|
||||
}
|
||||
|
||||
// Fingerprint tries to find a valid cgroup mount point
|
||||
func (f *CGroupFingerprint) Fingerprint(req *FingerprintRequest, resp *FingerprintResponse) error {
|
||||
mount, err := f.mountPointDetector.MountPoint()
|
||||
|
||||
@@ -5,5 +5,9 @@ import (
|
||||
)
|
||||
|
||||
func (f *CPUFingerprint) deriveReservableCores(req *FingerprintRequest) ([]uint16, error) {
|
||||
return cgutil.GetCPUsFromCgroup(req.Config.CgroupParent)
|
||||
parent := req.Config.CgroupParent
|
||||
if parent == "" {
|
||||
parent = cgutil.DefaultCgroupParent
|
||||
}
|
||||
return cgutil.GetCPUsFromCgroup(parent)
|
||||
}
|
||||
|
||||
@@ -9,9 +9,10 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/nomad/client/lib/cgutil"
|
||||
|
||||
"github.com/hashicorp/consul-template/signals"
|
||||
hclog "github.com/hashicorp/go-hclog"
|
||||
"github.com/hashicorp/nomad/client/fingerprint"
|
||||
"github.com/hashicorp/nomad/drivers/shared/eventer"
|
||||
"github.com/hashicorp/nomad/drivers/shared/executor"
|
||||
"github.com/hashicorp/nomad/drivers/shared/resolvconf"
|
||||
@@ -313,7 +314,7 @@ func (d *Driver) buildFingerprint() *drivers.Fingerprint {
|
||||
return fp
|
||||
}
|
||||
|
||||
mount, err := fingerprint.FindCgroupMountpointDir()
|
||||
mount, err := cgutil.FindCgroupMountpointDir()
|
||||
if err != nil {
|
||||
fp.Health = drivers.HealthStateUnhealthy
|
||||
fp.HealthDescription = drivers.NoCgroupMountMessage
|
||||
|
||||
@@ -9,9 +9,10 @@ import (
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/nomad/client/lib/cgutil"
|
||||
|
||||
"github.com/hashicorp/consul-template/signals"
|
||||
hclog "github.com/hashicorp/go-hclog"
|
||||
"github.com/hashicorp/nomad/client/fingerprint"
|
||||
"github.com/hashicorp/nomad/drivers/shared/eventer"
|
||||
"github.com/hashicorp/nomad/drivers/shared/executor"
|
||||
"github.com/hashicorp/nomad/drivers/shared/resolvconf"
|
||||
@@ -281,7 +282,7 @@ func (d *Driver) buildFingerprint() *drivers.Fingerprint {
|
||||
return fp
|
||||
}
|
||||
|
||||
mount, err := fingerprint.FindCgroupMountpointDir()
|
||||
mount, err := cgutil.FindCgroupMountpointDir()
|
||||
if err != nil {
|
||||
fp.Health = drivers.HealthStateUnhealthy
|
||||
fp.HealthDescription = drivers.NoCgroupMountMessage
|
||||
|
||||
Reference in New Issue
Block a user