Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers/docker: rename logging type to driver #5372

Merged
merged 2 commits into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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