Skip to content

Commit

Permalink
Allow for OomScoreAdj
Browse files Browse the repository at this point in the history
Signed-off-by: plaurent <[email protected]>
  • Loading branch information
psaintlaurent committed Jun 21, 2024
1 parent 482bf86 commit e174fe5
Show file tree
Hide file tree
Showing 65 changed files with 1,390 additions and 590 deletions.
1 change: 1 addition & 0 deletions cli/command/service/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func newCreateCommand(dockerCli command.Cli) *cobra.Command {
flags.SetAnnotation(flagSysCtl, "version", []string{"1.40"})
flags.Var(&opts.ulimits, flagUlimit, "Ulimit options")
flags.SetAnnotation(flagUlimit, "version", []string{"1.41"})
flags.Var(&opts.oomScoreAdj, flagOomScoreAdj, "oom score adjustment (-1000 to 1000)")

flags.Var(cliopts.NewListOptsRef(&opts.resources.resGenericResources, ValidateSingleGenericResource), "generic-resource", "User defined resources")
flags.SetAnnotation(flagHostAdd, "version", []string{"1.32"})
Expand Down
4 changes: 4 additions & 0 deletions cli/command/service/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ type serviceOptions struct {
capAdd opts.ListOpts
capDrop opts.ListOpts
ulimits opts.UlimitOpt
oomScoreAdj opts.OomScoreAdj

resources resourceOptions
stopGrace opts.DurationOpt
Expand Down Expand Up @@ -575,6 +576,7 @@ func newServiceOptions() *serviceOptions {
capAdd: opts.NewListOpts(nil),
capDrop: opts.NewListOpts(nil),
ulimits: *opts.NewUlimitOpt(nil),
oomScoreAdj: opts.OomScoreAdj(0),
}
}

Expand Down Expand Up @@ -747,6 +749,7 @@ func (options *serviceOptions) ToService(ctx context.Context, apiClient client.N
CapabilityAdd: capAdd,
CapabilityDrop: capDrop,
Ulimits: options.ulimits.GetList(),
OomScoreAdj: options.oomScoreAdj.Value(),
},
Networks: networks,
Resources: resources,
Expand Down Expand Up @@ -1043,6 +1046,7 @@ const (
flagUlimit = "ulimit"
flagUlimitAdd = "ulimit-add"
flagUlimitRemove = "ulimit-rm"
flagOomScoreAdj = "oom-score-adj"
)

func validateAPIVersion(c swarm.ServiceSpec, serverAPIVersion string) error {
Expand Down
5 changes: 5 additions & 0 deletions cli/command/service/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func newUpdateCommand(dockerCli command.Cli) *cobra.Command {
flags.SetAnnotation(flagUlimitAdd, "version", []string{"1.41"})
flags.Var(newListOptsVar(), flagUlimitRemove, "Remove a ulimit option")
flags.SetAnnotation(flagUlimitRemove, "version", []string{"1.41"})
flags.Var(&options.oomScoreAdj, flagOomScoreAdj, "oom score adjustment (-1000 to 1000)")

// Add needs parsing, Remove only needs the key
flags.Var(newListOptsVar(), flagGenericResourcesRemove, "Remove a Generic resource")
Expand Down Expand Up @@ -368,6 +369,10 @@ func updateService(ctx context.Context, apiClient client.NetworkAPIClient, flags
updateInt64Value(flagReserveMemory, &task.Resources.Reservations.MemoryBytes)
}

if anyChanged(flags, flagOomScoreAdj) {
updateInt64(flagOomScoreAdj, &task.ContainerSpec.OomScoreAdj)
}

if err := addGenericResources(flags, task); err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions cli/compose/convert/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func Service(
CapabilityAdd: capAdd,
CapabilityDrop: capDrop,
Ulimits: convertUlimits(service.Ulimits),
OomScoreAdj: service.OomScoreAdj,
},
LogDriver: logDriver,
Resources: resources,
Expand Down
1 change: 1 addition & 0 deletions cli/compose/loader/interpolate.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var interpolateTypeCastMapping = map[interp.Path]interp.Cast{
servicePath("ulimits", interp.PathMatchAll): toInt,
servicePath("ulimits", interp.PathMatchAll, "hard"): toInt,
servicePath("ulimits", interp.PathMatchAll, "soft"): toInt,
servicePath("oom_score_adj"): toInt,
servicePath("privileged"): toBoolean,
servicePath("read_only"): toBoolean,
servicePath("stdin_open"): toBoolean,
Expand Down
1 change: 1 addition & 0 deletions cli/compose/schema/data/config_schema_v3.13.json
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@
}
}
},
"oom_score_adj": {"type": "integer"},
"user": {"type": "string"},
"userns_mode": {"type": "string"},
"volumes": {
Expand Down
1 change: 1 addition & 0 deletions cli/compose/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ type ServiceConfig struct {
Tty bool `mapstructure:"tty" yaml:"tty,omitempty" json:"tty,omitempty"`
Ulimits map[string]*UlimitsConfig `yaml:",omitempty" json:"ulimits,omitempty"`
User string `yaml:",omitempty" json:"user,omitempty"`
OomScoreAdj int64 `yaml:",omitempty" json:"oom_score_adj,omitempty"`
UserNSMode string `mapstructure:"userns_mode" yaml:"userns_mode,omitempty" json:"userns_mode,omitempty"`
Volumes []ServiceVolumeConfig `yaml:",omitempty" json:"volumes,omitempty"`
WorkingDir string `mapstructure:"working_dir" yaml:"working_dir,omitempty" json:"working_dir,omitempty"`
Expand Down
19 changes: 19 additions & 0 deletions opts/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net"
"path"
"regexp"
"strconv"
"strings"

"github.com/docker/docker/api/types/filters"
Expand Down Expand Up @@ -515,3 +516,21 @@ func (m *MemSwapBytes) UnmarshalJSON(s []byte) error {
b := MemBytes(*m)
return b.UnmarshalJSON(s)
}

type OomScoreAdj int64

func (o *OomScoreAdj) Type() string { return "int64" }

func (o *OomScoreAdj) Value() int64 { return int64(*o) }

func (o *OomScoreAdj) String() string {
return strconv.FormatInt(int64(*o), 10)
}

func (o *OomScoreAdj) Set(value string) error {

var conv int64
conv, _ = strconv.ParseInt(value, 10, 64)
*o = OomScoreAdj(conv)
return nil
}
4 changes: 2 additions & 2 deletions vendor.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/creack/pty v1.1.21
github.com/distribution/reference v0.5.0
github.com/docker/distribution v2.8.3+incompatible
github.com/docker/docker v26.1.1-0.20240606182029-00f18ef7a455+incompatible // master (v27.0.0-dev)
github.com/docker/docker v27.0.1-rc.1.0.20240621110831-6da604aa6a74+incompatible
github.com/docker/docker-credential-helpers v0.8.2
github.com/docker/go-connections v0.5.0
github.com/docker/go-units v0.5.0
Expand All @@ -23,7 +23,7 @@ require (
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/mattn/go-runewidth v0.0.15
github.com/moby/patternmatcher v0.6.0
github.com/moby/swarmkit/v2 v2.0.0-20240415162501-c1c857e2dca1
github.com/moby/swarmkit/v2 v2.0.0-20240611172349-ea1a7cec35cb
github.com/moby/sys/sequential v0.5.0
github.com/moby/sys/signal v0.7.0
github.com/moby/term v0.5.0
Expand Down
8 changes: 4 additions & 4 deletions vendor.sum
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5
github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk=
github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker v26.1.1-0.20240606182029-00f18ef7a455+incompatible h1:6OR7f7LuvJU27W400ctN0mxeAGDnPc0Fg2IGQhltKb0=
github.com/docker/docker v26.1.1-0.20240606182029-00f18ef7a455+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker v27.0.1-rc.1.0.20240621110831-6da604aa6a74+incompatible h1:AaVEcuJZ91YFAjfHHxy/LQsOYzoqWzc5JyYYG290EiY=
github.com/docker/docker v27.0.1-rc.1.0.20240621110831-6da604aa6a74+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker-credential-helpers v0.8.2 h1:bX3YxiGzFP5sOXWc3bTPEXdEaZSeVMrFgOr3T+zrFAo=
github.com/docker/docker-credential-helpers v0.8.2/go.mod h1:P3ci7E3lwkZg6XiHdRKft1KckHiO9a2rNtyFbZ/ry9M=
github.com/docker/go v1.5.1-1.0.20160303222718-d30aec9fd63c h1:lzqkGL9b3znc+ZUgi7FlLnqjQhcXxkNM/quxIjBVMD0=
Expand Down Expand Up @@ -179,8 +179,8 @@ github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3N
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
github.com/moby/patternmatcher v0.6.0 h1:GmP9lR19aU5GqSSFko+5pRqHi+Ohk1O69aFiKkVGiPk=
github.com/moby/patternmatcher v0.6.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc=
github.com/moby/swarmkit/v2 v2.0.0-20240415162501-c1c857e2dca1 h1:F3L5Rx1jDTbUn/2U9Kb6tsNAl4MhQ+cdTiidA/qAiEA=
github.com/moby/swarmkit/v2 v2.0.0-20240415162501-c1c857e2dca1/go.mod h1:kNy225f/gWAnF8wPftteMc5nbAHhrH+HUfvyjmhFjeQ=
github.com/moby/swarmkit/v2 v2.0.0-20240611172349-ea1a7cec35cb h1:1UTTg2EgO3nuyV03wREDzldqqePzQ4+0a5G1C1y1bIo=
github.com/moby/swarmkit/v2 v2.0.0-20240611172349-ea1a7cec35cb/go.mod h1:kNy225f/gWAnF8wPftteMc5nbAHhrH+HUfvyjmhFjeQ=
github.com/moby/sys/sequential v0.5.0 h1:OPvI35Lzn9K04PBbCLW0g4LcFAJgHsvXsRyewg5lXtc=
github.com/moby/sys/sequential v0.5.0/go.mod h1:tH2cOOs5V9MlPiXcQzRC+eEyab644PWKGRYaaV5ZZlo=
github.com/moby/sys/signal v0.7.0 h1:25RW3d5TnQEoKvRbEKUGay6DCQ46IxAVTT9CUMgmsSI=
Expand Down
20 changes: 19 additions & 1 deletion vendor/github.com/docker/docker/AUTHORS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e174fe5

Please sign in to comment.