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

Commit 6fcbdfb

Browse files
committed
schema: replace bool with *bool in types.Volume.
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.
1 parent 40f1966 commit 6fcbdfb

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

schema/types/volume.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type Volume struct {
1919
// currently used only by "host"
2020
// TODO(jonboulle): factor out?
2121
Source string `json:"source,omitempty"`
22-
ReadOnly bool `json:"readOnly,omitempty"`
22+
ReadOnly *bool `json:"readOnly,omitempty"`
2323
}
2424

2525
type volume Volume
@@ -69,7 +69,7 @@ func (v Volume) MarshalJSON() ([]byte, error) {
6969
}
7070

7171
func (v Volume) String() string {
72-
s := fmt.Sprintf("%s,kind=%s,readOnly=%t", v.Name, v.Kind, v.ReadOnly)
72+
s := fmt.Sprintf("%s,kind=%s,readOnly=%t", v.Name, v.Kind, *v.ReadOnly)
7373
if v.Source != "" {
7474
s = s + fmt.Sprintf("source=%s", v.Source)
7575
}
@@ -110,7 +110,7 @@ func VolumeFromString(vp string) (*Volume, error) {
110110
if err != nil {
111111
return nil, err
112112
}
113-
vol.ReadOnly = ro
113+
vol.ReadOnly = &ro
114114
default:
115115
return nil, fmt.Errorf("unknown volume parameter %q", key)
116116
}

schema/types/volume_test.go

+17-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
)
77

88
func TestVolumeFromString(t *testing.T) {
9+
trueVar := true
10+
falseVar := false
911
tests := []struct {
1012
s string
1113
v Volume
@@ -16,7 +18,16 @@ func TestVolumeFromString(t *testing.T) {
1618
Name: "foobar",
1719
Kind: "host",
1820
Source: "/tmp",
19-
ReadOnly: false,
21+
ReadOnly: nil,
22+
},
23+
},
24+
{
25+
"foobar,kind=host,source=/tmp,readOnly=false",
26+
Volume{
27+
Name: "foobar",
28+
Kind: "host",
29+
Source: "/tmp",
30+
ReadOnly: &falseVar,
2031
},
2132
},
2233
{
@@ -25,22 +36,23 @@ func TestVolumeFromString(t *testing.T) {
2536
Name: "foobar",
2637
Kind: "host",
2738
Source: "/tmp",
28-
ReadOnly: true,
39+
ReadOnly: &trueVar,
2940
},
3041
},
3142
{
3243
"foobar,kind=empty",
3344
Volume{
34-
Name: "foobar",
35-
Kind: "empty",
45+
Name: "foobar",
46+
Kind: "empty",
47+
ReadOnly: nil,
3648
},
3749
},
3850
{
3951
"foobar,kind=empty,readOnly=true",
4052
Volume{
4153
Name: "foobar",
4254
Kind: "empty",
43-
ReadOnly: true,
55+
ReadOnly: &trueVar,
4456
},
4557
},
4658
}

0 commit comments

Comments
 (0)