Commit ea9accf4 authored by Seth Hoenig's avatar Seth Hoenig
Browse files

wip build on darwin

parent ef5f97a4
Branches unavailable
No related merge requests found
Showing with 56 additions and 23 deletions
+56 -23
......@@ -6,7 +6,6 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/nomad/helper/uuid"
......@@ -47,17 +46,6 @@ func GetCPUsFromCgroup(group string) ([]uint16, error) {
return getCPUsFromCgroupV1(getParentV1(group))
}
// SplitPath determines the parent and cgroup from p.
// p must contain at least 2 elements (parent + cgroup).
//
// Handles the cgroup root if present.
func SplitPath(p string) (string, string) {
p = strings.TrimPrefix(p, CgroupRoot)
p = strings.Trim(p, "/")
parts := strings.Split(p, string(os.PathSeparator))
return parts[0], "/" + filepath.Join(parts[1:]...)
}
// CgroupScope returns the name of the scope for Nomad's managed cgroups for
// the given allocID and task.
//
......
//go:build linux
package cgutil
import (
......
//go:build !linux
// +build !linux
package cgutil
......
......@@ -3,11 +3,20 @@ package cgutil
import (
"context"
"fmt"
"os"
"path/filepath"
"strings"
"github.com/hashicorp/nomad/lib/cpuset"
"github.com/hashicorp/nomad/nomad/structs"
)
const (
// CgroupRoot is hard-coded in the cgroups specification.
// It only applies to linux but helpers have references to it in driver(s).
CgroupRoot = "/sys/fs/cgroup"
)
// CpusetManager is used to setup cpuset cgroups for each task.
type CpusetManager interface {
// Init should be called with the initial set of reservable cores before any
......@@ -62,3 +71,14 @@ func makeID(allocID, task string) string {
func makeScope(id string) string {
return id + ".scope"
}
// SplitPath determines the parent and cgroup from p.
// p must contain at least 2 elements (parent + cgroup).
//
// Handles the cgroup root if present.
func SplitPath(p string) (string, string) {
p = strings.TrimPrefix(p, CgroupRoot)
p = strings.Trim(p, "/")
parts := strings.Split(p, string(os.PathSeparator))
return parts[0], "/" + filepath.Join(parts[1:]...)
}
......@@ -20,9 +20,6 @@ import (
)
const (
// CgroupRoot is hard-coded in the cgroups specification.
CgroupRoot = "/sys/fs/cgroup"
// CreationPID is a special PID in libcontainer used to denote a cgroup
// should be created, but with no process added.
CreationPID = -1
......
......@@ -704,7 +704,7 @@ func TestConfig_DriverConfig_PullActivityTimeout(t *testing.T) {
func TestConfig_DriverConfig_AllowRuntimes(t *testing.T) {
ci.Parallel(t)
cases := []struct {
name string
config string
......
......@@ -31,7 +31,6 @@ import (
"github.com/hashicorp/nomad/plugins/base"
"github.com/hashicorp/nomad/plugins/drivers"
pstructs "github.com/hashicorp/nomad/plugins/shared/structs"
"github.com/opencontainers/runc/libcontainer/cgroups"
"github.com/ryanuber/go-glob"
)
......@@ -125,7 +124,7 @@ type Driver struct {
detectedLock sync.RWMutex
danglingReconciler *containerReconciler
cpusetFixer *cpusetFixer
cpusetFixer CpusetFixer
}
// NewDockerDriver returns a docker implementation of a driver plugin
......@@ -1207,9 +1206,10 @@ func (d *Driver) createContainerConfig(task *drivers.TaskConfig, driverConfig *T
config.Env = task.EnvList()
containerName := fmt.Sprintf("%s-%s", strings.ReplaceAll(task.Name, "/", "_"), task.AllocID)
if cgroups.IsCgroup2UnifiedMode() {
containerName = fmt.Sprintf("%s.%s.scope", task.AllocID, task.Name)
}
// todo: remove
//if cgroups.IsCgroup2UnifiedMode() {
// containerName = fmt.Sprintf("%s.%s.scope", task.AllocID, task.Name)
//}
logger.Info("setting container name", "container_name", containerName)
var networkingConfig *docker.NetworkingConfig
......
//go:build linux
package docker
import (
......@@ -16,6 +18,10 @@ const (
cpusetReconcileInterval = 1 * time.Second
)
type CpusetFixer interface {
Start()
}
// cpusetFixer adjusts the cpuset.cpus cgroup value to the assigned value by Nomad.
//
// Due to Docker not allowing the configuration of the full cgroup path, we must
......@@ -35,7 +41,7 @@ type cpusetFixer struct {
tasks func() map[coordinate]struct{}
}
func newCpusetFixer(d *Driver) *cpusetFixer {
func newCpusetFixer(d *Driver) CpusetFixer {
return &cpusetFixer{
interval: cpusetReconcileInterval,
ctx: d.ctx,
......
//go:build !linux
package docker
type CpusetFixer interface {
Start()
}
func newCpusetFixer(*Driver) CpusetFixer {
return new(noop)
}
type noop struct {
// empty
}
func (*noop) Start() {
// empty
}
//go:build linux
package docker
import (
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment