From 78185557f26b64a7ad468402225a2c78008b8e2d Mon Sep 17 00:00:00 2001 From: Yorick Gersie Date: Thu, 26 Jan 2023 16:27:01 +0100 Subject: [PATCH 1/3] Ensure infra_image gets proper label used for reconciliation Currently infra containers are not cleaned up as part of the dangling container cleanup routine. The reason is that Nomad checks if a container is a Nomad owned container by verifying the existence of the: `com.hashicorp.nomad.alloc_id` label. Ensure we set this label on the infra container as well. --- drivers/docker/network.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/docker/network.go b/drivers/docker/network.go index 71a9ab512f3d..1cc57db77d8f 100644 --- a/drivers/docker/network.go +++ b/drivers/docker/network.go @@ -119,12 +119,14 @@ func (d *Driver) DestroyNetwork(allocID string, spec *drivers.NetworkIsolationSp // createSandboxContainerConfig creates a docker container configuration which // starts a container with an empty network namespace. func (d *Driver) createSandboxContainerConfig(allocID string, createSpec *drivers.NetworkCreateRequest) (*docker.CreateContainerOptions, error) { - return &docker.CreateContainerOptions{ Name: fmt.Sprintf("nomad_init_%s", allocID), Config: &docker.Config{ Image: d.config.InfraImage, Hostname: createSpec.Hostname, + Labels: map[string]string{ + dockerLabelAllocID: allocID, + }, }, HostConfig: &docker.HostConfig{ // Set the network mode to none which creates a network namespace From 16048aa4332b122711bfab12768e8020dcd50ce1 Mon Sep 17 00:00:00 2001 From: Yorick Gersie Date: Thu, 26 Jan 2023 17:09:49 +0100 Subject: [PATCH 2/3] fix unit test --- drivers/docker/network_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/docker/network_test.go b/drivers/docker/network_test.go index 80c235cf8e4e..8d53306f6cec 100644 --- a/drivers/docker/network_test.go +++ b/drivers/docker/network_test.go @@ -26,6 +26,9 @@ func TestDriver_createSandboxContainerConfig(t *testing.T) { Name: "nomad_init_768b5e8c-a52e-825c-d564-51100230eb62", Config: &docker.Config{ Image: "gcr.io/google_containers/pause-amd64:3.1", + Labels: map[string]string{ + dockerLabelAllocID: "768b5e8c-a52e-825c-d564-51100230eb62", + }, }, HostConfig: &docker.HostConfig{ NetworkMode: "none", @@ -44,6 +47,9 @@ func TestDriver_createSandboxContainerConfig(t *testing.T) { Config: &docker.Config{ Image: "gcr.io/google_containers/pause-amd64:3.1", Hostname: "linux", + Labels: map[string]string{ + dockerLabelAllocID: "768b5e8c-a52e-825c-d564-51100230eb62", + }, }, HostConfig: &docker.HostConfig{ NetworkMode: "none", From b35dc407868d66191ecbd948a0793f853cd7afa0 Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Mon, 30 Jan 2023 09:01:52 -0600 Subject: [PATCH 3/3] changelog: add entry --- .changelog/15898.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/15898.txt diff --git a/.changelog/15898.txt b/.changelog/15898.txt new file mode 100644 index 000000000000..64d96190d93e --- /dev/null +++ b/.changelog/15898.txt @@ -0,0 +1,3 @@ +```release-note:bug +docker: Fixed a bug where infra_image did not get alloc_id label +```