Explorar el Código

Fix docker top a restarting container

Signed-off-by: Lei Jitang <leijitang@huawei.com>
Lei Jitang hace 9 años
padre
commit
5566ccb7aa
Se han modificado 3 ficheros con 14 adiciones y 11 borrados
  1. 2 2
      daemon/exec.go
  2. 3 0
      daemon/top_unix.go
  3. 9 9
      errors/daemon.go

+ 2 - 2
daemon/exec.go

@@ -53,7 +53,7 @@ func (d *Daemon) getExecConfig(name string) (*exec.Config, error) {
 				return nil, derr.ErrorCodeExecPaused.WithArgs(container.ID)
 			}
 			if container.IsRestarting() {
-				return nil, derr.ErrorCodeExecRestarting.WithArgs(container.ID)
+				return nil, derr.ErrorCodeContainerRestarting.WithArgs(container.ID)
 			}
 			return ec, nil
 		}
@@ -80,7 +80,7 @@ func (d *Daemon) getActiveContainer(name string) (*container.Container, error) {
 		return nil, derr.ErrorCodeExecPaused.WithArgs(name)
 	}
 	if container.IsRestarting() {
-		return nil, derr.ErrorCodeExecRestarting.WithArgs(name)
+		return nil, derr.ErrorCodeContainerRestarting.WithArgs(name)
 	}
 	return container, nil
 }

+ 3 - 0
daemon/top_unix.go

@@ -30,6 +30,9 @@ func (daemon *Daemon) ContainerTop(name string, psArgs string) (*types.Container
 		return nil, derr.ErrorCodeNotRunning.WithArgs(name)
 	}
 
+	if container.IsRestarting() {
+		return nil, derr.ErrorCodeContainerRestarting.WithArgs(name)
+	}
 	pids, err := daemon.ExecutionDriver().GetPidsForContainer(container.ID)
 	if err != nil {
 		return nil, err

+ 9 - 9
errors/daemon.go

@@ -715,6 +715,15 @@ var (
 		HTTPStatusCode: http.StatusConflict,
 	})
 
+	// ErrorCodeContainerRestarting is generated when an operation was made
+	// on a restarting container.
+	ErrorCodeContainerRestarting = errcode.Register(errGroup, errcode.ErrorDescriptor{
+		Value:          "CONTAINERRESTARTING",
+		Message:        "Container %s is restarting, wait until the container is running",
+		Description:    "An operation was made on a restarting container",
+		HTTPStatusCode: http.StatusConflict,
+	})
+
 	// ErrorCodeNoExecID is generated when we try to get the info
 	// on an exec but it can't be found.
 	ErrorCodeNoExecID = errcode.Register(errGroup, errcode.ErrorDescriptor{
@@ -733,15 +742,6 @@ var (
 		HTTPStatusCode: http.StatusConflict,
 	})
 
-	// ErrorCodeExecRestarting is generated when we try to start an exec
-	// but the container is restarting.
-	ErrorCodeExecRestarting = errcode.Register(errGroup, errcode.ErrorDescriptor{
-		Value:          "EXECRESTARTING",
-		Message:        "Container %s is restarting, wait until the container is running",
-		Description:    "An attempt to start an 'exec' was made, but the owning container is restarting",
-		HTTPStatusCode: http.StatusConflict,
-	})
-
 	// ErrorCodeExecRunning is generated when we try to start an exec
 	// but its already running.
 	ErrorCodeExecRunning = errcode.Register(errGroup, errcode.ErrorDescriptor{