Refactor hosts_dir lookup

Applies feedback from #199 to inline the hosts_dir env-var
lookup.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
Alex Ellis (OpenFaaS Ltd) 2021-09-15 12:44:56 +01:00
parent b8ada0d46b
commit 73c7349e36

View File

@ -247,23 +247,25 @@ func prepareEnv(envProcess string, reqEnvVars map[string]string) []string {
} }
func getMounts() []specs.Mount { func getMounts() []specs.Mount {
wd, _ := os.LookupEnv("hosts_dir") // Prior to hosts_dir env-var, this value was set to
if len(wd) == 0 { // os.Getwd()
wd = "/var/lib/faasd" hostsDir := "/var/lib/faasd"
if v, ok := os.LookupEnv("hosts_dir"); ok && len(v) > 0 {
hostsDir = v
} }
mounts := []specs.Mount{} mounts := []specs.Mount{}
mounts = append(mounts, specs.Mount{ mounts = append(mounts, specs.Mount{
Destination: "/etc/resolv.conf", Destination: "/etc/resolv.conf",
Type: "bind", Type: "bind",
Source: path.Join(wd, "resolv.conf"), Source: path.Join(hostsDir, "resolv.conf"),
Options: []string{"rbind", "ro"}, Options: []string{"rbind", "ro"},
}) })
mounts = append(mounts, specs.Mount{ mounts = append(mounts, specs.Mount{
Destination: "/etc/hosts", Destination: "/etc/hosts",
Type: "bind", Type: "bind",
Source: path.Join(wd, "hosts"), Source: path.Join(hostsDir, "hosts"),
Options: []string{"rbind", "ro"}, Options: []string{"rbind", "ro"},
}) })
return mounts return mounts