Skip to content

Commit

Permalink
Ensure infra_image gets proper label used for reconciliation (#15898)
Browse files Browse the repository at this point in the history
* 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.

* fix unit test

* changelog: add entry

---------

Co-authored-by: Seth Hoenig <shoenig@duck.com>
  • Loading branch information
ygersie and shoenig committed Jan 30, 2023
1 parent 340ad2d commit f9d835f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/15898.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
docker: Fixed a bug where infra_image did not get alloc_id label
```
4 changes: 3 additions & 1 deletion drivers/docker/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions drivers/docker/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit f9d835f

Please sign in to comment.