Skip to content

Commit ea1a7ce

Browse files
authored
Merge pull request #3177 from psaintlaurent/ENGINE-903
Add OOM adjustment flag to hostconfig via swarmctl cli
2 parents c1c857e + 447c519 commit ea1a7ce

File tree

7 files changed

+220
-159
lines changed

7 files changed

+220
-159
lines changed

api/api.pb.txt

+7
Original file line numberDiff line numberDiff line change
@@ -5803,6 +5803,13 @@ file {
58035803
type_name: ".docker.swarmkit.v1.ContainerSpec.Ulimit"
58045804
json_name: "ulimits"
58055805
}
5806+
field {
5807+
name: "oom_score_adj"
5808+
number: 30
5809+
label: LABEL_OPTIONAL
5810+
type: TYPE_INT64
5811+
json_name: "oomScoreAdj"
5812+
}
58065813
nested_type {
58075814
name: "LabelsEntry"
58085815
field {

api/specs.pb.go

+194-159
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/specs.proto

+5
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ message TaskSpec {
137137
// Placement specifies node selection constraints
138138
Placement placement = 5;
139139

140+
141+
140142
// LogDriver specifies the log driver to use for the task. Any runtime will
141143
// direct logs into the specified driver for the duration of the task.
142144
Driver log_driver = 6;
@@ -370,6 +372,9 @@ message ContainerSpec {
370372
// Ulimits defines the list of ulimits to set in the container. This option
371373
// is equivalent to passing --ulimit to docker run.
372374
repeated Ulimit ulimits = 29;
375+
// OOmScoreAdj defines the relative value used for destroying a container during an OOM
376+
// Values are between -1000 and 1000
377+
int64 oom_score_adj = 30;
373378
}
374379

375380
// EndpointSpec defines the properties that can be configured to

api/types.proto

+2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ message ResourceRequirements {
9090
// to the container OS's default - generally 60, or the value predefined in
9191
// the image; set to -1 to unset a previously set value
9292
google.protobuf.Int64Value memory_swappiness = 4;
93+
94+
9395
}
9496

9597
message Platform {

swarmd/cmd/swarmctl/service/flagparser/container.go

+10
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,15 @@ func parseContainer(flags *pflag.FlagSet, spec *api.ServiceSpec) error {
7676
}
7777
}
7878

79+
if flags.Changed("oom-score-adj") {
80+
81+
oomScoreAdj, err := flags.GetInt64("oom-score-adj")
82+
if err != nil {
83+
return err
84+
}
85+
86+
spec.Task.GetContainer().OomScoreAdj = oomScoreAdj
87+
}
88+
7989
return nil
8090
}

swarmd/cmd/swarmctl/service/flagparser/flags.go

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func AddServiceFlags(flags *pflag.FlagSet) {
5050
flags.String("restart-delay", "5s", "delay between task restarts")
5151
flags.Uint64("restart-max-attempts", 0, "maximum number of restart attempts (0 = unlimited)")
5252
flags.String("restart-window", "0s", "time window to evaluate restart attempts (0 = unbound)")
53+
flags.Int64("oom-score-adj", 0, "oom score adjustment (-1000 to 1000)")
5354

5455
flags.StringSlice("constraint", nil, "Placement constraint (e.g. node.labels.key==value)")
5556

swarmd/dockerexec/container.go

+1
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ func (c *containerConfig) hostConfig() *enginecontainer.HostConfig {
215215
Isolation: c.isolation(),
216216
CapAdd: c.spec().CapabilityAdd,
217217
CapDrop: c.spec().CapabilityDrop,
218+
OomScoreAdj: int(c.spec().OomScoreAdj),
218219
}
219220

220221
// The format of extra hosts on swarmkit is specified in:

0 commit comments

Comments
 (0)