Skip to content

Commit 3c33c54

Browse files
authored
Merge pull request #1493 from nak3/rkt-fix1
Pass command and trust_prefix to the validation of rkt task configuration
2 parents a8cf924 + c2a38d6 commit 3c33c54

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

client/driver/rkt.go

+8
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ type RktDriver struct {
5757

5858
type RktDriverConfig struct {
5959
ImageName string `mapstructure:"image"`
60+
Command string `mapstructure:"command"`
6061
Args []string `mapstructure:"args"`
62+
TrustPrefix string `mapstructure:"trust_prefix"`
6163
DNSServers []string `mapstructure:"dns_servers"` // DNS Server for containers
6264
DNSSearchDomains []string `mapstructure:"dns_search_domains"` // DNS Search domains for containers
6365
}
@@ -99,9 +101,15 @@ func (d *RktDriver) Validate(config map[string]interface{}) error {
99101
Type: fields.TypeString,
100102
Required: true,
101103
},
104+
"command": &fields.FieldSchema{
105+
Type: fields.TypeString,
106+
},
102107
"args": &fields.FieldSchema{
103108
Type: fields.TypeArray,
104109
},
110+
"trust_prefix": &fields.FieldSchema{
111+
Type: fields.TypeString,
112+
},
105113
"dns_servers": &fields.FieldSchema{
106114
Type: fields.TypeArray,
107115
},

client/driver/rkt_test.go

+60
Original file line numberDiff line numberDiff line change
@@ -325,3 +325,63 @@ func TestRktDriverUser(t *testing.T) {
325325
t.Fatalf("Expecting '%v' in '%v'", msg, err)
326326
}
327327
}
328+
329+
func TestRktTrustPrefix(t *testing.T) {
330+
if os.Getenv("NOMAD_TEST_RKT") == "" {
331+
t.Skip("skipping rkt tests")
332+
}
333+
ctestutils.RktCompatible(t)
334+
task := &structs.Task{
335+
Name: "etcd",
336+
Config: map[string]interface{}{
337+
"trust_prefix": "example.com/invalid",
338+
"image": "coreos.com/etcd:v2.0.4",
339+
"command": "/etcd",
340+
"args": []string{"--version"},
341+
},
342+
LogConfig: &structs.LogConfig{
343+
MaxFiles: 10,
344+
MaxFileSizeMB: 10,
345+
},
346+
Resources: &structs.Resources{
347+
MemoryMB: 128,
348+
CPU: 100,
349+
},
350+
}
351+
driverCtx, execCtx := testDriverContexts(task)
352+
defer execCtx.AllocDir.Destroy()
353+
354+
d := NewRktDriver(driverCtx)
355+
356+
handle, err := d.Start(execCtx, task)
357+
if err == nil {
358+
handle.Kill()
359+
t.Fatalf("Should've failed")
360+
}
361+
msg := "Error running rkt trust"
362+
if !strings.Contains(err.Error(), msg) {
363+
t.Fatalf("Expecting '%v' in '%v'", msg, err)
364+
}
365+
}
366+
367+
func TestRktTaskValidate(t *testing.T) {
368+
ctestutils.RktCompatible(t)
369+
task := &structs.Task{
370+
Name: "etcd",
371+
Config: map[string]interface{}{
372+
"trust_prefix": "coreos.com/etcd",
373+
"image": "coreos.com/etcd:v2.0.4",
374+
"command": "/etcd",
375+
"args": []string{"--version"},
376+
"dns_servers": []string{"8.8.8.8", "8.8.4.4"},
377+
"dns_search_domains": []string{"example.com", "example.org", "example.net"},
378+
},
379+
}
380+
driverCtx, execCtx := testDriverContexts(task)
381+
defer execCtx.AllocDir.Destroy()
382+
383+
d := NewRktDriver(driverCtx)
384+
if err := d.Validate(task.Config); err != nil {
385+
t.Fatalf("Validation error in TaskConfig : '%v'", err)
386+
}
387+
}

0 commit comments

Comments
 (0)