Jelajahi Sumber

api: POST /containers/{id}/kill: remove handling for api < 1.20

API v1.20 and up produces an error when signalling / killing a non-running
container (see c92377e300d2e9863ffa8eda9c3166a039b60e09). Older API versions
allowed this, and an exception was added in 621e3d8587bbee86b4e36d0b7822662bfbedd76c.

API v1.23 and older are deprecated, so we can remove this handling.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 1 tahun lalu
induk
melakukan
dfdf2adf0c

+ 2 - 13
api/server/router/container/container_routes.go

@@ -248,25 +248,14 @@ func (s *containerRouter) postContainersStop(ctx context.Context, w http.Respons
 	return nil
 	return nil
 }
 }
 
 
-func (s *containerRouter) postContainersKill(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
+func (s *containerRouter) postContainersKill(_ context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
 	if err := httputils.ParseForm(r); err != nil {
 	if err := httputils.ParseForm(r); err != nil {
 		return err
 		return err
 	}
 	}
 
 
 	name := vars["name"]
 	name := vars["name"]
 	if err := s.backend.ContainerKill(name, r.Form.Get("signal")); err != nil {
 	if err := s.backend.ContainerKill(name, r.Form.Get("signal")); err != nil {
-		var isStopped bool
-		if errdefs.IsConflict(err) {
-			isStopped = true
-		}
-
-		// Return error that's not caused because the container is stopped.
-		// Return error if the container is not running and the api is >= 1.20
-		// to keep backwards compatibility.
-		version := httputils.VersionFromContext(ctx)
-		if versions.GreaterThanOrEqualTo(version, "1.20") || !isStopped {
-			return errors.Wrapf(err, "Cannot kill container: %s", name)
-		}
+		return errors.Wrapf(err, "cannot kill container: %s", name)
 	}
 	}
 
 
 	w.WriteHeader(http.StatusNoContent)
 	w.WriteHeader(http.StatusNoContent)

+ 0 - 10
integration/container/kill_test.go

@@ -6,7 +6,6 @@ import (
 	"time"
 	"time"
 
 
 	containertypes "github.com/docker/docker/api/types/container"
 	containertypes "github.com/docker/docker/api/types/container"
-	"github.com/docker/docker/client"
 	"github.com/docker/docker/integration/internal/container"
 	"github.com/docker/docker/integration/internal/container"
 	"github.com/docker/docker/testutil"
 	"github.com/docker/docker/testutil"
 	"github.com/docker/docker/testutil/request"
 	"github.com/docker/docker/testutil/request"
@@ -133,15 +132,6 @@ func TestKillStoppedContainer(t *testing.T) {
 	assert.Assert(t, is.Contains(err.Error(), "is not running"))
 	assert.Assert(t, is.Contains(err.Error(), "is not running"))
 }
 }
 
 
-func TestKillStoppedContainerAPIPre120(t *testing.T) {
-	skip.If(t, testEnv.DaemonInfo.OSType == "windows", "Windows only supports 1.25 or later")
-	ctx := setupTest(t)
-	apiClient := request.NewAPIClient(t, client.WithVersion("1.19"))
-	id := container.Create(ctx, t, apiClient)
-	err := apiClient.ContainerKill(ctx, id, "SIGKILL")
-	assert.NilError(t, err)
-}
-
 func TestKillDifferentUserContainer(t *testing.T) {
 func TestKillDifferentUserContainer(t *testing.T) {
 	// TODO Windows: Windows does not yet support -u (Feb 2016).
 	// TODO Windows: Windows does not yet support -u (Feb 2016).
 	skip.If(t, testEnv.DaemonInfo.OSType == "windows", "User containers (container.Config.User) are not yet supported on %q platform", testEnv.DaemonInfo.OSType)
 	skip.If(t, testEnv.DaemonInfo.OSType == "windows", "User containers (container.Config.User) are not yet supported on %q platform", testEnv.DaemonInfo.OSType)