Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker: move host path for hosts file mount to alloc dir #10823

Merged
merged 3 commits into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## 1.1.3 (Unreleased)

BUG FIXES:
csi: fixed a CLI panic when formatting `volume status` with `-verbose` flag [[GH-10818](https://github.com/hashicorp/nomad/issues/10818)]
* csi: Fixed a CLI panic when formatting `volume status` with `-verbose` flag [[GH-10818](https://github.com/hashicorp/nomad/issues/10818)]
* docker: Moved the generated `/etc/hosts` file's mount source to the allocation directory so that it can be shared between tasks of an allocation. [[GH-10823](https://github.com/hashicorp/nomad/issues/10823)]
tgross marked this conversation as resolved.
Show resolved Hide resolved

## 1.1.2 (June 22, 2021)

Expand Down
2 changes: 1 addition & 1 deletion drivers/docker/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ func (d *Driver) createContainerConfig(task *drivers.TaskConfig, driverConfig *T
// that comes from the pause container
if task.NetworkIsolation != nil && driverConfig.NetworkMode == "" {
etcHostMount, err := hostnames.GenerateEtcHostsMount(
task.TaskDir().Dir, task.NetworkIsolation, driverConfig.ExtraHosts)
task.AllocDir, task.NetworkIsolation, driverConfig.ExtraHosts)
if err != nil {
return c, fmt.Errorf("failed to build mount for /etc/hosts: %v", err)
}
Expand Down
12 changes: 9 additions & 3 deletions drivers/shared/hostnames/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io/ioutil"
"net"
"os"
"path/filepath"
"strings"

Expand Down Expand Up @@ -56,9 +57,14 @@ ff02::3 ip6-allhosts
}

path := filepath.Join(taskDir, "hosts")
err := ioutil.WriteFile(path, []byte(content.String()), 0644)
if err != nil {
return nil, err

// tasks within an alloc should be able to share and modify the file, so
// only write to it if it doesn't exist
if _, err := os.Stat(path); os.IsNotExist(err) {
err := ioutil.WriteFile(path, []byte(content.String()), 0644)
if err != nil {
return nil, err
}
}

// Note that we're not setting readonly. The file is in the task dir
Expand Down