mirror of https://github.com/docker/docs.git
api/server fix golint errors/warnings.
Addresses #14756 Signed-off-by: Srini Brahmaroutu <srbrahma@us.ibm.com>
This commit is contained in:
parent
f809037128
commit
351f6b8ec0
|
@ -9,7 +9,7 @@ import (
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ProfilerSetup(mainRouter *mux.Router, path string) {
|
func profilerSetup(mainRouter *mux.Router, path string) {
|
||||||
var r = mainRouter.PathPrefix(path).Subrouter()
|
var r = mainRouter.PathPrefix(path).Subrouter()
|
||||||
r.HandleFunc("/vars", expVars)
|
r.HandleFunc("/vars", expVars)
|
||||||
r.HandleFunc("/pprof/", pprof.Index)
|
r.HandleFunc("/pprof/", pprof.Index)
|
||||||
|
|
|
@ -40,7 +40,8 @@ import (
|
||||||
"github.com/docker/docker/utils"
|
"github.com/docker/docker/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ServerConfig struct {
|
// Config provides the configuration for the API server
|
||||||
|
type Config struct {
|
||||||
Logging bool
|
Logging bool
|
||||||
EnableCors bool
|
EnableCors bool
|
||||||
CorsHeaders string
|
CorsHeaders string
|
||||||
|
@ -49,15 +50,17 @@ type ServerConfig struct {
|
||||||
TLSConfig *tls.Config
|
TLSConfig *tls.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Server contains instance details for the server
|
||||||
type Server struct {
|
type Server struct {
|
||||||
daemon *daemon.Daemon
|
daemon *daemon.Daemon
|
||||||
cfg *ServerConfig
|
cfg *Config
|
||||||
router *mux.Router
|
router *mux.Router
|
||||||
start chan struct{}
|
start chan struct{}
|
||||||
servers []serverCloser
|
servers []serverCloser
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(cfg *ServerConfig) *Server {
|
// New returns a new instance of the server based on the specified configuration.
|
||||||
|
func New(cfg *Config) *Server {
|
||||||
srv := &Server{
|
srv := &Server{
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
start: make(chan struct{}),
|
start: make(chan struct{}),
|
||||||
|
@ -67,6 +70,7 @@ func New(cfg *ServerConfig) *Server {
|
||||||
return srv
|
return srv
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close closes servers and thus stop receiving requests
|
||||||
func (s *Server) Close() {
|
func (s *Server) Close() {
|
||||||
for _, srv := range s.servers {
|
for _, srv := range s.servers {
|
||||||
if err := srv.Close(); err != nil {
|
if err := srv.Close(); err != nil {
|
||||||
|
@ -80,9 +84,9 @@ type serverCloser interface {
|
||||||
Close() error
|
Close() error
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServeApi loops through all of the protocols sent in to docker and spawns
|
// ServeAPI loops through all of the protocols sent in to docker and spawns
|
||||||
// off a go routine to setup a serving http.Server for each.
|
// off a go routine to setup a serving http.Server for each.
|
||||||
func (s *Server) ServeApi(protoAddrs []string) error {
|
func (s *Server) ServeAPI(protoAddrs []string) error {
|
||||||
var chErrors = make(chan error, len(protoAddrs))
|
var chErrors = make(chan error, len(protoAddrs))
|
||||||
|
|
||||||
for _, protoAddr := range protoAddrs {
|
for _, protoAddr := range protoAddrs {
|
||||||
|
@ -117,19 +121,27 @@ func (s *Server) ServeApi(protoAddrs []string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type HttpServer struct {
|
// HTTPServer contains an instance of http server and the listener.
|
||||||
|
// srv *http.Server, contains configuration to create a http server and a mux router with all api end points.
|
||||||
|
// l net.Listener, is a TCP or Socket listener that dispatches incoming request to the router.
|
||||||
|
type HTTPServer struct {
|
||||||
srv *http.Server
|
srv *http.Server
|
||||||
l net.Listener
|
l net.Listener
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *HttpServer) Serve() error {
|
// Serve starts listening for inbound requests.
|
||||||
|
func (s *HTTPServer) Serve() error {
|
||||||
return s.srv.Serve(s.l)
|
return s.srv.Serve(s.l)
|
||||||
}
|
}
|
||||||
func (s *HttpServer) Close() error {
|
|
||||||
|
// Close closes the HTTPServer from listening for the inbound requests.
|
||||||
|
func (s *HTTPServer) Close() error {
|
||||||
return s.l.Close()
|
return s.l.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
type HttpApiFunc func(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error
|
// HTTPAPIFunc is an adapter to allow the use of ordinary functions as Docker API endpoints.
|
||||||
|
// Any function that has the appropriate signature can be register as a API endpoint (e.g. getVersion).
|
||||||
|
type HTTPAPIFunc func(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error
|
||||||
|
|
||||||
func hijackServer(w http.ResponseWriter) (io.ReadCloser, io.Writer, error) {
|
func hijackServer(w http.ResponseWriter) (io.ReadCloser, io.Writer, error) {
|
||||||
conn, _, err := w.(http.Hijacker).Hijack()
|
conn, _, err := w.(http.Hijacker).Hijack()
|
||||||
|
@ -153,8 +165,8 @@ func closeStreams(streams ...interface{}) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check to make sure request's Content-Type is application/json
|
// checkForJSON makes sure that the request's Content-Type is application/json.
|
||||||
func checkForJson(r *http.Request) error {
|
func checkForJSON(r *http.Request) error {
|
||||||
ct := r.Header.Get("Content-Type")
|
ct := r.Header.Get("Content-Type")
|
||||||
|
|
||||||
// No Content-Type header is ok as long as there's no Body
|
// No Content-Type header is ok as long as there's no Body
|
||||||
|
@ -438,7 +450,7 @@ func (s *Server) getEvents(version version.Version, w http.ResponseWriter, r *ht
|
||||||
outStream.Write(nil) // make sure response is sent immediately
|
outStream.Write(nil) // make sure response is sent immediately
|
||||||
enc := json.NewEncoder(outStream)
|
enc := json.NewEncoder(outStream)
|
||||||
|
|
||||||
getContainerId := func(cn string) string {
|
getContainerID := func(cn string) string {
|
||||||
c, err := d.Get(cn)
|
c, err := d.Get(cn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return ""
|
||||||
|
@ -449,7 +461,7 @@ func (s *Server) getEvents(version version.Version, w http.ResponseWriter, r *ht
|
||||||
sendEvent := func(ev *jsonmessage.JSONMessage) error {
|
sendEvent := func(ev *jsonmessage.JSONMessage) error {
|
||||||
//incoming container filter can be name,id or partial id, convert and replace as a full container id
|
//incoming container filter can be name,id or partial id, convert and replace as a full container id
|
||||||
for i, cn := range ef["container"] {
|
for i, cn := range ef["container"] {
|
||||||
ef["container"][i] = getContainerId(cn)
|
ef["container"][i] = getContainerID(cn)
|
||||||
}
|
}
|
||||||
|
|
||||||
if isFiltered(ev.Status, ef["event"]) || (isFiltered(ev.ID, ef["image"]) &&
|
if isFiltered(ev.Status, ef["event"]) || (isFiltered(ev.ID, ef["image"]) &&
|
||||||
|
@ -684,7 +696,7 @@ func (s *Server) postCommit(version version.Version, w http.ResponseWriter, r *h
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := checkForJson(r); err != nil {
|
if err := checkForJSON(r); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -734,8 +746,8 @@ func (s *Server) postImagesCreate(version version.Version, w http.ResponseWriter
|
||||||
authEncoded := r.Header.Get("X-Registry-Auth")
|
authEncoded := r.Header.Get("X-Registry-Auth")
|
||||||
authConfig := &cliconfig.AuthConfig{}
|
authConfig := &cliconfig.AuthConfig{}
|
||||||
if authEncoded != "" {
|
if authEncoded != "" {
|
||||||
authJson := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded))
|
authJSON := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded))
|
||||||
if err := json.NewDecoder(authJson).Decode(authConfig); err != nil {
|
if err := json.NewDecoder(authJSON).Decode(authConfig); err != nil {
|
||||||
// for a pull it is not an error if no auth was given
|
// for a pull it is not an error if no auth was given
|
||||||
// to increase compatibility with the existing api it is defaulting to be empty
|
// to increase compatibility with the existing api it is defaulting to be empty
|
||||||
authConfig = &cliconfig.AuthConfig{}
|
authConfig = &cliconfig.AuthConfig{}
|
||||||
|
@ -814,8 +826,8 @@ func (s *Server) getImagesSearch(version version.Version, w http.ResponseWriter,
|
||||||
)
|
)
|
||||||
|
|
||||||
if authEncoded != "" {
|
if authEncoded != "" {
|
||||||
authJson := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded))
|
authJSON := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded))
|
||||||
if err := json.NewDecoder(authJson).Decode(&config); err != nil {
|
if err := json.NewDecoder(authJSON).Decode(&config); err != nil {
|
||||||
// for a search it is not an error if no auth was given
|
// for a search it is not an error if no auth was given
|
||||||
// to increase compatibility with the existing api it is defaulting to be empty
|
// to increase compatibility with the existing api it is defaulting to be empty
|
||||||
config = &cliconfig.AuthConfig{}
|
config = &cliconfig.AuthConfig{}
|
||||||
|
@ -852,8 +864,8 @@ func (s *Server) postImagesPush(version version.Version, w http.ResponseWriter,
|
||||||
authEncoded := r.Header.Get("X-Registry-Auth")
|
authEncoded := r.Header.Get("X-Registry-Auth")
|
||||||
if authEncoded != "" {
|
if authEncoded != "" {
|
||||||
// the new format is to handle the authConfig as a header
|
// the new format is to handle the authConfig as a header
|
||||||
authJson := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded))
|
authJSON := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded))
|
||||||
if err := json.NewDecoder(authJson).Decode(authConfig); err != nil {
|
if err := json.NewDecoder(authJSON).Decode(authConfig); err != nil {
|
||||||
// to increase compatibility to existing api it is defaulting to be empty
|
// to increase compatibility to existing api it is defaulting to be empty
|
||||||
authConfig = &cliconfig.AuthConfig{}
|
authConfig = &cliconfig.AuthConfig{}
|
||||||
}
|
}
|
||||||
|
@ -923,7 +935,7 @@ func (s *Server) postContainersCreate(version version.Version, w http.ResponseWr
|
||||||
if err := parseForm(r); err != nil {
|
if err := parseForm(r); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := checkForJson(r); err != nil {
|
if err := checkForJSON(r); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
|
@ -935,15 +947,15 @@ func (s *Server) postContainersCreate(version version.Version, w http.ResponseWr
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
adjustCpuShares(version, hostConfig)
|
adjustCPUShares(version, hostConfig)
|
||||||
|
|
||||||
containerId, warnings, err := s.daemon.ContainerCreate(name, config, hostConfig)
|
containerID, warnings, err := s.daemon.ContainerCreate(name, config, hostConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return writeJSON(w, http.StatusCreated, &types.ContainerCreateResponse{
|
return writeJSON(w, http.StatusCreated, &types.ContainerCreateResponse{
|
||||||
ID: containerId,
|
ID: containerID,
|
||||||
Warnings: warnings,
|
Warnings: warnings,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1045,7 +1057,7 @@ func (s *Server) postContainersStart(version version.Version, w http.ResponseWri
|
||||||
// allow a nil body for backwards compatibility
|
// allow a nil body for backwards compatibility
|
||||||
var hostConfig *runconfig.HostConfig
|
var hostConfig *runconfig.HostConfig
|
||||||
if r.Body != nil && (r.ContentLength > 0 || r.ContentLength == -1) {
|
if r.Body != nil && (r.ContentLength > 0 || r.ContentLength == -1) {
|
||||||
if err := checkForJson(r); err != nil {
|
if err := checkForJSON(r); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1292,9 +1304,9 @@ func (s *Server) postBuild(version version.Version, w http.ResponseWriter, r *ht
|
||||||
buildConfig.CgroupParent = r.FormValue("cgroupparent")
|
buildConfig.CgroupParent = r.FormValue("cgroupparent")
|
||||||
|
|
||||||
var buildUlimits = []*ulimit.Ulimit{}
|
var buildUlimits = []*ulimit.Ulimit{}
|
||||||
ulimitsJson := r.FormValue("ulimits")
|
ulimitsJSON := r.FormValue("ulimits")
|
||||||
if ulimitsJson != "" {
|
if ulimitsJSON != "" {
|
||||||
if err := json.NewDecoder(strings.NewReader(ulimitsJson)).Decode(&buildUlimits); err != nil {
|
if err := json.NewDecoder(strings.NewReader(ulimitsJSON)).Decode(&buildUlimits); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
buildConfig.Ulimits = buildUlimits
|
buildConfig.Ulimits = buildUlimits
|
||||||
|
@ -1332,7 +1344,7 @@ func (s *Server) postContainersCopy(version version.Version, w http.ResponseWrit
|
||||||
return fmt.Errorf("Missing parameter")
|
return fmt.Errorf("Missing parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := checkForJson(r); err != nil {
|
if err := checkForJSON(r); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1431,7 +1443,7 @@ func (s *Server) postContainerExecCreate(version version.Version, w http.Respons
|
||||||
if err := parseForm(r); err != nil {
|
if err := parseForm(r); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := checkForJson(r); err != nil {
|
if err := checkForJSON(r); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
name := vars["name"]
|
name := vars["name"]
|
||||||
|
@ -1547,7 +1559,7 @@ func (s *Server) ping(version version.Version, w http.ResponseWriter, r *http.Re
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) initTcpSocket(addr string) (l net.Listener, err error) {
|
func (s *Server) initTCPSocket(addr string) (l net.Listener, err error) {
|
||||||
if s.cfg.TLSConfig == nil || s.cfg.TLSConfig.ClientAuth != tls.RequireAndVerifyClientCert {
|
if s.cfg.TLSConfig == nil || s.cfg.TLSConfig.ClientAuth != tls.RequireAndVerifyClientCert {
|
||||||
logrus.Warn("/!\\ DON'T BIND ON ANY IP ADDRESS WITHOUT setting -tlsverify IF YOU DON'T KNOW WHAT YOU'RE DOING /!\\")
|
logrus.Warn("/!\\ DON'T BIND ON ANY IP ADDRESS WITHOUT setting -tlsverify IF YOU DON'T KNOW WHAT YOU'RE DOING /!\\")
|
||||||
}
|
}
|
||||||
|
@ -1560,7 +1572,7 @@ func (s *Server) initTcpSocket(addr string) (l net.Listener, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeHttpHandler(logging bool, localMethod string, localRoute string, handlerFunc HttpApiFunc, corsHeaders string, dockerVersion version.Version) http.HandlerFunc {
|
func makeHTTPHandler(logging bool, localMethod string, localRoute string, handlerFunc HTTPAPIFunc, corsHeaders string, dockerVersion version.Version) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
// log the request
|
// log the request
|
||||||
logrus.Debugf("Calling %s %s", localMethod, localRoute)
|
logrus.Debugf("Calling %s %s", localMethod, localRoute)
|
||||||
|
@ -1612,9 +1624,9 @@ func makeHttpHandler(logging bool, localMethod string, localRoute string, handle
|
||||||
func createRouter(s *Server) *mux.Router {
|
func createRouter(s *Server) *mux.Router {
|
||||||
r := mux.NewRouter()
|
r := mux.NewRouter()
|
||||||
if os.Getenv("DEBUG") != "" {
|
if os.Getenv("DEBUG") != "" {
|
||||||
ProfilerSetup(r, "/debug/")
|
profilerSetup(r, "/debug/")
|
||||||
}
|
}
|
||||||
m := map[string]map[string]HttpApiFunc{
|
m := map[string]map[string]HTTPAPIFunc{
|
||||||
"HEAD": {
|
"HEAD": {
|
||||||
"/containers/{name:.*}/archive": s.headContainersArchive,
|
"/containers/{name:.*}/archive": s.headContainersArchive,
|
||||||
},
|
},
|
||||||
|
@ -1693,7 +1705,7 @@ func createRouter(s *Server) *mux.Router {
|
||||||
localMethod := method
|
localMethod := method
|
||||||
|
|
||||||
// build the handler function
|
// build the handler function
|
||||||
f := makeHttpHandler(s.cfg.Logging, localMethod, localRoute, localFct, corsHeaders, version.Version(s.cfg.Version))
|
f := makeHTTPHandler(s.cfg.Logging, localMethod, localRoute, localFct, corsHeaders, version.Version(s.cfg.Version))
|
||||||
|
|
||||||
// add the new route
|
// add the new route
|
||||||
if localRoute == "" {
|
if localRoute == "" {
|
||||||
|
|
|
@ -19,8 +19,8 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// See http://git.kernel.org/cgit/linux/kernel/git/tip/tip.git/tree/kernel/sched/sched.h?id=8cd9234c64c584432f6992fe944ca9e46ca8ea76#n269
|
// See http://git.kernel.org/cgit/linux/kernel/git/tip/tip.git/tree/kernel/sched/sched.h?id=8cd9234c64c584432f6992fe944ca9e46ca8ea76#n269
|
||||||
linuxMinCpuShares = 2
|
linuxMinCPUShares = 2
|
||||||
linuxMaxCpuShares = 262144
|
linuxMaxCPUShares = 262144
|
||||||
)
|
)
|
||||||
|
|
||||||
// newServer sets up the required serverClosers and does protocol specific checking.
|
// newServer sets up the required serverClosers and does protocol specific checking.
|
||||||
|
@ -40,7 +40,7 @@ func (s *Server) newServer(proto, addr string) ([]serverCloser, error) {
|
||||||
// won't be ready.
|
// won't be ready.
|
||||||
<-s.start
|
<-s.start
|
||||||
case "tcp":
|
case "tcp":
|
||||||
l, err := s.initTcpSocket(addr)
|
l, err := s.initTCPSocket(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ func (s *Server) newServer(proto, addr string) ([]serverCloser, error) {
|
||||||
}
|
}
|
||||||
var res []serverCloser
|
var res []serverCloser
|
||||||
for _, l := range ls {
|
for _, l := range ls {
|
||||||
res = append(res, &HttpServer{
|
res = append(res, &HTTPServer{
|
||||||
&http.Server{
|
&http.Server{
|
||||||
Addr: addr,
|
Addr: addr,
|
||||||
Handler: s.router,
|
Handler: s.router,
|
||||||
|
@ -67,6 +67,9 @@ func (s *Server) newServer(proto, addr string) ([]serverCloser, error) {
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AcceptConnections allows clients to connect to the API server.
|
||||||
|
// Referenced Daemon is notified about this server, and waits for the
|
||||||
|
// daemon acknowledgement before the incoming connections are accepted.
|
||||||
func (s *Server) AcceptConnections(d *daemon.Daemon) {
|
func (s *Server) AcceptConnections(d *daemon.Daemon) {
|
||||||
// Tell the init daemon we are accepting requests
|
// Tell the init daemon we are accepting requests
|
||||||
s.daemon = d
|
s.daemon = d
|
||||||
|
@ -107,16 +110,16 @@ func allocateDaemonPort(addr string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func adjustCpuShares(version version.Version, hostConfig *runconfig.HostConfig) {
|
func adjustCPUShares(version version.Version, hostConfig *runconfig.HostConfig) {
|
||||||
if version.LessThan("1.19") {
|
if version.LessThan("1.19") {
|
||||||
if hostConfig != nil && hostConfig.CPUShares > 0 {
|
if hostConfig != nil && hostConfig.CPUShares > 0 {
|
||||||
// Handle unsupported CpuShares
|
// Handle unsupported CpuShares
|
||||||
if hostConfig.CPUShares < linuxMinCpuShares {
|
if hostConfig.CPUShares < linuxMinCPUShares {
|
||||||
logrus.Warnf("Changing requested CpuShares of %d to minimum allowed of %d", hostConfig.CPUShares, linuxMinCpuShares)
|
logrus.Warnf("Changing requested CpuShares of %d to minimum allowed of %d", hostConfig.CPUShares, linuxMinCPUShares)
|
||||||
hostConfig.CPUShares = linuxMinCpuShares
|
hostConfig.CPUShares = linuxMinCPUShares
|
||||||
} else if hostConfig.CPUShares > linuxMaxCpuShares {
|
} else if hostConfig.CPUShares > linuxMaxCPUShares {
|
||||||
logrus.Warnf("Changing requested CpuShares of %d to maximum allowed of %d", hostConfig.CPUShares, linuxMaxCpuShares)
|
logrus.Warnf("Changing requested CpuShares of %d to maximum allowed of %d", hostConfig.CPUShares, linuxMaxCPUShares)
|
||||||
hostConfig.CPUShares = linuxMaxCpuShares
|
hostConfig.CPUShares = linuxMaxCPUShares
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,60 +9,60 @@ import (
|
||||||
"github.com/docker/docker/runconfig"
|
"github.com/docker/docker/runconfig"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAdjustCpuSharesOldApi(t *testing.T) {
|
func TestAdjustCPUSharesOldApi(t *testing.T) {
|
||||||
apiVersion := version.Version("1.18")
|
apiVersion := version.Version("1.18")
|
||||||
hostConfig := &runconfig.HostConfig{
|
hostConfig := &runconfig.HostConfig{
|
||||||
CPUShares: linuxMinCpuShares - 1,
|
CPUShares: linuxMinCPUShares - 1,
|
||||||
}
|
}
|
||||||
adjustCpuShares(apiVersion, hostConfig)
|
adjustCPUShares(apiVersion, hostConfig)
|
||||||
if hostConfig.CPUShares != linuxMinCpuShares {
|
if hostConfig.CPUShares != linuxMinCPUShares {
|
||||||
t.Errorf("Expected CpuShares to be %d", linuxMinCpuShares)
|
t.Errorf("Expected CPUShares to be %d", linuxMinCPUShares)
|
||||||
}
|
}
|
||||||
|
|
||||||
hostConfig.CPUShares = linuxMaxCpuShares + 1
|
hostConfig.CPUShares = linuxMaxCPUShares + 1
|
||||||
adjustCpuShares(apiVersion, hostConfig)
|
adjustCPUShares(apiVersion, hostConfig)
|
||||||
if hostConfig.CPUShares != linuxMaxCpuShares {
|
if hostConfig.CPUShares != linuxMaxCPUShares {
|
||||||
t.Errorf("Expected CpuShares to be %d", linuxMaxCpuShares)
|
t.Errorf("Expected CPUShares to be %d", linuxMaxCPUShares)
|
||||||
}
|
}
|
||||||
|
|
||||||
hostConfig.CPUShares = 0
|
hostConfig.CPUShares = 0
|
||||||
adjustCpuShares(apiVersion, hostConfig)
|
adjustCPUShares(apiVersion, hostConfig)
|
||||||
if hostConfig.CPUShares != 0 {
|
if hostConfig.CPUShares != 0 {
|
||||||
t.Error("Expected CpuShares to be unchanged")
|
t.Error("Expected CPUShares to be unchanged")
|
||||||
}
|
}
|
||||||
|
|
||||||
hostConfig.CPUShares = 1024
|
hostConfig.CPUShares = 1024
|
||||||
adjustCpuShares(apiVersion, hostConfig)
|
adjustCPUShares(apiVersion, hostConfig)
|
||||||
if hostConfig.CPUShares != 1024 {
|
if hostConfig.CPUShares != 1024 {
|
||||||
t.Error("Expected CpuShares to be unchanged")
|
t.Error("Expected CPUShares to be unchanged")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAdjustCpuSharesNoAdjustment(t *testing.T) {
|
func TestAdjustCPUSharesNoAdjustment(t *testing.T) {
|
||||||
apiVersion := version.Version("1.19")
|
apiVersion := version.Version("1.19")
|
||||||
hostConfig := &runconfig.HostConfig{
|
hostConfig := &runconfig.HostConfig{
|
||||||
CPUShares: linuxMinCpuShares - 1,
|
CPUShares: linuxMinCPUShares - 1,
|
||||||
}
|
}
|
||||||
adjustCpuShares(apiVersion, hostConfig)
|
adjustCPUShares(apiVersion, hostConfig)
|
||||||
if hostConfig.CPUShares != linuxMinCpuShares-1 {
|
if hostConfig.CPUShares != linuxMinCPUShares-1 {
|
||||||
t.Errorf("Expected CpuShares to be %d", linuxMinCpuShares-1)
|
t.Errorf("Expected CPUShares to be %d", linuxMinCPUShares-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
hostConfig.CPUShares = linuxMaxCpuShares + 1
|
hostConfig.CPUShares = linuxMaxCPUShares + 1
|
||||||
adjustCpuShares(apiVersion, hostConfig)
|
adjustCPUShares(apiVersion, hostConfig)
|
||||||
if hostConfig.CPUShares != linuxMaxCpuShares+1 {
|
if hostConfig.CPUShares != linuxMaxCPUShares+1 {
|
||||||
t.Errorf("Expected CpuShares to be %d", linuxMaxCpuShares+1)
|
t.Errorf("Expected CPUShares to be %d", linuxMaxCPUShares+1)
|
||||||
}
|
}
|
||||||
|
|
||||||
hostConfig.CPUShares = 0
|
hostConfig.CPUShares = 0
|
||||||
adjustCpuShares(apiVersion, hostConfig)
|
adjustCPUShares(apiVersion, hostConfig)
|
||||||
if hostConfig.CPUShares != 0 {
|
if hostConfig.CPUShares != 0 {
|
||||||
t.Error("Expected CpuShares to be unchanged")
|
t.Error("Expected CPUShares to be unchanged")
|
||||||
}
|
}
|
||||||
|
|
||||||
hostConfig.CPUShares = 1024
|
hostConfig.CPUShares = 1024
|
||||||
adjustCpuShares(apiVersion, hostConfig)
|
adjustCPUShares(apiVersion, hostConfig)
|
||||||
if hostConfig.CPUShares != 1024 {
|
if hostConfig.CPUShares != 1024 {
|
||||||
t.Error("Expected CpuShares to be unchanged")
|
t.Error("Expected CPUShares to be unchanged")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ func (s *Server) newServer(proto, addr string) ([]serverCloser, error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AcceptConnections allows router to start listening for the incoming requests.
|
||||||
func (s *Server) AcceptConnections(d *daemon.Daemon) {
|
func (s *Server) AcceptConnections(d *daemon.Daemon) {
|
||||||
s.daemon = d
|
s.daemon = d
|
||||||
s.registerSubRouter()
|
s.registerSubRouter()
|
||||||
|
@ -58,7 +59,7 @@ func allocateDaemonPort(addr string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func adjustCpuShares(version version.Version, hostConfig *runconfig.HostConfig) {
|
func adjustCPUShares(version version.Version, hostConfig *runconfig.HostConfig) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// getContainersByNameDownlevel performs processing for pre 1.20 APIs. This
|
// getContainersByNameDownlevel performs processing for pre 1.20 APIs. This
|
||||||
|
|
|
@ -211,7 +211,7 @@ func (cli *DaemonCli) CmdDaemon(args ...string) error {
|
||||||
cli.LogConfig.Config = make(map[string]string)
|
cli.LogConfig.Config = make(map[string]string)
|
||||||
}
|
}
|
||||||
|
|
||||||
serverConfig := &apiserver.ServerConfig{
|
serverConfig := &apiserver.Config{
|
||||||
Logging: true,
|
Logging: true,
|
||||||
Version: dockerversion.VERSION,
|
Version: dockerversion.VERSION,
|
||||||
}
|
}
|
||||||
|
@ -236,7 +236,7 @@ func (cli *DaemonCli) CmdDaemon(args ...string) error {
|
||||||
// daemon doesn't exit
|
// daemon doesn't exit
|
||||||
serveAPIWait := make(chan error)
|
serveAPIWait := make(chan error)
|
||||||
go func() {
|
go func() {
|
||||||
if err := api.ServeApi(commonFlags.Hosts); err != nil {
|
if err := api.ServeAPI(commonFlags.Hosts); err != nil {
|
||||||
logrus.Errorf("ServeAPI error: %v", err)
|
logrus.Errorf("ServeAPI error: %v", err)
|
||||||
serveAPIWait <- err
|
serveAPIWait <- err
|
||||||
return
|
return
|
||||||
|
|
|
@ -15,7 +15,7 @@ import (
|
||||||
_ "github.com/docker/docker/daemon/execdriver/native"
|
_ "github.com/docker/docker/daemon/execdriver/native"
|
||||||
)
|
)
|
||||||
|
|
||||||
func setPlatformServerConfig(serverConfig *apiserver.ServerConfig, daemonCfg *daemon.Config) *apiserver.ServerConfig {
|
func setPlatformServerConfig(serverConfig *apiserver.Config, daemonCfg *daemon.Config) *apiserver.Config {
|
||||||
serverConfig.SocketGroup = daemonCfg.SocketGroup
|
serverConfig.SocketGroup = daemonCfg.SocketGroup
|
||||||
serverConfig.EnableCors = daemonCfg.EnableCors
|
serverConfig.EnableCors = daemonCfg.EnableCors
|
||||||
serverConfig.CorsHeaders = daemonCfg.CorsHeaders
|
serverConfig.CorsHeaders = daemonCfg.CorsHeaders
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"github.com/docker/docker/daemon"
|
"github.com/docker/docker/daemon"
|
||||||
)
|
)
|
||||||
|
|
||||||
func setPlatformServerConfig(serverConfig *apiserver.ServerConfig, daemonCfg *daemon.Config) *apiserver.ServerConfig {
|
func setPlatformServerConfig(serverConfig *apiserver.Config, daemonCfg *daemon.Config) *apiserver.Config {
|
||||||
return serverConfig
|
return serverConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ source "${MAKEDIR}/.validate"
|
||||||
# packages=( $(go list ./... 2> /dev/null | grep -vE "^github.com/docker/docker/vendor" || true ) )
|
# packages=( $(go list ./... 2> /dev/null | grep -vE "^github.com/docker/docker/vendor" || true ) )
|
||||||
|
|
||||||
packages=(
|
packages=(
|
||||||
|
api/server
|
||||||
builder
|
builder
|
||||||
builder/command
|
builder/command
|
||||||
builder/parser
|
builder/parser
|
||||||
|
|
Loading…
Reference in New Issue