Merge pull request #892 from achanda/rkt_dns

Enable passing DNS info to the rkt driver
This commit is contained in:
Alex Dadgar 2016-03-10 08:54:26 -08:00
commit 2ccfb43c7a
3 changed files with 32 additions and 6 deletions

View File

@ -5,6 +5,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"log" "log"
"net"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"regexp" "regexp"
@ -49,8 +50,10 @@ type RktDriver struct {
} }
type RktDriverConfig struct { type RktDriverConfig struct {
ImageName string `mapstructure:"image"` ImageName string `mapstructure:"image"`
Args []string `mapstructure:"args"` Args []string `mapstructure:"args"`
DNSServers []string `mapstructure:"dns_servers"` // DNS Server for containers
DNSSearchDomains []string `mapstructure:"dns_search_domains"` // DNS Search domains for containers
} }
// rktHandle is returned from Start/Open as a handle to the PID // rktHandle is returned from Start/Open as a handle to the PID
@ -185,6 +188,22 @@ func (d *RktDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, e
// Add CPU isolator // Add CPU isolator
cmdArgs = append(cmdArgs, fmt.Sprintf("--cpu=%vm", int64(task.Resources.CPU))) cmdArgs = append(cmdArgs, fmt.Sprintf("--cpu=%vm", int64(task.Resources.CPU)))
// Add DNS servers
for _, ip := range driverConfig.DNSServers {
if err := net.ParseIP(ip); err == nil {
msg := fmt.Errorf("invalid ip address for container dns server %q", ip)
d.logger.Printf("[DEBUG] driver.rkt: %v", msg)
return nil, msg
} else {
cmdArgs = append(cmdArgs, fmt.Sprintf("--dns=%s", ip))
}
}
// set DNS search domains
for _, domain := range driverConfig.DNSSearchDomains {
cmdArgs = append(cmdArgs, fmt.Sprintf("--dns-search=%s", domain))
}
// Add user passed arguments. // Add user passed arguments.
if len(driverConfig.Args) != 0 { if len(driverConfig.Args) != 0 {
parsed := d.taskEnv.ParseAndReplace(driverConfig.Args) parsed := d.taskEnv.ParseAndReplace(driverConfig.Args)

View File

@ -57,15 +57,17 @@ func TestRktDriver_Fingerprint(t *testing.T) {
} }
} }
func TestRktDriver_Start(t *testing.T) { func TestRktDriver_Start_DNS(t *testing.T) {
ctestutils.RktCompatible(t) ctestutils.RktCompatible(t)
// TODO: use test server to load from a fixture // TODO: use test server to load from a fixture
task := &structs.Task{ task := &structs.Task{
Name: "etcd", Name: "etcd",
Config: map[string]interface{}{ Config: map[string]interface{}{
"trust_prefix": "coreos.com/etcd", "trust_prefix": "coreos.com/etcd",
"image": "coreos.com/etcd:v2.0.4", "image": "coreos.com/etcd:v2.0.4",
"command": "/etcd", "command": "/etcd",
"dns_servers": []string{"8.8.8.8", "8.8.4.4"},
"dns_search_domains": []string{"example.com", "example.org", "example.net"},
}, },
LogConfig: &structs.LogConfig{ LogConfig: &structs.LogConfig{
MaxFiles: 10, MaxFiles: 10,

View File

@ -37,6 +37,11 @@ The `rkt` driver supports the following configuration in the job spec:
reachable from the box running the nomad agent. If not specified, the image is reachable from the box running the nomad agent. If not specified, the image is
run without verifying the image signature. run without verifying the image signature.
* `dns_servers` - (Optional) A list of DNS servers to be used in the containers
* `dns_search_domains` - (Optional) A list of DNS search domains to be used in
the containers
## Task Directories ## Task Directories
The `rkt` driver currently does not support mounting of the `alloc/` and `local/` directory. The `rkt` driver currently does not support mounting of the `alloc/` and `local/` directory.