From d1066ead3f0c114a082cbee92c8be6ea16429978 Mon Sep 17 00:00:00 2001 From: Aaron Brown Date: Mon, 1 Jul 2019 15:59:47 -0400 Subject: [PATCH] quote container name in container already use error matching https://github.com/moby/moby/pull/27510 switched the container already in use message from a bare string to a quoted string, so the auto-deletion of "in use" containers no longer works in Docker > 17.04. --- pkg/kubelet/dockershim/docker_container_test.go | 2 +- pkg/kubelet/dockershim/helpers.go | 2 +- pkg/kubelet/dockershim/helpers_test.go | 13 +++++++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pkg/kubelet/dockershim/docker_container_test.go b/pkg/kubelet/dockershim/docker_container_test.go index 94bb2d0e12f..d26a136ee05 100644 --- a/pkg/kubelet/dockershim/docker_container_test.go +++ b/pkg/kubelet/dockershim/docker_container_test.go @@ -248,7 +248,7 @@ func TestContainerCreationConflict(t *testing.T) { containerName := makeContainerName(sConfig, config) const sandboxId = "sandboxid" const containerId = "containerid" - conflictError := fmt.Errorf("Error response from daemon: Conflict. The name \"/%s\" is already in use by container %s. You have to remove (or rename) that container to be able to reuse that name.", + conflictError := fmt.Errorf("Error response from daemon: Conflict. The name \"/%s\" is already in use by container %q. You have to remove (or rename) that container to be able to reuse that name.", containerName, containerId) noContainerError := fmt.Errorf("Error response from daemon: No such container: %s", containerId) randomError := fmt.Errorf("random error") diff --git a/pkg/kubelet/dockershim/helpers.go b/pkg/kubelet/dockershim/helpers.go index 8763ef5275c..656e2a138fd 100644 --- a/pkg/kubelet/dockershim/helpers.go +++ b/pkg/kubelet/dockershim/helpers.go @@ -43,7 +43,7 @@ const ( ) var ( - conflictRE = regexp.MustCompile(`Conflict. (?:.)+ is already in use by container ([0-9a-z]+)`) + conflictRE = regexp.MustCompile(`Conflict. (?:.)+ is already in use by container \"?([0-9a-z]+)\"?`) // this is hacky, but extremely common. // if a container starts but the executable file is not found, runc gives a message that matches diff --git a/pkg/kubelet/dockershim/helpers_test.go b/pkg/kubelet/dockershim/helpers_test.go index fe36073a59b..20144820274 100644 --- a/pkg/kubelet/dockershim/helpers_test.go +++ b/pkg/kubelet/dockershim/helpers_test.go @@ -118,11 +118,16 @@ func TestGetUserFromImageUser(t *testing.T) { func TestParsingCreationConflictError(t *testing.T) { // Expected error message from docker. - msg := "Conflict. The name \"/k8s_POD_pfpod_e2e-tests-port-forwarding-dlxt2_81a3469e-99e1-11e6-89f2-42010af00002_0\" is already in use by container 24666ab8c814d16f986449e504ea0159468ddf8da01897144a770f66dce0e14e. You have to remove (or rename) that container to be able to reuse that name." + msgs := []string{ + "Conflict. The name \"/k8s_POD_pfpod_e2e-tests-port-forwarding-dlxt2_81a3469e-99e1-11e6-89f2-42010af00002_0\" is already in use by container 24666ab8c814d16f986449e504ea0159468ddf8da01897144a770f66dce0e14e. You have to remove (or rename) that container to be able to reuse that name.", + "Conflict. The name \"/k8s_POD_pfpod_e2e-tests-port-forwarding-dlxt2_81a3469e-99e1-11e6-89f2-42010af00002_0\" is already in use by container \"24666ab8c814d16f986449e504ea0159468ddf8da01897144a770f66dce0e14e\". You have to remove (or rename) that container to be able to reuse that name.", + } - matches := conflictRE.FindStringSubmatch(msg) - require.Len(t, matches, 2) - require.Equal(t, matches[1], "24666ab8c814d16f986449e504ea0159468ddf8da01897144a770f66dce0e14e") + for _, msg := range msgs { + matches := conflictRE.FindStringSubmatch(msg) + require.Len(t, matches, 2) + require.Equal(t, matches[1], "24666ab8c814d16f986449e504ea0159468ddf8da01897144a770f66dce0e14e") + } } func TestEnsureSandboxImageExists(t *testing.T) {