Skip to content

Commit

Permalink
docker: image_delay default missing without gc stanza (#9101)
Browse files Browse the repository at this point in the history
In the Docker driver plugin config for garbage collection, the `image_delay`
field was missing from the default we set if the entire `gc` stanza is
missing. This results in a default of 0s and immediate GC of Docker images.

Expanded docker gc config test fields.
  • Loading branch information
tgross committed Oct 15, 2020
1 parent b3c8dee commit a9979db
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 25 deletions.
1 change: 1 addition & 0 deletions drivers/docker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ var (
),
})), hclspec.NewLiteral(`{
image = true
image_delay = "3m"
container = true
dangling_containers = {
enabled = true
Expand Down
97 changes: 72 additions & 25 deletions drivers/docker/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,52 +443,99 @@ config {
require.EqualValues(t, expected, tc)
}

// TestConfig_DriverConfig_DanglingContainers asserts that dangling_containers is parsed
// TestConfig_DriverConfig_GC asserts that gc is parsed
// and populated with defaults as expected
func TestConfig_DriverConfig_DanglingContainers(t *testing.T) {
func TestConfig_DriverConfig_GC(t *testing.T) {
cases := []struct {
name string
config string
expected ContainerGCConfig
expected GCConfig
}{
{
name: "pure default",
config: `{}`,
expected: ContainerGCConfig{Enabled: true, PeriodStr: "5m", CreationGraceStr: "5m"},
name: "pure default",
config: `{}`,
expected: GCConfig{
Image: true, ImageDelay: "3m", Container: true,
DanglingContainers: ContainerGCConfig{
Enabled: true, PeriodStr: "5m", CreationGraceStr: "5m"},
},
},
{
name: "partial gc",
config: `{ gc { } }`,
expected: GCConfig{
Image: true, ImageDelay: "3m", Container: true,
DanglingContainers: ContainerGCConfig{
Enabled: true, PeriodStr: "5m", CreationGraceStr: "5m"},
},
},
{
name: "partial gc",
config: `{ gc { dangling_containers { } } }`,
expected: GCConfig{
Image: true, ImageDelay: "3m", Container: true,
DanglingContainers: ContainerGCConfig{
Enabled: true, PeriodStr: "5m", CreationGraceStr: "5m"},
},
},
{
name: "partial gc",
config: `{ gc { } }`,
expected: ContainerGCConfig{Enabled: true, PeriodStr: "5m", CreationGraceStr: "5m"},
name: "partial image",
config: `{ gc { image = false } }`,
expected: GCConfig{
Image: false, ImageDelay: "3m", Container: true,
DanglingContainers: ContainerGCConfig{
Enabled: true, PeriodStr: "5m", CreationGraceStr: "5m"},
},
},
{
name: "partial gc",
config: `{ gc { dangling_containers { } } }`,
expected: ContainerGCConfig{Enabled: true, PeriodStr: "5m", CreationGraceStr: "5m"},
name: "partial image_delay",
config: `{ gc { image_delay = "1d"} }`,
expected: GCConfig{
Image: true, ImageDelay: "1d", Container: true,
DanglingContainers: ContainerGCConfig{
Enabled: true, PeriodStr: "5m", CreationGraceStr: "5m"},
},
},
{
name: "partial dangling_containers",
config: `{ gc { dangling_containers { enabled = false } } }`,
expected: ContainerGCConfig{Enabled: false, PeriodStr: "5m", CreationGraceStr: "5m"},
name: "partial dangling_containers",
config: `{ gc { dangling_containers { enabled = false } } }`,
expected: GCConfig{
Image: true, ImageDelay: "3m", Container: true,
DanglingContainers: ContainerGCConfig{
Enabled: false, PeriodStr: "5m", CreationGraceStr: "5m"},
},
},
{
name: "incomplete dangling_containers 2",
config: `{ gc { dangling_containers { period = "10m" } } }`,
expected: ContainerGCConfig{Enabled: true, PeriodStr: "10m", CreationGraceStr: "5m"},
name: "incomplete dangling_containers 2",
config: `{ gc { dangling_containers { period = "10m" } } }`,
expected: GCConfig{
Image: true, ImageDelay: "3m", Container: true,
DanglingContainers: ContainerGCConfig{
Enabled: true, PeriodStr: "10m", CreationGraceStr: "5m"},
},
},
{
name: "full default",
config: `{ gc { dangling_containers {
config: `{ gc {
image = false
image_delay = "5m"
container = false
dangling_containers {
enabled = false
dry_run = true
period = "10m"
creation_grace = "20m"
}}}`,
expected: ContainerGCConfig{
Enabled: false,
DryRun: true,
PeriodStr: "10m",
CreationGraceStr: "20m",
expected: GCConfig{
Image: false,
ImageDelay: "5m",
Container: false,
DanglingContainers: ContainerGCConfig{
Enabled: false,
DryRun: true,
PeriodStr: "10m",
CreationGraceStr: "20m",
},
},
},
}
Expand All @@ -497,7 +544,7 @@ func TestConfig_DriverConfig_DanglingContainers(t *testing.T) {
t.Run(c.name, func(t *testing.T) {
var tc DriverConfig
hclutils.NewConfigParser(configSpec).ParseHCL(t, "config "+c.config, &tc)
require.EqualValues(t, c.expected, tc.GC.DanglingContainers)
require.EqualValues(t, c.expected, tc.GC)

})
}
Expand Down

0 comments on commit a9979db

Please sign in to comment.