Skip to content

Commit

Permalink
Merge pull request #5372 from hashicorp/f-docker-logging-driver
Browse files Browse the repository at this point in the history
drivers/docker: rename logging `type` to `driver`
  • Loading branch information
schmichael committed Feb 28, 2019
2 parents 737ea19 + 011315b commit 82d37b9
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
2 changes: 2 additions & 0 deletions drivers/docker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ var (
"load": hclspec.NewAttr("load", "string", false),
"logging": hclspec.NewBlock("logging", false, hclspec.NewObject(map[string]*hclspec.Spec{
"type": hclspec.NewAttr("type", "string", false),
"driver": hclspec.NewAttr("driver", "string", false),
"config": hclspec.NewAttr("config", "list(map(string))", false),
})),
"mac_address": hclspec.NewAttr("mac_address", "string", false),
Expand Down Expand Up @@ -397,6 +398,7 @@ func (d DockerDevice) toDockerDevice() (docker.Device, error) {

type DockerLogging struct {
Type string `codec:"type"`
Driver string `codec:"driver"`
Config hclutils.MapStrStr `codec:"config"`
}

Expand Down
6 changes: 4 additions & 2 deletions drivers/docker/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ config {
}
load = "/tmp/image.tar.gz"
logging {
type = "json-file"
driver = "json-file-driver"
type = "json-file"
config {
"max-file" = "3"
"max-size" = "10m"
Expand Down Expand Up @@ -308,7 +309,8 @@ config {
},
LoadImage: "/tmp/image.tar.gz",
Logging: DockerLogging{
Type: "json-file",
Driver: "json-file-driver",
Type: "json-file",
Config: map[string]string{
"max-file": "3",
"max-size": "10m",
Expand Down
7 changes: 6 additions & 1 deletion drivers/docker/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,8 +706,13 @@ func (d *Driver) createContainerConfig(task *drivers.TaskConfig, driverConfig *T
hostConfig.MemorySwap = task.Resources.LinuxResources.MemoryLimitBytes // MemorySwap is memory + swap.
}

loggingDriver := driverConfig.Logging.Type
if loggingDriver == "" {
loggingDriver = driverConfig.Logging.Driver
}

hostConfig.LogConfig = docker.LogConfig{
Type: driverConfig.Logging.Type,
Type: loggingDriver,
Config: driverConfig.Logging.Config,
}

Expand Down
46 changes: 46 additions & 0 deletions drivers/docker/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,52 @@ func TestDockerDriver_CreateContainerConfig(t *testing.T) {
require.EqualValues(t, opt, c.HostConfig.StorageOpt)
}

func TestDockerDriver_CreateContainerConfig_Logging(t *testing.T) {
t.Parallel()

cases := []struct {
name string
loggingConfig DockerLogging
expectedDriver string
}{
{
"simple type",
DockerLogging{Type: "fluentd"},
"fluentd",
},
{
"simple driver",
DockerLogging{Driver: "fluentd"},
"fluentd",
},
{
"type takes precedence",
DockerLogging{
Type: "json-file",
Driver: "fluentd",
},
"json-file",
},
}

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
task, cfg, _ := dockerTask(t)

cfg.Logging = c.loggingConfig
require.NoError(t, task.EncodeConcreteDriverConfig(cfg))

dh := dockerDriverHarness(t, nil)
driver := dh.Impl().(*Driver)

cc, err := driver.createContainerConfig(task, cfg, "org/repo:0.1")
require.NoError(t, err)

require.Equal(t, c.expectedDriver, cc.HostConfig.LogConfig.Type)
})
}
}

func TestDockerDriver_CreateContainerConfigWithRuntimes(t *testing.T) {
if !tu.IsCI() {
t.Parallel()
Expand Down

0 comments on commit 82d37b9

Please sign in to comment.