mirror of https://github.com/docker/docs.git
Fix compile and unit test errors after merge
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
parent
eab56ac007
commit
2d270c4f06
|
@ -49,6 +49,9 @@ func rawApply(c *Cgroup, pid int) (ActiveCgroup, error) {
|
||||||
if err := raw.setupCpu(c, pid); err != nil {
|
if err := raw.setupCpu(c, pid); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if err := raw.setupCpuset(c, pid); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return raw, nil
|
return raw, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,6 +173,25 @@ func (raw *rawCgroup) setupCpu(c *Cgroup, pid int) (err error) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (raw *rawCgroup) setupCpuset(c *Cgroup, pid int) (err error) {
|
||||||
|
if c.CpusetCpus != "" {
|
||||||
|
dir, err := raw.join("cpuset", pid)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
os.RemoveAll(dir)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
if err := writeFile(dir, "cpuset.cpus", c.CpusetCpus); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (raw *rawCgroup) Cleanup() error {
|
func (raw *rawCgroup) Cleanup() error {
|
||||||
get := func(subsystem string) string {
|
get := func(subsystem string) string {
|
||||||
path, _ := raw.path(subsystem)
|
path, _ := raw.path(subsystem)
|
||||||
|
@ -180,6 +202,7 @@ func (raw *rawCgroup) Cleanup() error {
|
||||||
get("memory"),
|
get("memory"),
|
||||||
get("devices"),
|
get("devices"),
|
||||||
get("cpu"),
|
get("cpu"),
|
||||||
|
get("cpuset"),
|
||||||
} {
|
} {
|
||||||
if path != "" {
|
if path != "" {
|
||||||
os.RemoveAll(path)
|
os.RemoveAll(path)
|
||||||
|
|
|
@ -101,22 +101,3 @@ func (c *Cgroup) Apply(pid int) (ActiveCgroup, error) {
|
||||||
return rawApply(c, pid)
|
return rawApply(c, pid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cgroup) setupCpuset(cgroupRoot string, pid int) (err error) {
|
|
||||||
if c.CpusetCpus != "" {
|
|
||||||
dir, err := c.Join(cgroupRoot, "cpuset", pid)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer func() {
|
|
||||||
if err != nil {
|
|
||||||
os.RemoveAll(dir)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
if err := writeFile(dir, "cpuset.cpus", c.CpusetCpus); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
|
@ -17,11 +17,6 @@ type HostConfig struct {
|
||||||
DriverOptions map[string][]string
|
DriverOptions map[string][]string
|
||||||
}
|
}
|
||||||
|
|
||||||
type KeyValuePair struct {
|
|
||||||
Key string
|
|
||||||
Value string
|
|
||||||
}
|
|
||||||
|
|
||||||
func ContainerHostConfigFromJob(job *engine.Job) *HostConfig {
|
func ContainerHostConfigFromJob(job *engine.Job) *HostConfig {
|
||||||
hostConfig := &HostConfig{
|
hostConfig := &HostConfig{
|
||||||
ContainerIDFile: job.Getenv("ContainerIDFile"),
|
ContainerIDFile: job.Getenv("ContainerIDFile"),
|
||||||
|
|
|
@ -4,10 +4,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dotcloud/docker/nat"
|
"github.com/dotcloud/docker/nat"
|
||||||
"github.com/dotcloud/docker/opts"
|
"github.com/dotcloud/docker/opts"
|
||||||
"github.com/dotcloud/docker/pkg/label"
|
|
||||||
flag "github.com/dotcloud/docker/pkg/mflag"
|
flag "github.com/dotcloud/docker/pkg/mflag"
|
||||||
"github.com/dotcloud/docker/pkg/sysinfo"
|
"github.com/dotcloud/docker/pkg/sysinfo"
|
||||||
"github.com/dotcloud/docker/runtime/execdriver"
|
|
||||||
"github.com/dotcloud/docker/utils"
|
"github.com/dotcloud/docker/utils"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"path"
|
"path"
|
||||||
|
@ -34,10 +32,6 @@ func ParseSubcommand(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseRun(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Config, *HostConfig, *flag.FlagSet, error) {
|
func parseRun(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Config, *HostConfig, *flag.FlagSet, error) {
|
||||||
var (
|
|
||||||
processLabel string
|
|
||||||
mountLabel string
|
|
||||||
)
|
|
||||||
var (
|
var (
|
||||||
// FIXME: use utils.ListOpts for attach and volumes?
|
// FIXME: use utils.ListOpts for attach and volumes?
|
||||||
flAttach = opts.NewListOpts(opts.ValidateAttach)
|
flAttach = opts.NewListOpts(opts.ValidateAttach)
|
||||||
|
@ -67,7 +61,6 @@ func parseRun(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Conf
|
||||||
flUser = cmd.String([]string{"u", "-user"}, "", "Username or UID")
|
flUser = cmd.String([]string{"u", "-user"}, "", "Username or UID")
|
||||||
flWorkingDir = cmd.String([]string{"w", "-workdir"}, "", "Working directory inside the container")
|
flWorkingDir = cmd.String([]string{"w", "-workdir"}, "", "Working directory inside the container")
|
||||||
flCpuShares = cmd.Int64([]string{"c", "-cpu-shares"}, 0, "CPU shares (relative weight)")
|
flCpuShares = cmd.Int64([]string{"c", "-cpu-shares"}, 0, "CPU shares (relative weight)")
|
||||||
flLabelOptions = cmd.String([]string{"Z", "-label"}, "", "Options to pass to underlying labeling system")
|
|
||||||
|
|
||||||
// For documentation purpose
|
// For documentation purpose
|
||||||
_ = cmd.Bool([]string{"#sig-proxy", "-sig-proxy"}, true, "Proxify all received signal to the process (even in non-tty mode)")
|
_ = cmd.Bool([]string{"#sig-proxy", "-sig-proxy"}, true, "Proxify all received signal to the process (even in non-tty mode)")
|
||||||
|
@ -159,15 +152,6 @@ func parseRun(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Conf
|
||||||
entrypoint = []string{*flEntrypoint}
|
entrypoint = []string{*flEntrypoint}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !*flPrivileged {
|
|
||||||
pLabel, mLabel, e := label.GenLabels(*flLabelOptions)
|
|
||||||
if e != nil {
|
|
||||||
return nil, nil, cmd, fmt.Errorf("Invalid security labels : %s", e)
|
|
||||||
}
|
|
||||||
processLabel = pLabel
|
|
||||||
mountLabel = mLabel
|
|
||||||
}
|
|
||||||
|
|
||||||
lxcConf, err := parseKeyValueOpts(flLxcOpts)
|
lxcConf, err := parseKeyValueOpts(flLxcOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, cmd, err
|
return nil, nil, cmd, err
|
||||||
|
@ -222,10 +206,6 @@ func parseRun(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Conf
|
||||||
VolumesFrom: strings.Join(flVolumesFrom.GetAll(), ","),
|
VolumesFrom: strings.Join(flVolumesFrom.GetAll(), ","),
|
||||||
Entrypoint: entrypoint,
|
Entrypoint: entrypoint,
|
||||||
WorkingDir: *flWorkingDir,
|
WorkingDir: *flWorkingDir,
|
||||||
Context: execdriver.Context{
|
|
||||||
"mount_label": mountLabel,
|
|
||||||
"process_label": processLabel,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
driverOptions, err := parseDriverOpts(flDriverOpts)
|
driverOptions, err := parseDriverOpts(flDriverOpts)
|
||||||
|
@ -233,11 +213,6 @@ func parseRun(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Conf
|
||||||
return nil, nil, cmd, err
|
return nil, nil, cmd, err
|
||||||
}
|
}
|
||||||
|
|
||||||
pluginOptions, err := parseDriverOpts(flDriverOpts)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, cmd, err
|
|
||||||
}
|
|
||||||
|
|
||||||
hostConfig := &HostConfig{
|
hostConfig := &HostConfig{
|
||||||
Binds: binds,
|
Binds: binds,
|
||||||
ContainerIDFile: *flContainerIDFile,
|
ContainerIDFile: *flContainerIDFile,
|
||||||
|
@ -289,20 +264,3 @@ func parseKeyValueOpts(opts opts.ListOpts) ([]utils.KeyValuePair, error) {
|
||||||
}
|
}
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// options will come in the format of name.type=value
|
|
||||||
func parseDriverOpts(opts opts.ListOpts) (map[string][]string, error) {
|
|
||||||
out := make(map[string][]string, len(opts.GetAll()))
|
|
||||||
for _, o := range opts.GetAll() {
|
|
||||||
parts := strings.SplitN(o, ".", 2)
|
|
||||||
if len(parts) < 2 {
|
|
||||||
return nil, fmt.Errorf("invalid opt format %s", o)
|
|
||||||
}
|
|
||||||
values, exists := out[parts[0]]
|
|
||||||
if !exists {
|
|
||||||
values = []string{}
|
|
||||||
}
|
|
||||||
out[parts[0]] = append(values, parts[1])
|
|
||||||
}
|
|
||||||
return out, nil
|
|
||||||
}
|
|
||||||
|
|
|
@ -404,7 +404,6 @@ func populateCommand(c *Container) {
|
||||||
User: c.Config.User,
|
User: c.Config.User,
|
||||||
Config: driverConfig,
|
Config: driverConfig,
|
||||||
Resources: resources,
|
Resources: resources,
|
||||||
Context: c.Config.Context,
|
|
||||||
}
|
}
|
||||||
c.command.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
|
c.command.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,9 +30,9 @@ lxc.pts = 1024
|
||||||
|
|
||||||
# disable the main console
|
# disable the main console
|
||||||
lxc.console = none
|
lxc.console = none
|
||||||
{{if getProcessLabel .Context}}
|
{{if getProcessLabel .Config}}
|
||||||
lxc.se_context = {{ getProcessLabel .Context}}
|
lxc.se_context = {{ getProcessLabel .Config}}
|
||||||
{{$MOUNTLABEL := getMountLabel .Context}}
|
{{$MOUNTLABEL := getMountLabel .Config}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
# no controlling tty at all
|
# no controlling tty at all
|
||||||
|
@ -147,12 +147,23 @@ func getMemorySwap(v *execdriver.Resources) int64 {
|
||||||
return v.Memory * 2
|
return v.Memory * 2
|
||||||
}
|
}
|
||||||
|
|
||||||
func getProcessLabel(c execdriver.Context) string {
|
func getProcessLabel(c map[string][]string) string {
|
||||||
return c["process_label"]
|
return getLabel(c, "process")
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMountLabel(c execdriver.Context) string {
|
func getMountLabel(c map[string][]string) string {
|
||||||
return c["mount_label"]
|
return getLabel(c, "mount")
|
||||||
|
}
|
||||||
|
|
||||||
|
func getLabel(c map[string][]string, name string) string {
|
||||||
|
label := c["label"]
|
||||||
|
for _, l := range label {
|
||||||
|
parts := strings.SplitN(l, "=", 2)
|
||||||
|
if parts[0] == name {
|
||||||
|
return parts[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
|
@ -2,13 +2,14 @@ package runtime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/dotcloud/docker/runconfig"
|
"github.com/dotcloud/docker/runconfig"
|
||||||
|
"github.com/dotcloud/docker/utils"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMergeLxcConfig(t *testing.T) {
|
func TestMergeLxcConfig(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
hostConfig = &runconfig.HostConfig{
|
hostConfig = &runconfig.HostConfig{
|
||||||
LxcConf: []runconfig.KeyValuePair{
|
LxcConf: []utils.KeyValuePair{
|
||||||
{Key: "lxc.cgroups.cpuset", Value: "1,2"},
|
{Key: "lxc.cgroups.cpuset", Value: "1,2"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue