logging.Type over logging.Driver

This commit is contained in:
Mahmood Ali 2019-02-28 16:40:18 -05:00
parent 104869c0e1
commit 4726cb2207
2 changed files with 48 additions and 2 deletions

View file

@ -706,9 +706,9 @@ func (d *Driver) createContainerConfig(task *drivers.TaskConfig, driverConfig *T
hostConfig.MemorySwap = task.Resources.LinuxResources.MemoryLimitBytes // MemorySwap is memory + swap. hostConfig.MemorySwap = task.Resources.LinuxResources.MemoryLimitBytes // MemorySwap is memory + swap.
} }
loggingDriver := driverConfig.Logging.Driver loggingDriver := driverConfig.Logging.Type
if loggingDriver == "" { if loggingDriver == "" {
loggingDriver = driverConfig.Logging.Type loggingDriver = driverConfig.Logging.Driver
} }
hostConfig.LogConfig = docker.LogConfig{ hostConfig.LogConfig = docker.LogConfig{

View file

@ -930,6 +930,52 @@ func TestDockerDriver_CreateContainerConfig(t *testing.T) {
require.EqualValues(t, opt, c.HostConfig.StorageOpt) 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) { func TestDockerDriver_CreateContainerConfigWithRuntimes(t *testing.T) {
if !tu.IsCI() { if !tu.IsCI() {
t.Parallel() t.Parallel()