Skip to content

Commit eb98387

Browse files
committed
create_host_path must not be omitted when set to false
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 1b2139e commit eb98387

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

types/types.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,12 +564,20 @@ const (
564564
type ServiceVolumeBind struct {
565565
SELinux string `yaml:"selinux,omitempty" json:"selinux,omitempty"`
566566
Propagation string `yaml:"propagation,omitempty" json:"propagation,omitempty"`
567-
CreateHostPath bool `yaml:"create_host_path,omitempty" json:"create_host_path,omitempty"`
567+
CreateHostPath OptOut `yaml:"create_host_path,omitempty" json:"create_host_path,omitempty"`
568568
Recursive string `yaml:"recursive,omitempty" json:"recursive,omitempty"`
569569

570570
Extensions Extensions `yaml:"#extensions,inline,omitempty" json:"-"`
571571
}
572572

573+
// OptOut is a boolean which default value is 'true'
574+
type OptOut bool
575+
576+
func (o OptOut) IsZero() bool {
577+
// Attribute can be omitted if value is true
578+
return bool(o)
579+
}
580+
573581
// SELinux represents the SELinux re-labeling options.
574582
const (
575583
// SELinuxShared option indicates that the bind mount content is shared among multiple containers

types/types_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,3 +380,37 @@ func TestMappingValues(t *testing.T) {
380380
})
381381
assert.DeepEqual(t, mapping.Values(), values)
382382
}
383+
384+
func TestMarhsall(t *testing.T) {
385+
p := Project{
386+
Services: Services{
387+
"test": ServiceConfig{
388+
Volumes: []ServiceVolumeConfig{
389+
{
390+
Type: "bind",
391+
Bind: &ServiceVolumeBind{
392+
CreateHostPath: true, // default
393+
},
394+
},
395+
{
396+
Type: "bind",
397+
Bind: &ServiceVolumeBind{
398+
CreateHostPath: false,
399+
},
400+
},
401+
},
402+
},
403+
},
404+
}
405+
marshalYAML, err := p.MarshalYAML()
406+
assert.NilError(t, err)
407+
assert.Equal(t, string(marshalYAML), `services:
408+
test:
409+
volumes:
410+
- type: bind
411+
bind: {}
412+
- type: bind
413+
bind:
414+
create_host_path: false
415+
`)
416+
}

0 commit comments

Comments
 (0)