Skip to content

Commit

Permalink
Merge pull request #3177 from psaintlaurent/ENGINE-903
Browse files Browse the repository at this point in the history
Add OOM adjustment flag to hostconfig via swarmctl cli
  • Loading branch information
dperny authored Jun 11, 2024
2 parents c1c857e + 447c519 commit ea1a7ce
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 159 deletions.
7 changes: 7 additions & 0 deletions api/api.pb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5803,6 +5803,13 @@ file {
type_name: ".docker.swarmkit.v1.ContainerSpec.Ulimit"
json_name: "ulimits"
}
field {
name: "oom_score_adj"
number: 30
label: LABEL_OPTIONAL
type: TYPE_INT64
json_name: "oomScoreAdj"
}
nested_type {
name: "LabelsEntry"
field {
Expand Down
353 changes: 194 additions & 159 deletions api/specs.pb.go

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions api/specs.proto
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ message TaskSpec {
// Placement specifies node selection constraints
Placement placement = 5;



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

// EndpointSpec defines the properties that can be configured to
Expand Down
2 changes: 2 additions & 0 deletions api/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ message ResourceRequirements {
// to the container OS's default - generally 60, or the value predefined in
// the image; set to -1 to unset a previously set value
google.protobuf.Int64Value memory_swappiness = 4;


}

message Platform {
Expand Down
10 changes: 10 additions & 0 deletions swarmd/cmd/swarmctl/service/flagparser/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,15 @@ func parseContainer(flags *pflag.FlagSet, spec *api.ServiceSpec) error {
}
}

if flags.Changed("oom-score-adj") {

oomScoreAdj, err := flags.GetInt64("oom-score-adj")
if err != nil {
return err
}

spec.Task.GetContainer().OomScoreAdj = oomScoreAdj
}

return nil
}
1 change: 1 addition & 0 deletions swarmd/cmd/swarmctl/service/flagparser/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func AddServiceFlags(flags *pflag.FlagSet) {
flags.String("restart-delay", "5s", "delay between task restarts")
flags.Uint64("restart-max-attempts", 0, "maximum number of restart attempts (0 = unlimited)")
flags.String("restart-window", "0s", "time window to evaluate restart attempts (0 = unbound)")
flags.Int64("oom-score-adj", 0, "oom score adjustment (-1000 to 1000)")

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

Expand Down
1 change: 1 addition & 0 deletions swarmd/dockerexec/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ func (c *containerConfig) hostConfig() *enginecontainer.HostConfig {
Isolation: c.isolation(),
CapAdd: c.spec().CapabilityAdd,
CapDrop: c.spec().CapabilityDrop,
OomScoreAdj: int(c.spec().OomScoreAdj),
}

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

0 comments on commit ea1a7ce

Please sign in to comment.