mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #18862 from dnephin/move_ulimit_opts_to_runconfig
Move ulimit opts to runconfig
This commit is contained in:
commit
3499e3a230
16 changed files with 59 additions and 104 deletions
|
@ -27,9 +27,9 @@ import (
|
|||
flag "github.com/docker/docker/pkg/mflag"
|
||||
"github.com/docker/docker/pkg/progress"
|
||||
"github.com/docker/docker/pkg/streamformatter"
|
||||
"github.com/docker/docker/pkg/ulimit"
|
||||
"github.com/docker/docker/pkg/urlutil"
|
||||
"github.com/docker/docker/reference"
|
||||
runconfigopts "github.com/docker/docker/runconfig/opts"
|
||||
"github.com/docker/docker/utils"
|
||||
"github.com/docker/go-units"
|
||||
)
|
||||
|
@ -62,8 +62,8 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
|
|||
cmd.Var(&flBuildArg, []string{"-build-arg"}, "Set build-time variables")
|
||||
isolation := cmd.String([]string{"-isolation"}, "", "Container isolation level")
|
||||
|
||||
ulimits := make(map[string]*ulimit.Ulimit)
|
||||
flUlimits := opts.NewUlimitOpt(&ulimits)
|
||||
ulimits := make(map[string]*units.Ulimit)
|
||||
flUlimits := runconfigopts.NewUlimitOpt(&ulimits)
|
||||
cmd.Var(flUlimits, []string{"-ulimit"}, "Ulimit options")
|
||||
|
||||
cmd.Require(flag.Exact, 1)
|
||||
|
|
|
@ -23,9 +23,9 @@ import (
|
|||
"github.com/docker/docker/pkg/ioutils"
|
||||
"github.com/docker/docker/pkg/progress"
|
||||
"github.com/docker/docker/pkg/streamformatter"
|
||||
"github.com/docker/docker/pkg/ulimit"
|
||||
"github.com/docker/docker/reference"
|
||||
"github.com/docker/docker/utils"
|
||||
"github.com/docker/go-units"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
|
@ -151,7 +151,7 @@ func (br *buildRouter) postBuild(ctx context.Context, w http.ResponseWriter, r *
|
|||
buildConfig.Isolation = i
|
||||
}
|
||||
|
||||
var buildUlimits = []*ulimit.Ulimit{}
|
||||
var buildUlimits = []*units.Ulimit{}
|
||||
ulimitsJSON := r.FormValue("ulimits")
|
||||
if ulimitsJSON != "" {
|
||||
if err := json.NewDecoder(strings.NewReader(ulimitsJSON)).Decode(&buildUlimits); err != nil {
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/pkg/ulimit"
|
||||
"github.com/docker/go-units"
|
||||
)
|
||||
|
||||
// ContainerAttachOptions holds parameters to attach to a container.
|
||||
|
@ -137,7 +137,7 @@ type ImageBuildOptions struct {
|
|||
CgroupParent string
|
||||
ShmSize string
|
||||
Dockerfile string
|
||||
Ulimits []*ulimit.Ulimit
|
||||
Ulimits []*units.Ulimit
|
||||
BuildArgs []string
|
||||
AuthConfigs map[string]AuthConfig
|
||||
Context io.Reader
|
||||
|
|
|
@ -5,8 +5,8 @@ import (
|
|||
|
||||
"github.com/docker/docker/api/types/blkiodev"
|
||||
"github.com/docker/docker/api/types/strslice"
|
||||
"github.com/docker/docker/pkg/ulimit"
|
||||
"github.com/docker/go-connections/nat"
|
||||
"github.com/docker/go-units"
|
||||
)
|
||||
|
||||
// NetworkMode represents the container network stack.
|
||||
|
@ -170,18 +170,18 @@ type Resources struct {
|
|||
BlkioDeviceWriteBps []*blkiodev.ThrottleDevice
|
||||
BlkioDeviceReadIOps []*blkiodev.ThrottleDevice
|
||||
BlkioDeviceWriteIOps []*blkiodev.ThrottleDevice
|
||||
CPUPeriod int64 `json:"CpuPeriod"` // CPU CFS (Completely Fair Scheduler) period
|
||||
CPUQuota int64 `json:"CpuQuota"` // CPU CFS (Completely Fair Scheduler) quota
|
||||
CpusetCpus string // CpusetCpus 0-2, 0,1
|
||||
CpusetMems string // CpusetMems 0-2, 0,1
|
||||
Devices []DeviceMapping // List of devices to map inside the container
|
||||
KernelMemory int64 // Kernel memory limit (in bytes)
|
||||
Memory int64 // Memory limit (in bytes)
|
||||
MemoryReservation int64 // Memory soft limit (in bytes)
|
||||
MemorySwap int64 // Total memory usage (memory + swap); set `-1` to disable swap
|
||||
MemorySwappiness *int64 // Tuning container memory swappiness behaviour
|
||||
OomKillDisable bool // Whether to disable OOM Killer or not
|
||||
Ulimits []*ulimit.Ulimit // List of ulimits to be set in the container
|
||||
CPUPeriod int64 `json:"CpuPeriod"` // CPU CFS (Completely Fair Scheduler) period
|
||||
CPUQuota int64 `json:"CpuQuota"` // CPU CFS (Completely Fair Scheduler) quota
|
||||
CpusetCpus string // CpusetCpus 0-2, 0,1
|
||||
CpusetMems string // CpusetMems 0-2, 0,1
|
||||
Devices []DeviceMapping // List of devices to map inside the container
|
||||
KernelMemory int64 // Kernel memory limit (in bytes)
|
||||
Memory int64 // Memory limit (in bytes)
|
||||
MemoryReservation int64 // Memory soft limit (in bytes)
|
||||
MemorySwap int64 // Total memory usage (memory + swap); set `-1` to disable swap
|
||||
MemorySwappiness *int64 // Tuning container memory swappiness behaviour
|
||||
OomKillDisable bool // Whether to disable OOM Killer or not
|
||||
Ulimits []*units.Ulimit // List of ulimits to be set in the container
|
||||
}
|
||||
|
||||
// HostConfig the non-portable Config structure of a container.
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
"github.com/docker/docker/builder"
|
||||
"github.com/docker/docker/builder/dockerfile/parser"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
"github.com/docker/docker/pkg/ulimit"
|
||||
"github.com/docker/go-units"
|
||||
)
|
||||
|
||||
var validCommitCommands = map[string]bool{
|
||||
|
@ -66,7 +66,7 @@ type Config struct {
|
|||
CPUSetCpus string
|
||||
CPUSetMems string
|
||||
CgroupParent string
|
||||
Ulimits []*ulimit.Ulimit
|
||||
Ulimits []*units.Ulimit
|
||||
}
|
||||
|
||||
// Builder is a Dockerfile builder
|
||||
|
|
|
@ -7,7 +7,8 @@ import (
|
|||
|
||||
"github.com/docker/docker/opts"
|
||||
flag "github.com/docker/docker/pkg/mflag"
|
||||
"github.com/docker/docker/pkg/ulimit"
|
||||
runconfigopts "github.com/docker/docker/runconfig/opts"
|
||||
"github.com/docker/go-units"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -27,7 +28,7 @@ type Config struct {
|
|||
EnableSelinuxSupport bool
|
||||
RemappedRoot string
|
||||
SocketGroup string
|
||||
Ulimits map[string]*ulimit.Ulimit
|
||||
Ulimits map[string]*units.Ulimit
|
||||
}
|
||||
|
||||
// bridgeConfig stores all the bridge driver specific
|
||||
|
@ -59,8 +60,8 @@ func (config *Config) InstallFlags(cmd *flag.FlagSet, usageFn func(string) strin
|
|||
// Then platform-specific install flags
|
||||
cmd.BoolVar(&config.EnableSelinuxSupport, []string{"-selinux-enabled"}, false, usageFn("Enable selinux support"))
|
||||
cmd.StringVar(&config.SocketGroup, []string{"G", "-group"}, "docker", usageFn("Group for the unix socket"))
|
||||
config.Ulimits = make(map[string]*ulimit.Ulimit)
|
||||
cmd.Var(opts.NewUlimitOpt(&config.Ulimits), []string{"-default-ulimit"}, usageFn("Set default ulimits for containers"))
|
||||
config.Ulimits = make(map[string]*units.Ulimit)
|
||||
cmd.Var(runconfigopts.NewUlimitOpt(&config.Ulimits), []string{"-default-ulimit"}, usageFn("Set default ulimits for containers"))
|
||||
cmd.BoolVar(&config.Bridge.EnableIPTables, []string{"#iptables", "-iptables"}, true, usageFn("Enable addition of iptables rules"))
|
||||
cmd.BoolVar(&config.Bridge.EnableIPForward, []string{"#ip-forward", "-ip-forward"}, true, usageFn("Enable net.ipv4.ip_forward"))
|
||||
cmd.BoolVar(&config.Bridge.EnableIPMasq, []string{"-ip-masq"}, true, usageFn("Enable IP masquerading"))
|
||||
|
|
|
@ -24,8 +24,8 @@ import (
|
|||
"github.com/docker/docker/pkg/idtools"
|
||||
"github.com/docker/docker/pkg/mount"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
"github.com/docker/docker/pkg/ulimit"
|
||||
"github.com/docker/docker/runconfig"
|
||||
"github.com/docker/go-units"
|
||||
"github.com/docker/libnetwork"
|
||||
"github.com/docker/libnetwork/netlabel"
|
||||
"github.com/docker/libnetwork/options"
|
||||
|
@ -146,11 +146,11 @@ func (daemon *Daemon) populateCommand(c *container.Container, env []string) erro
|
|||
|
||||
autoCreatedDevices := mergeDevices(configs.DefaultAutoCreatedDevices, userSpecifiedDevices)
|
||||
|
||||
var rlimits []*ulimit.Rlimit
|
||||
var rlimits []*units.Rlimit
|
||||
ulimits := c.HostConfig.Ulimits
|
||||
|
||||
// Merge ulimits with daemon defaults
|
||||
ulIdx := make(map[string]*ulimit.Ulimit)
|
||||
ulIdx := make(map[string]*units.Ulimit)
|
||||
for _, ul := range ulimits {
|
||||
ulIdx[ul.Name] = ul
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
"github.com/docker/docker/daemon/execdriver/native/template"
|
||||
"github.com/docker/docker/pkg/idtools"
|
||||
"github.com/docker/docker/pkg/mount"
|
||||
"github.com/docker/docker/pkg/ulimit"
|
||||
"github.com/docker/go-units"
|
||||
"github.com/opencontainers/runc/libcontainer"
|
||||
"github.com/opencontainers/runc/libcontainer/cgroups/fs"
|
||||
"github.com/opencontainers/runc/libcontainer/configs"
|
||||
|
@ -48,7 +48,7 @@ type Resources struct {
|
|||
CpusetCpus string `json:"cpuset_cpus"`
|
||||
CpusetMems string `json:"cpuset_mems"`
|
||||
CPUPeriod int64 `json:"cpu_period"`
|
||||
Rlimits []*ulimit.Rlimit `json:"rlimits"`
|
||||
Rlimits []*units.Rlimit `json:"rlimits"`
|
||||
OomKillDisable bool `json:"oom_kill_disable"`
|
||||
MemorySwappiness int64 `json:"memory_swappiness"`
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ clone git github.com/mistifyio/go-zfs v2.1.1
|
|||
clone git github.com/tchap/go-patricia v2.1.0
|
||||
clone git github.com/vdemeester/shakers 3c10293ce22b900c27acad7b28656196fcc2f73b
|
||||
clone git golang.org/x/net 47990a1ba55743e6ef1affd3a14e5bac8553615d https://github.com/golang/net.git
|
||||
clone git github.com/docker/go-units v0.2.0
|
||||
clone git github.com/docker/go-units 651fc226e7441360384da338d0fd37f2440ffbe3
|
||||
clone git github.com/docker/go-connections 4e42727957c146776e5de9cec8c39e4059ed9f20
|
||||
|
||||
#get libnetwork packages
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/docker/docker/pkg/integration/checker"
|
||||
"github.com/docker/docker/pkg/ulimit"
|
||||
"github.com/docker/go-units"
|
||||
"github.com/go-check/check"
|
||||
)
|
||||
|
||||
|
@ -33,7 +33,7 @@ func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *check.C) {
|
|||
CpusetMems string
|
||||
CPUShares int64
|
||||
CPUQuota int64
|
||||
Ulimits []*ulimit.Ulimit
|
||||
Ulimits []*units.Ulimit
|
||||
}
|
||||
|
||||
cfg, err := inspectFieldJSON(cID, "HostConfig")
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
package ulimit
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestParseValid(t *testing.T) {
|
||||
u1 := &Ulimit{"nofile", 1024, 512}
|
||||
if u2, _ := Parse("nofile=512:1024"); *u1 != *u2 {
|
||||
t.Fatalf("expected %q, but got %q", u1, u2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseInvalidLimitType(t *testing.T) {
|
||||
if _, err := Parse("notarealtype=1024:1024"); err == nil {
|
||||
t.Fatalf("expected error on invalid ulimit type")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseBadFormat(t *testing.T) {
|
||||
if _, err := Parse("nofile:1024:1024"); err == nil {
|
||||
t.Fatal("expected error on bad syntax")
|
||||
}
|
||||
|
||||
if _, err := Parse("nofile"); err == nil {
|
||||
t.Fatal("expected error on bad syntax")
|
||||
}
|
||||
|
||||
if _, err := Parse("nofile="); err == nil {
|
||||
t.Fatal("expected error on bad syntax")
|
||||
}
|
||||
if _, err := Parse("nofile=:"); err == nil {
|
||||
t.Fatal("expected error on bad syntax")
|
||||
}
|
||||
if _, err := Parse("nofile=:1024"); err == nil {
|
||||
t.Fatal("expected error on bad syntax")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseHardLessThanSoft(t *testing.T) {
|
||||
if _, err := Parse("nofile:1024:1"); err == nil {
|
||||
t.Fatal("expected error on hard limit less than soft limit")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseInvalidValueType(t *testing.T) {
|
||||
if _, err := Parse("nofile:asdf"); err == nil {
|
||||
t.Fatal("expected error on bad value type")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringOutput(t *testing.T) {
|
||||
u := &Ulimit{"nofile", 1024, 512}
|
||||
if s := u.String(); s != "nofile=512:1024" {
|
||||
t.Fatal("expected String to return nofile=512:1024, but got", s)
|
||||
}
|
||||
}
|
|
@ -3,25 +3,25 @@ package opts
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/docker/docker/pkg/ulimit"
|
||||
"github.com/docker/go-units"
|
||||
)
|
||||
|
||||
// UlimitOpt defines a map of Ulimits
|
||||
type UlimitOpt struct {
|
||||
values *map[string]*ulimit.Ulimit
|
||||
values *map[string]*units.Ulimit
|
||||
}
|
||||
|
||||
// NewUlimitOpt creates a new UlimitOpt
|
||||
func NewUlimitOpt(ref *map[string]*ulimit.Ulimit) *UlimitOpt {
|
||||
func NewUlimitOpt(ref *map[string]*units.Ulimit) *UlimitOpt {
|
||||
if ref == nil {
|
||||
ref = &map[string]*ulimit.Ulimit{}
|
||||
ref = &map[string]*units.Ulimit{}
|
||||
}
|
||||
return &UlimitOpt{ref}
|
||||
}
|
||||
|
||||
// Set validates a Ulimit and sets its name as a key in UlimitOpt
|
||||
func (o *UlimitOpt) Set(val string) error {
|
||||
l, err := ulimit.Parse(val)
|
||||
l, err := units.ParseUlimit(val)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -42,8 +42,8 @@ func (o *UlimitOpt) String() string {
|
|||
}
|
||||
|
||||
// GetList returns a slice of pointers to Ulimits.
|
||||
func (o *UlimitOpt) GetList() []*ulimit.Ulimit {
|
||||
var ulimits []*ulimit.Ulimit
|
||||
func (o *UlimitOpt) GetList() []*units.Ulimit {
|
||||
var ulimits []*units.Ulimit
|
||||
for _, v := range *o.values {
|
||||
ulimits = append(ulimits, v)
|
||||
}
|
|
@ -3,11 +3,11 @@ package opts
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/pkg/ulimit"
|
||||
"github.com/docker/go-units"
|
||||
)
|
||||
|
||||
func TestUlimitOpt(t *testing.T) {
|
||||
ulimitMap := map[string]*ulimit.Ulimit{
|
||||
ulimitMap := map[string]*units.Ulimit{
|
||||
"nofile": {"nofile", 1024, 512},
|
||||
}
|
||||
|
|
@ -64,7 +64,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*container.Config, *container.Host
|
|||
flLabels = opts.NewListOpts(opts.ValidateEnv)
|
||||
flDevices = opts.NewListOpts(ValidateDevice)
|
||||
|
||||
flUlimits = opts.NewUlimitOpt(nil)
|
||||
flUlimits = runconfigopts.NewUlimitOpt(nil)
|
||||
|
||||
flPublish = opts.NewListOpts(nil)
|
||||
flExpose = opts.NewListOpts(nil)
|
||||
|
|
11
vendor/src/github.com/docker/go-units/circle.yml
vendored
Normal file
11
vendor/src/github.com/docker/go-units/circle.yml
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
dependencies:
|
||||
post:
|
||||
# install golint
|
||||
- go get github.com/golang/lint/golint
|
||||
|
||||
test:
|
||||
pre:
|
||||
# run analysis before tests
|
||||
- go vet ./...
|
||||
- test -z "$(golint ./... | tee /dev/stderr)"
|
||||
- test -z "$(gofmt -s -l . | tee /dev/stderr)"
|
|
@ -1,6 +1,4 @@
|
|||
// Package ulimit provides structure and helper function to parse and represent
|
||||
// resource limits (Rlimit and Ulimit, its human friendly version).
|
||||
package ulimit
|
||||
package units
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -64,8 +62,8 @@ var ulimitNameMapping = map[string]int{
|
|||
"stack": rlimitStack,
|
||||
}
|
||||
|
||||
// Parse parses and returns a Ulimit from the specified string.
|
||||
func Parse(val string) (*Ulimit, error) {
|
||||
// ParseUlimit parses and returns a Ulimit from the specified string.
|
||||
func ParseUlimit(val string) (*Ulimit, error) {
|
||||
parts := strings.SplitN(val, "=", 2)
|
||||
if len(parts) != 2 {
|
||||
return nil, fmt.Errorf("invalid ulimit argument: %s", val)
|
Loading…
Add table
Reference in a new issue