Skip to content

Commit 2248c1e

Browse files
committed
Add OOM adjustment flag to hostconfig via swarmctl cli
Signed-off-by: plaurent <[email protected]>
1 parent 22ee520 commit 2248c1e

File tree

7 files changed

+234
-160
lines changed

7 files changed

+234
-160
lines changed

api/api.pb.txt

+22
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 {
@@ -11691,6 +11698,21 @@ file {
1169111698
weak_dependency: 2
1169211699
syntax: "proto3"
1169311700
}
11701+
file {
11702+
name: "github.com/docker/swarmkit/api/test.proto"
11703+
package: "docker.swarmkit.v1"
11704+
message_type {
11705+
name: "TestService"
11706+
field {
11707+
name: "TestService"
11708+
number: 1
11709+
label: LABEL_OPTIONAL
11710+
type: TYPE_UINT64
11711+
json_name: "TestService"
11712+
}
11713+
}
11714+
syntax: "proto3"
11715+
}
1169411716
file {
1169511717
name: "github.com/docker/swarmkit/api/watch.proto"
1169611718
package: "docker.swarmkit.v1"

api/specs.pb.go

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

api/specs.proto

+4
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,8 @@ 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+
376+
int64 oom_score_adj = 30;
373377
}
374378

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

api/types.proto

+3
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ message ResourceRequirements {
8080
Resources limits = 1;
8181
Resources reservations = 2;
8282

83+
8384
// Amount of swap in bytes - can only be used together with a memory limit
8485
// -1 means unlimited
8586
// a null pointer indicates that the default behaviour of granting twice
@@ -90,6 +91,8 @@ message ResourceRequirements {
9091
// to the container OS's default - generally 60, or the value predefined in
9192
// the image; set to -1 to unset a previously set value
9293
google.protobuf.Int64Value memory_swappiness = 4;
94+
95+
9396
}
9497

9598
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)