Handle any volume type, not only tmpfs (#42)

This commit is contained in:
Fabricio Voznika
2019-11-25 17:10:10 -08:00
committed by Lantao Liu
parent f299b553af
commit 67745b88e0
2 changed files with 39 additions and 7 deletions
+2 -6
View File
@@ -117,10 +117,6 @@ func UpdateVolumeAnnotations(bundle string, s *specs.Spec) error {
if volumeFieldName(k) != "type" {
continue
}
if v != "tmpfs" {
// Only tmpfs is supported now.
continue
}
volume := volumeName(k)
if uid != "" {
// This is a sandbox
@@ -143,8 +139,8 @@ func UpdateVolumeAnnotations(bundle string, s *specs.Spec) error {
// more accurate matching.
if yes, _ := isVolumePath(volume, s.Mounts[i].Source); yes {
// gVisor requires the container mount type to match
// sandbox mount type for tmpfs.
s.Mounts[i].Type = "tmpfs"
// sandbox mount type.
s.Mounts[i].Type = v
updated = true
}
}
+37 -1
View File
@@ -103,7 +103,7 @@ func TestUpdateVolumeAnnotations(t *testing.T) {
expectUpdate: true,
},
{
desc: "volume annotations for container",
desc: "tmpfs: volume annotations for container",
spec: &specs.Spec{
Mounts: []specs.Mount{
{
@@ -150,6 +150,42 @@ func TestUpdateVolumeAnnotations(t *testing.T) {
},
expectUpdate: true,
},
{
desc: "bind: volume annotations for container",
spec: &specs.Spec{
Mounts: []specs.Mount{
{
Destination: "/test",
Type: "bind",
Source: testVolumePath,
Options: []string{"ro"},
},
},
Annotations: map[string]string{
annotations.ContainerType: annotations.ContainerTypeContainer,
"gvisor.dev/spec/mount/" + testVolumeName + "/share": "container",
"gvisor.dev/spec/mount/" + testVolumeName + "/type": "bind",
"gvisor.dev/spec/mount/" + testVolumeName + "/options": "ro",
},
},
expected: &specs.Spec{
Mounts: []specs.Mount{
{
Destination: "/test",
Type: "bind",
Source: testVolumePath,
Options: []string{"ro"},
},
},
Annotations: map[string]string{
annotations.ContainerType: annotations.ContainerTypeContainer,
"gvisor.dev/spec/mount/" + testVolumeName + "/share": "container",
"gvisor.dev/spec/mount/" + testVolumeName + "/type": "bind",
"gvisor.dev/spec/mount/" + testVolumeName + "/options": "ro",
},
},
expectUpdate: true,
},
{
desc: "should not return error without pod log directory",
spec: &specs.Spec{