From aa2c2cd906211ef0358caab4edae8bd5836a01e0 Mon Sep 17 00:00:00 2001 From: plaurent Date: Mon, 8 Jul 2024 13:39:15 -0400 Subject: [PATCH] Allow for OomScoreAdj Signed-off-by: plaurent --- cli/command/service/create.go | 2 ++ cli/command/service/opts.go | 3 +++ cli/command/service/update.go | 6 ++++++ cli/compose/convert/service.go | 1 + cli/compose/loader/interpolate.go | 1 + cli/compose/schema/data/config_schema_v3.13.json | 1 + cli/compose/types/types.go | 1 + docs/reference/commandline/service_create.md | 1 + docs/reference/commandline/service_update.md | 1 + 9 files changed, 17 insertions(+) diff --git a/cli/command/service/create.go b/cli/command/service/create.go index 6e49558609a1..b1bed6619594 100644 --- a/cli/command/service/create.go +++ b/cli/command/service/create.go @@ -68,6 +68,8 @@ 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.Int64Var(&opts.oomScoreAdj, flagOomScoreAdj, 0, "Tune host's OOM preferences (-1000 to 1000) ") + flags.SetAnnotation(flagOomScoreAdj, "version", []string{"1.46"}) flags.Var(cliopts.NewListOptsRef(&opts.resources.resGenericResources, ValidateSingleGenericResource), "generic-resource", "User defined resources") flags.SetAnnotation(flagHostAdd, "version", []string{"1.32"}) diff --git a/cli/command/service/opts.go b/cli/command/service/opts.go index c0a30674ec9e..79f545445a03 100644 --- a/cli/command/service/opts.go +++ b/cli/command/service/opts.go @@ -529,6 +529,7 @@ type serviceOptions struct { capAdd opts.ListOpts capDrop opts.ListOpts ulimits opts.UlimitOpt + oomScoreAdj int64 resources resourceOptions stopGrace opts.DurationOpt @@ -747,6 +748,7 @@ func (options *serviceOptions) ToService(ctx context.Context, apiClient client.N CapabilityAdd: capAdd, CapabilityDrop: capDrop, Ulimits: options.ulimits.GetList(), + OomScoreAdj: options.oomScoreAdj, }, Networks: networks, Resources: resources, @@ -1043,6 +1045,7 @@ const ( flagUlimit = "ulimit" flagUlimitAdd = "ulimit-add" flagUlimitRemove = "ulimit-rm" + flagOomScoreAdj = "oom-score-adj" ) func validateAPIVersion(c swarm.ServiceSpec, serverAPIVersion string) error { diff --git a/cli/command/service/update.go b/cli/command/service/update.go index e02e19ccc842..d8f89185aeec 100644 --- a/cli/command/service/update.go +++ b/cli/command/service/update.go @@ -108,6 +108,8 @@ 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.Int64Var(&options.oomScoreAdj, flagOomScoreAdj, 0, "Tune host's OOM preferences (-1000 to 1000) ") + flags.SetAnnotation(flagOomScoreAdj, "version", []string{"1.46"}) // Add needs parsing, Remove only needs the key flags.Var(newListOptsVar(), flagGenericResourcesRemove, "Remove a Generic resource") @@ -367,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 } diff --git a/cli/compose/convert/service.go b/cli/compose/convert/service.go index 62cadf57e7e9..44b6de1415c6 100644 --- a/cli/compose/convert/service.go +++ b/cli/compose/convert/service.go @@ -148,6 +148,7 @@ func Service( CapabilityAdd: capAdd, CapabilityDrop: capDrop, Ulimits: convertUlimits(service.Ulimits), + OomScoreAdj: service.OomScoreAdj, }, LogDriver: logDriver, Resources: resources, diff --git a/cli/compose/loader/interpolate.go b/cli/compose/loader/interpolate.go index 445cdeb54786..68d3b8c32945 100644 --- a/cli/compose/loader/interpolate.go +++ b/cli/compose/loader/interpolate.go @@ -29,6 +29,7 @@ var interpolateTypeCastMapping = map[interp.Path]interp.Cast{ servicePath("ulimits", interp.PathMatchAll, "hard"): toInt, servicePath("ulimits", interp.PathMatchAll, "soft"): toInt, servicePath("privileged"): toBoolean, + servicePath("oom_score_adj"): toInt, servicePath("read_only"): toBoolean, servicePath("stdin_open"): toBoolean, servicePath("tty"): toBoolean, diff --git a/cli/compose/schema/data/config_schema_v3.13.json b/cli/compose/schema/data/config_schema_v3.13.json index 0a85b3e6c508..8daa8892d625 100644 --- a/cli/compose/schema/data/config_schema_v3.13.json +++ b/cli/compose/schema/data/config_schema_v3.13.json @@ -287,6 +287,7 @@ } } }, + "oom_score_adj": {"type": "integer"}, "user": {"type": "string"}, "userns_mode": {"type": "string"}, "volumes": { diff --git a/cli/compose/types/types.go b/cli/compose/types/types.go index 16417f328aaa..2b929f4d7f36 100644 --- a/cli/compose/types/types.go +++ b/cli/compose/types/types.go @@ -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"` diff --git a/docs/reference/commandline/service_create.md b/docs/reference/commandline/service_create.md index db821e2afe41..25b9048b26aa 100644 --- a/docs/reference/commandline/service_create.md +++ b/docs/reference/commandline/service_create.md @@ -46,6 +46,7 @@ Create a new service | [`--network`](#network) | `network` | | Network attachments | | `--no-healthcheck` | `bool` | | Disable any container-specified HEALTHCHECK | | `--no-resolve-image` | `bool` | | Do not query the registry to resolve image digest and supported platforms | +| `--oom-score-adj` | `int64` | `0` | Tune host's OOM preferences (-1000 to 1000) | | [`--placement-pref`](#placement-pref) | `pref` | | Add a placement preference | | [`-p`](#publish), [`--publish`](#publish) | `port` | | Publish a port as a node port | | `-q`, `--quiet` | `bool` | | Suppress progress output | diff --git a/docs/reference/commandline/service_update.md b/docs/reference/commandline/service_update.md index 634b95dac367..cac2d66ce7d1 100644 --- a/docs/reference/commandline/service_update.md +++ b/docs/reference/commandline/service_update.md @@ -59,6 +59,7 @@ Update a service | `--network-rm` | `list` | | Remove a network | | `--no-healthcheck` | `bool` | | Disable any container-specified HEALTHCHECK | | `--no-resolve-image` | `bool` | | Do not query the registry to resolve image digest and supported platforms | +| `--oom-score-adj` | `int64` | `0` | Tune host's OOM preferences (-1000 to 1000) | | `--placement-pref-add` | `pref` | | Add a placement preference | | `--placement-pref-rm` | `pref` | | Remove a placement preference | | [`--publish-add`](#publish-add) | `port` | | Add or update a published port |