Skip to content

Commit

Permalink
fix: make cpuquota, MemorySwappiness validation compatible with docker
Browse files Browse the repository at this point in the history
refactor: logCreateOption before validation, it enable developer to see what's wrong.

Signed-off-by: zhuangqh <zhuangqhc@gmail.com>
  • Loading branch information
zhuangqh committed Nov 19, 2018
1 parent 8acae57 commit 029d517
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 32 deletions.
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
3 changes: 1 addition & 2 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 @@ -2663,7 +2662,7 @@ definitions:
description: "Tune a container's memory swappiness behavior. Accepts an integer between 0 and 100."
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.

0 comments on commit 029d517

Please sign in to comment.