Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make cpuquota, MemorySwappiness validation compatible with docker #2474

Merged
merged 1 commit into from
Nov 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions apis/server/container_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ func (s *Server) createContainer(ctx context.Context, rw http.ResponseWriter, re
if err := json.NewDecoder(reader).Decode(config); err != nil {
return httputils.NewHTTPError(err, http.StatusBadRequest)
}

logCreateOptions("container", config)

// validate request body
if err := config.Validate(strfmt.NewFormats()); err != nil {
return httputils.NewHTTPError(err, http.StatusBadRequest)
}

logCreateOptions("container", config)

name := req.FormValue("name")
//consider set specific id by url params
specificID := req.FormValue("specificId")
Expand Down
8 changes: 4 additions & 4 deletions apis/server/exec_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ func (s *Server) createContainerExec(ctx context.Context, rw http.ResponseWriter
if err := json.NewDecoder(req.Body).Decode(config); err != nil {
return httputils.NewHTTPError(err, http.StatusBadRequest)
}
name := mux.Vars(req)["name"]

logCreateOptions("container exec for "+name, config)

// validate request body
if err := config.Validate(strfmt.NewFormats()); err != nil {
return httputils.NewHTTPError(err, http.StatusBadRequest)
}

name := mux.Vars(req)["name"]

logCreateOptions("container exec for "+name, config)

id, err := s.ContainerMgr.CreateExec(ctx, name, config)
if err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions apis/server/network_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ func (s *Server) createNetwork(ctx context.Context, rw http.ResponseWriter, req
if err := json.NewDecoder(req.Body).Decode(config); err != nil {
return httputils.NewHTTPError(err, http.StatusBadRequest)
}

logCreateOptions("network", config)

// validate request body
if err := config.Validate(strfmt.NewFormats()); err != nil {
return httputils.NewHTTPError(err, http.StatusBadRequest)
}

logCreateOptions("network", config)

network, err := s.NetworkMgr.Create(ctx, *config)
if err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions apis/server/volume_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ func (s *Server) createVolume(ctx context.Context, rw http.ResponseWriter, req *
if err := json.NewDecoder(req.Body).Decode(config); err != nil {
return httputils.NewHTTPError(err, http.StatusBadRequest)
}

logCreateOptions("volume", config)

// validate request body
if err := config.Validate(strfmt.NewFormats()); err != nil {
return httputils.NewHTTPError(err, http.StatusBadRequest)
}

logCreateOptions("volume", config)

name := config.Name
driver := config.Driver
options := config.DriverOpts
Expand Down
5 changes: 2 additions & 3 deletions apis/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2598,7 +2598,6 @@ definitions:
Microseconds of CPU time that the container can get in a CPU period."
type: "integer"
format: "int64"
minimum: 1000
x-nullable: false
x-omitempty: false
CpuRealtimePeriod:
Expand Down Expand Up @@ -2660,10 +2659,10 @@ definitions:
x-nullable: false
x-omitempty: false
MemorySwappiness:
description: "Tune a container's memory swappiness behavior. Accepts an integer between 0 and 100."
description: "Tune a container's memory swappiness behavior. Accepts an integer between 0 and 100. -1 is also accepted, as a legacy alias of 0."
type: "integer"
format: "int64"
minimum: 0
minimum: -1
maximum: 100
x-omitempty: false
NanoCpus:
Expand Down
22 changes: 2 additions & 20 deletions apis/types/resources.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion daemon/mgr/container_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func validateResource(r *types.Resources, update bool) ([]string, error) {
r.MemorySwappiness = nil
}
if r.MemorySwappiness != nil && *r.MemorySwappiness != -1 && (*r.MemorySwappiness < 0 || *r.MemorySwappiness > 100) {
return warnings, fmt.Errorf("MemorySwappiness should in range [0, 100]")
return warnings, fmt.Errorf("MemorySwappiness should in range [0, 100] or -1 as a legacy alias of 0")
}
if r.OomKillDisable != nil && !cgroupInfo.Memory.OOMKillDisable {
logrus.Warn(OOMKillWarn)
Expand Down
2 changes: 1 addition & 1 deletion test/cli_run_memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (suite *PouchRunMemorySuite) TestRunWithMemoryswappiness(c *check.C) {
"--memory-swappiness", "-1",
"--name", cname, busyboxImage, "top")
DelContainerForceMultyTime(c, cname)
c.Assert(res.ExitCode, check.Equals, 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we use the swagger validation, this test case should not passed, Right?

c.Assert(res.ExitCode, check.Equals, 0)

cname = "TestRunWithMemoryswappiness"
memory := "100m"
Expand Down