mirror of
https://github.com/kemko/nomad.git
synced 2026-01-08 19:35:41 +03:00
Merge pull request #1493 from nak3/rkt-fix1
Pass command and trust_prefix to the validation of rkt task configuration
This commit is contained in:
@@ -57,7 +57,9 @@ type RktDriver struct {
|
||||
|
||||
type RktDriverConfig struct {
|
||||
ImageName string `mapstructure:"image"`
|
||||
Command string `mapstructure:"command"`
|
||||
Args []string `mapstructure:"args"`
|
||||
TrustPrefix string `mapstructure:"trust_prefix"`
|
||||
DNSServers []string `mapstructure:"dns_servers"` // DNS Server for containers
|
||||
DNSSearchDomains []string `mapstructure:"dns_search_domains"` // DNS Search domains for containers
|
||||
}
|
||||
@@ -99,9 +101,15 @@ func (d *RktDriver) Validate(config map[string]interface{}) error {
|
||||
Type: fields.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
"command": &fields.FieldSchema{
|
||||
Type: fields.TypeString,
|
||||
},
|
||||
"args": &fields.FieldSchema{
|
||||
Type: fields.TypeArray,
|
||||
},
|
||||
"trust_prefix": &fields.FieldSchema{
|
||||
Type: fields.TypeString,
|
||||
},
|
||||
"dns_servers": &fields.FieldSchema{
|
||||
Type: fields.TypeArray,
|
||||
},
|
||||
|
||||
@@ -325,3 +325,63 @@ func TestRktDriverUser(t *testing.T) {
|
||||
t.Fatalf("Expecting '%v' in '%v'", msg, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRktTrustPrefix(t *testing.T) {
|
||||
if os.Getenv("NOMAD_TEST_RKT") == "" {
|
||||
t.Skip("skipping rkt tests")
|
||||
}
|
||||
ctestutils.RktCompatible(t)
|
||||
task := &structs.Task{
|
||||
Name: "etcd",
|
||||
Config: map[string]interface{}{
|
||||
"trust_prefix": "example.com/invalid",
|
||||
"image": "coreos.com/etcd:v2.0.4",
|
||||
"command": "/etcd",
|
||||
"args": []string{"--version"},
|
||||
},
|
||||
LogConfig: &structs.LogConfig{
|
||||
MaxFiles: 10,
|
||||
MaxFileSizeMB: 10,
|
||||
},
|
||||
Resources: &structs.Resources{
|
||||
MemoryMB: 128,
|
||||
CPU: 100,
|
||||
},
|
||||
}
|
||||
driverCtx, execCtx := testDriverContexts(task)
|
||||
defer execCtx.AllocDir.Destroy()
|
||||
|
||||
d := NewRktDriver(driverCtx)
|
||||
|
||||
handle, err := d.Start(execCtx, task)
|
||||
if err == nil {
|
||||
handle.Kill()
|
||||
t.Fatalf("Should've failed")
|
||||
}
|
||||
msg := "Error running rkt trust"
|
||||
if !strings.Contains(err.Error(), msg) {
|
||||
t.Fatalf("Expecting '%v' in '%v'", msg, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRktTaskValidate(t *testing.T) {
|
||||
ctestutils.RktCompatible(t)
|
||||
task := &structs.Task{
|
||||
Name: "etcd",
|
||||
Config: map[string]interface{}{
|
||||
"trust_prefix": "coreos.com/etcd",
|
||||
"image": "coreos.com/etcd:v2.0.4",
|
||||
"command": "/etcd",
|
||||
"args": []string{"--version"},
|
||||
"dns_servers": []string{"8.8.8.8", "8.8.4.4"},
|
||||
"dns_search_domains": []string{"example.com", "example.org", "example.net"},
|
||||
},
|
||||
}
|
||||
driverCtx, execCtx := testDriverContexts(task)
|
||||
defer execCtx.AllocDir.Destroy()
|
||||
|
||||
d := NewRktDriver(driverCtx)
|
||||
if err := d.Validate(task.Config); err != nil {
|
||||
t.Fatalf("Validation error in TaskConfig : '%v'", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user