Skip to content

Commit

Permalink
docker: add default blocks for driver plugin config schema
Browse files Browse the repository at this point in the history
  • Loading branch information
nickethier committed Nov 20, 2018
1 parent 249dbff commit fab76c6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
23 changes: 19 additions & 4 deletions drivers/docker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,24 @@ var (
// }
configSpec = hclspec.NewObject(map[string]*hclspec.Spec{
"endpoint": hclspec.NewAttr("endpoint", "string", false),

// docker daemon auth option for image registry
"auth": hclspec.NewBlock("auth", false, hclspec.NewObject(map[string]*hclspec.Spec{
"config": hclspec.NewAttr("config", "string", false),
"helper": hclspec.NewAttr("helper", "string", false),
})),

// client tls options
"tls": hclspec.NewBlock("tls", false, hclspec.NewObject(map[string]*hclspec.Spec{
"cert": hclspec.NewAttr("cert", "string", false),
"key": hclspec.NewAttr("key", "string", false),
"ca": hclspec.NewAttr("ca", "string", false),
})),
"gc": hclspec.NewBlock("gc", false, hclspec.NewObject(map[string]*hclspec.Spec{

// garbage collection options
// default needed for both if the gc {...} block is not set and
// if the default fields are missing
"gc": hclspec.NewDefault(hclspec.NewBlock("gc", false, hclspec.NewObject(map[string]*hclspec.Spec{
"image": hclspec.NewDefault(
hclspec.NewAttr("image", "bool", false),
hclspec.NewLiteral("true"),
Expand All @@ -170,14 +178,21 @@ var (
hclspec.NewAttr("container", "bool", false),
hclspec.NewLiteral("true"),
),
})),
"volumes": hclspec.NewBlock("volumes", false, hclspec.NewObject(map[string]*hclspec.Spec{
})), hclspec.NewLiteral(`{
image = true
container = true
}`)),

// docker volume options
// defaulted needed for both if the volumes {...} block is not set and
// if the default fields are missing
"volumes": hclspec.NewDefault(hclspec.NewBlock("volumes", false, hclspec.NewObject(map[string]*hclspec.Spec{
"enabled": hclspec.NewDefault(
hclspec.NewAttr("enabled", "bool", false),
hclspec.NewLiteral("true"),
),
"selinuxlabel": hclspec.NewAttr("selinuxlabel", "string", false),
})),
})), hclspec.NewLiteral("{ enabled = true }")),
"allow_privileged": hclspec.NewAttr("allow_privileged", "bool", false),
"allow_caps": hclspec.NewDefault(
hclspec.NewAttr("allow_caps", "list(string)", false),
Expand Down
15 changes: 9 additions & 6 deletions drivers/docker/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ func dockerDriverHarness(t *testing.T, cfg map[string]interface{}) *drivers.Driv
harness := drivers.NewDriverHarness(t, NewDockerDriver(logger))
if cfg == nil {
cfg = map[string]interface{}{
"image_gc_delay": "1s",
"gc": map[string]interface{}{
"image_delay": "1s",
},
}
}
plugLoader, err := loader.NewPluginLoader(&loader.PluginLoaderConfig{
Expand Down Expand Up @@ -1546,8 +1548,12 @@ func TestDockerDriver_VolumesDisabled(t *testing.T) {
}

cfg := map[string]interface{}{
"volumes_enabled": false,
"image_gc": false,
"volumes": map[string]interface{}{
"enabled": false,
},
"gc": map[string]interface{}{
"image": false,
},
}

{
Expand Down Expand Up @@ -1710,9 +1716,6 @@ func TestDockerDriver_Mounts(t *testing.T) {

// TestDockerDriver_Cleanup ensures Cleanup removes only downloaded images.
func TestDockerDriver_Cleanup(t *testing.T) {
if !tu.IsTravis() {
t.Parallel()
}
if !testutil.DockerIsConnected(t) {
t.Skip("Docker not connected")
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/docker/driver_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ done
handle, ok := driver.Impl().(*Driver).tasks.Get(task.ID)
require.True(t, ok)

waitForExist(t, newTestDockerClient(t), handle.container.ID)
waitForExist(t, newTestDockerClient(t), handle.containerID)
require.NoError(t, handle.Kill(time.Duration(tu.TestMultiplier()*5)*time.Second, os.Interrupt))

waitCh, err := driver.WaitTask(context.Background(), task.ID)
Expand Down
6 changes: 4 additions & 2 deletions drivers/shared/eventer/eventer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ func TestEventer(t *testing.T) {
t.Parallel()
require := require.New(t)

ctx, _ := context.WithCancel(context.Background())
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
e := NewEventer(ctx, testlog.HCLogger(t))

events := []*drivers.TaskEvent{
Expand All @@ -33,7 +34,8 @@ func TestEventer(t *testing.T) {
},
}

ctx1, _ := context.WithCancel(context.Background())
ctx1, cancel1 := context.WithCancel(context.Background())
defer cancel1()
consumer1, err := e.TaskEvents(ctx1)
require.NoError(err)
ctx2 := (context.Background())
Expand Down

0 comments on commit fab76c6

Please sign in to comment.