Skip to content
This repository has been archived by the owner on Aug 14, 2020. It is now read-only.

Commit

Permalink
schema: replace bool with *bool in types.Volume.
Browse files Browse the repository at this point in the history
By default the `readOnly` field in Volume is `false`, this will cause
an app container runtime to always override the image manifest's volume
mounts setting. Change it to `*bool` gives us the ability to ignore this
field in the container runtime manifest.
  • Loading branch information
yifan-gu committed Mar 20, 2015
1 parent 40f1966 commit 5adc741
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
6 changes: 3 additions & 3 deletions schema/types/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Volume struct {
// currently used only by "host"
// TODO(jonboulle): factor out?
Source string `json:"source,omitempty"`
ReadOnly bool `json:"readOnly,omitempty"`
ReadOnly *bool `json:"readOnly,omitempty"`
}

type volume Volume
Expand Down Expand Up @@ -69,7 +69,7 @@ func (v Volume) MarshalJSON() ([]byte, error) {
}

func (v Volume) String() string {
s := fmt.Sprintf("%s,kind=%s,readOnly=%t", v.Name, v.Kind, v.ReadOnly)
s := fmt.Sprintf("%s,kind=%s,readOnly=%t", v.Name, v.Kind, *v.ReadOnly)
if v.Source != "" {
s = s + fmt.Sprintf("source=%s", v.Source)
}
Expand Down Expand Up @@ -110,7 +110,7 @@ func VolumeFromString(vp string) (*Volume, error) {
if err != nil {
return nil, err
}
vol.ReadOnly = ro
vol.ReadOnly = &ro
default:
return nil, fmt.Errorf("unknown volume parameter %q", key)
}
Expand Down
22 changes: 17 additions & 5 deletions schema/types/volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
)

func TestVolumeFromString(t *testing.T) {
trueVar := true
falseVar := false
tests := []struct {
s string
v Volume
Expand All @@ -16,7 +18,16 @@ func TestVolumeFromString(t *testing.T) {
Name: "foobar",
Kind: "host",
Source: "/tmp",
ReadOnly: false,
ReadOnly: nil,
},
},
{
"foobar,kind=host,source=/tmp,readOnly=false",
Volume{
Name: "foobar",
Kind: "host",
Source: "/tmp",
ReadOnly: &falseVar,
},
},
{
Expand All @@ -25,22 +36,23 @@ func TestVolumeFromString(t *testing.T) {
Name: "foobar",
Kind: "host",
Source: "/tmp",
ReadOnly: true,
ReadOnly: &trueVar,
},
},
{
"foobar,kind=empty",
Volume{
Name: "foobar",
Kind: "empty",
Name: "foobar",
Kind: "empty",
ReadOnly: nil,
},
},
{
"foobar,kind=empty,readOnly=true",
Volume{
Name: "foobar",
Kind: "empty",
ReadOnly: true,
ReadOnly: &trueVar,
},
},
}
Expand Down

0 comments on commit 5adc741

Please sign in to comment.