Skip to content

Commit 82d37b9

Browse files
authored
Merge pull request #5372 from hashicorp/f-docker-logging-driver
drivers/docker: rename logging `type` to `driver`
2 parents 737ea19 + 011315b commit 82d37b9

File tree

4 files changed

+58
-3
lines changed

4 files changed

+58
-3
lines changed

drivers/docker/config.go

+2
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ var (
256256
"load": hclspec.NewAttr("load", "string", false),
257257
"logging": hclspec.NewBlock("logging", false, hclspec.NewObject(map[string]*hclspec.Spec{
258258
"type": hclspec.NewAttr("type", "string", false),
259+
"driver": hclspec.NewAttr("driver", "string", false),
259260
"config": hclspec.NewAttr("config", "list(map(string))", false),
260261
})),
261262
"mac_address": hclspec.NewAttr("mac_address", "string", false),
@@ -397,6 +398,7 @@ func (d DockerDevice) toDockerDevice() (docker.Device, error) {
397398

398399
type DockerLogging struct {
399400
Type string `codec:"type"`
401+
Driver string `codec:"driver"`
400402
Config hclutils.MapStrStr `codec:"config"`
401403
}
402404

drivers/docker/config_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ config {
181181
}
182182
load = "/tmp/image.tar.gz"
183183
logging {
184-
type = "json-file"
184+
driver = "json-file-driver"
185+
type = "json-file"
185186
config {
186187
"max-file" = "3"
187188
"max-size" = "10m"
@@ -308,7 +309,8 @@ config {
308309
},
309310
LoadImage: "/tmp/image.tar.gz",
310311
Logging: DockerLogging{
311-
Type: "json-file",
312+
Driver: "json-file-driver",
313+
Type: "json-file",
312314
Config: map[string]string{
313315
"max-file": "3",
314316
"max-size": "10m",

drivers/docker/driver.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -706,8 +706,13 @@ func (d *Driver) createContainerConfig(task *drivers.TaskConfig, driverConfig *T
706706
hostConfig.MemorySwap = task.Resources.LinuxResources.MemoryLimitBytes // MemorySwap is memory + swap.
707707
}
708708

709+
loggingDriver := driverConfig.Logging.Type
710+
if loggingDriver == "" {
711+
loggingDriver = driverConfig.Logging.Driver
712+
}
713+
709714
hostConfig.LogConfig = docker.LogConfig{
710-
Type: driverConfig.Logging.Type,
715+
Type: loggingDriver,
711716
Config: driverConfig.Logging.Config,
712717
}
713718

drivers/docker/driver_test.go

+46
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,52 @@ func TestDockerDriver_CreateContainerConfig(t *testing.T) {
930930
require.EqualValues(t, opt, c.HostConfig.StorageOpt)
931931
}
932932

933+
func TestDockerDriver_CreateContainerConfig_Logging(t *testing.T) {
934+
t.Parallel()
935+
936+
cases := []struct {
937+
name string
938+
loggingConfig DockerLogging
939+
expectedDriver string
940+
}{
941+
{
942+
"simple type",
943+
DockerLogging{Type: "fluentd"},
944+
"fluentd",
945+
},
946+
{
947+
"simple driver",
948+
DockerLogging{Driver: "fluentd"},
949+
"fluentd",
950+
},
951+
{
952+
"type takes precedence",
953+
DockerLogging{
954+
Type: "json-file",
955+
Driver: "fluentd",
956+
},
957+
"json-file",
958+
},
959+
}
960+
961+
for _, c := range cases {
962+
t.Run(c.name, func(t *testing.T) {
963+
task, cfg, _ := dockerTask(t)
964+
965+
cfg.Logging = c.loggingConfig
966+
require.NoError(t, task.EncodeConcreteDriverConfig(cfg))
967+
968+
dh := dockerDriverHarness(t, nil)
969+
driver := dh.Impl().(*Driver)
970+
971+
cc, err := driver.createContainerConfig(task, cfg, "org/repo:0.1")
972+
require.NoError(t, err)
973+
974+
require.Equal(t, c.expectedDriver, cc.HostConfig.LogConfig.Type)
975+
})
976+
}
977+
}
978+
933979
func TestDockerDriver_CreateContainerConfigWithRuntimes(t *testing.T) {
934980
if !tu.IsCI() {
935981
t.Parallel()

0 commit comments

Comments
 (0)