Skip to content

Commit

Permalink
Allow for OomScoreAdj
Browse files Browse the repository at this point in the history
Signed-off-by: plaurent <[email protected]>
  • Loading branch information
psaintlaurent committed Jun 14, 2024
1 parent 482bf86 commit fd3a9cd
Show file tree
Hide file tree
Showing 10 changed files with 716 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cli/command/container/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
hostConfig := &container.HostConfig{
Binds: binds,
ContainerIDFile: copts.containerIDFile,
OomScoreAdj: copts.oomScoreAdj,
OomScoreAdj: int(copts.oomScoreAdj),
AutoRemove: copts.autoRemove,
Privileged: copts.privileged,
PortBindings: portBindings,
Expand Down
1 change: 1 addition & 0 deletions cli/command/service/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ 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.Var(&opts.oomScoreAdj, flagOomScoreAdj, "oom score adjustment (-1000 to 1000)")

flags.Var(cliopts.NewListOptsRef(&opts.resources.resGenericResources, ValidateSingleGenericResource), "generic-resource", "User defined resources")
flags.SetAnnotation(flagHostAdd, "version", []string{"1.32"})
Expand Down
4 changes: 4 additions & 0 deletions cli/command/service/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ type serviceOptions struct {
capAdd opts.ListOpts
capDrop opts.ListOpts
ulimits opts.UlimitOpt
oomScoreAdj opts.OomScoreAdj

resources resourceOptions
stopGrace opts.DurationOpt
Expand Down Expand Up @@ -575,6 +576,7 @@ func newServiceOptions() *serviceOptions {
capAdd: opts.NewListOpts(nil),
capDrop: opts.NewListOpts(nil),
ulimits: *opts.NewUlimitOpt(nil),
oomScoreAdj: opts.OomScoreAdj(0),
}
}

Expand Down Expand Up @@ -747,6 +749,7 @@ func (options *serviceOptions) ToService(ctx context.Context, apiClient client.N
CapabilityAdd: capAdd,
CapabilityDrop: capDrop,
Ulimits: options.ulimits.GetList(),
OomScoreAdj: options.oomScoreAdj.Value(),
},
Networks: networks,
Resources: resources,
Expand Down Expand Up @@ -1043,6 +1046,7 @@ const (
flagUlimit = "ulimit"
flagUlimitAdd = "ulimit-add"
flagUlimitRemove = "ulimit-rm"
flagOomScoreAdj = "oom-score-adj"
)

func validateAPIVersion(c swarm.ServiceSpec, serverAPIVersion string) error {
Expand Down
1 change: 1 addition & 0 deletions cli/compose/convert/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func Service(
CapabilityAdd: capAdd,
CapabilityDrop: capDrop,
Ulimits: convertUlimits(service.Ulimits),
OomScoreAdj: service.OomScoreAdj,
},
LogDriver: logDriver,
Resources: resources,
Expand Down
1 change: 1 addition & 0 deletions cli/compose/loader/interpolate.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var interpolateTypeCastMapping = map[interp.Path]interp.Cast{
servicePath("ulimits", interp.PathMatchAll): toInt,
servicePath("ulimits", interp.PathMatchAll, "hard"): toInt,
servicePath("ulimits", interp.PathMatchAll, "soft"): toInt,
servicePath("oom_score_adj"): toInt,
servicePath("privileged"): toBoolean,
servicePath("read_only"): toBoolean,
servicePath("stdin_open"): toBoolean,
Expand Down
Loading

0 comments on commit fd3a9cd

Please sign in to comment.