Skip to content

Commit 8c75dbf

Browse files
ndeloofglours
authored andcommitted
Fix create_host_path default value is true
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
1 parent bb50e25 commit 8c75dbf

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

loader/loader_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3935,3 +3935,22 @@ services:
39353935
assert.DeepEqual(t, p.Services["string"].Build.NoCacheFilter, types.StringList{"foo"})
39363936
assert.DeepEqual(t, p.Services["list"].Build.NoCacheFilter, types.StringList{"foo", "bar"})
39373937
}
3938+
3939+
func TestCreateHostPathDefault(t *testing.T) {
3940+
p, err := loadYAML(`
3941+
name: no-cache-filter
3942+
services:
3943+
short:
3944+
volumes:
3945+
- /host:/container
3946+
long:
3947+
volumes:
3948+
- type: bind
3949+
source: /host
3950+
target: /container
3951+
bind: {}
3952+
`)
3953+
assert.NilError(t, err)
3954+
assert.Check(t, p.Services["short"].Volumes[0].Bind.CreateHostPath == true)
3955+
assert.Check(t, p.Services["long"].Volumes[0].Bind.CreateHostPath == true)
3956+
}

transform/defaults.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func init() {
2929
DefaultValues["services.*.ports.*"] = portDefaults
3030
DefaultValues["services.*.deploy.resources.reservations.devices.*"] = deviceRequestDefaults
3131
DefaultValues["services.*.gpus.*"] = deviceRequestDefaults
32+
DefaultValues["services.*.volumes.*.bind"] = defaultVolumeBind
3233
}
3334

3435
// RegisterDefaultValue registers a custom transformer for the given path pattern

transform/volume.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,14 @@ func cleanTarget(target string) string {
5050
}
5151
return path.Clean(target)
5252
}
53+
54+
func defaultVolumeBind(data any, p tree.Path, _ bool) (any, error) {
55+
bind, ok := data.(map[string]any)
56+
if !ok {
57+
return data, fmt.Errorf("%s: invalid type %T for service volume bind", p, data)
58+
}
59+
if _, ok := bind["create_host_path"]; !ok {
60+
bind["create_host_path"] = true
61+
}
62+
return bind, nil
63+
}

0 commit comments

Comments
 (0)