Skip to content

Commit c599566

Browse files
psaintlaurentthaJeztah
authored andcommitted
Allow for OomScoreAdj
Signed-off-by: plaurent <[email protected]> (cherry picked from commit aa2c2cd) Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent fb19def commit c599566

File tree

9 files changed

+17
-0
lines changed

9 files changed

+17
-0
lines changed

cli/command/service/create.go

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ func newCreateCommand(dockerCli command.Cli) *cobra.Command {
6868
flags.SetAnnotation(flagSysCtl, "version", []string{"1.40"})
6969
flags.Var(&opts.ulimits, flagUlimit, "Ulimit options")
7070
flags.SetAnnotation(flagUlimit, "version", []string{"1.41"})
71+
flags.Int64Var(&opts.oomScoreAdj, flagOomScoreAdj, 0, "Tune host's OOM preferences (-1000 to 1000) ")
72+
flags.SetAnnotation(flagOomScoreAdj, "version", []string{"1.46"})
7173

7274
flags.Var(cliopts.NewListOptsRef(&opts.resources.resGenericResources, ValidateSingleGenericResource), "generic-resource", "User defined resources")
7375
flags.SetAnnotation(flagHostAdd, "version", []string{"1.32"})

cli/command/service/opts.go

+3
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ type serviceOptions struct {
529529
capAdd opts.ListOpts
530530
capDrop opts.ListOpts
531531
ulimits opts.UlimitOpt
532+
oomScoreAdj int64
532533

533534
resources resourceOptions
534535
stopGrace opts.DurationOpt
@@ -747,6 +748,7 @@ func (options *serviceOptions) ToService(ctx context.Context, apiClient client.N
747748
CapabilityAdd: capAdd,
748749
CapabilityDrop: capDrop,
749750
Ulimits: options.ulimits.GetList(),
751+
OomScoreAdj: options.oomScoreAdj,
750752
},
751753
Networks: networks,
752754
Resources: resources,
@@ -1043,6 +1045,7 @@ const (
10431045
flagUlimit = "ulimit"
10441046
flagUlimitAdd = "ulimit-add"
10451047
flagUlimitRemove = "ulimit-rm"
1048+
flagOomScoreAdj = "oom-score-adj"
10461049
)
10471050

10481051
func validateAPIVersion(c swarm.ServiceSpec, serverAPIVersion string) error {

cli/command/service/update.go

+6
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ func newUpdateCommand(dockerCli command.Cli) *cobra.Command {
108108
flags.SetAnnotation(flagUlimitAdd, "version", []string{"1.41"})
109109
flags.Var(newListOptsVar(), flagUlimitRemove, "Remove a ulimit option")
110110
flags.SetAnnotation(flagUlimitRemove, "version", []string{"1.41"})
111+
flags.Int64Var(&options.oomScoreAdj, flagOomScoreAdj, 0, "Tune host's OOM preferences (-1000 to 1000) ")
112+
flags.SetAnnotation(flagOomScoreAdj, "version", []string{"1.46"})
111113

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

372+
if anyChanged(flags, flagOomScoreAdj) {
373+
updateInt64(flagOomScoreAdj, &task.ContainerSpec.OomScoreAdj)
374+
}
375+
370376
if err := addGenericResources(flags, task); err != nil {
371377
return err
372378
}

cli/compose/convert/service.go

+1
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ func Service(
148148
CapabilityAdd: capAdd,
149149
CapabilityDrop: capDrop,
150150
Ulimits: convertUlimits(service.Ulimits),
151+
OomScoreAdj: service.OomScoreAdj,
151152
},
152153
LogDriver: logDriver,
153154
Resources: resources,

cli/compose/loader/interpolate.go

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ var interpolateTypeCastMapping = map[interp.Path]interp.Cast{
2929
servicePath("ulimits", interp.PathMatchAll, "hard"): toInt,
3030
servicePath("ulimits", interp.PathMatchAll, "soft"): toInt,
3131
servicePath("privileged"): toBoolean,
32+
servicePath("oom_score_adj"): toInt,
3233
servicePath("read_only"): toBoolean,
3334
servicePath("stdin_open"): toBoolean,
3435
servicePath("tty"): toBoolean,

cli/compose/schema/data/config_schema_v3.13.json

+1
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@
287287
}
288288
}
289289
},
290+
"oom_score_adj": {"type": "integer"},
290291
"user": {"type": "string"},
291292
"userns_mode": {"type": "string"},
292293
"volumes": {

cli/compose/types/types.go

+1
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ type ServiceConfig struct {
207207
Tty bool `mapstructure:"tty" yaml:"tty,omitempty" json:"tty,omitempty"`
208208
Ulimits map[string]*UlimitsConfig `yaml:",omitempty" json:"ulimits,omitempty"`
209209
User string `yaml:",omitempty" json:"user,omitempty"`
210+
OomScoreAdj int64 `yaml:",omitempty" json:"oom_score_adj,omitempty"`
210211
UserNSMode string `mapstructure:"userns_mode" yaml:"userns_mode,omitempty" json:"userns_mode,omitempty"`
211212
Volumes []ServiceVolumeConfig `yaml:",omitempty" json:"volumes,omitempty"`
212213
WorkingDir string `mapstructure:"working_dir" yaml:"working_dir,omitempty" json:"working_dir,omitempty"`

docs/reference/commandline/service_create.md

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Create a new service
4646
| [`--network`](#network) | `network` | | Network attachments |
4747
| `--no-healthcheck` | `bool` | | Disable any container-specified HEALTHCHECK |
4848
| `--no-resolve-image` | `bool` | | Do not query the registry to resolve image digest and supported platforms |
49+
| `--oom-score-adj` | `int64` | `0` | Tune host's OOM preferences (-1000 to 1000) |
4950
| [`--placement-pref`](#placement-pref) | `pref` | | Add a placement preference |
5051
| [`-p`](#publish), [`--publish`](#publish) | `port` | | Publish a port as a node port |
5152
| `-q`, `--quiet` | `bool` | | Suppress progress output |

docs/reference/commandline/service_update.md

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Update a service
5959
| `--network-rm` | `list` | | Remove a network |
6060
| `--no-healthcheck` | `bool` | | Disable any container-specified HEALTHCHECK |
6161
| `--no-resolve-image` | `bool` | | Do not query the registry to resolve image digest and supported platforms |
62+
| `--oom-score-adj` | `int64` | `0` | Tune host's OOM preferences (-1000 to 1000) |
6263
| `--placement-pref-add` | `pref` | | Add a placement preference |
6364
| `--placement-pref-rm` | `pref` | | Remove a placement preference |
6465
| [`--publish-add`](#publish-add) | `port` | | Add or update a published port |

0 commit comments

Comments
 (0)