Make EmptyDir annotations compliant with K8s and OCI (#44)

Change annotation from 'gvisor.dev/spec/mount/NAME/share',
which is invalid because it has more than one '/', to
'dev.gvisor.spec.mount.NAME.share'.
This commit is contained in:
Fabricio Voznika
2019-12-05 16:36:24 -08:00
committed by GitHub
parent 757adfa287
commit e83ba10736
2 changed files with 41 additions and 41 deletions
+6 -6
View File
@@ -29,20 +29,20 @@ import (
"github.com/sirupsen/logrus"
)
const volumeKeyPrefix = "gvisor.dev/spec/mount/"
const volumeKeyPrefix = "dev.gvisor.spec.mount."
var kubeletPodsDir = "/var/lib/kubelet/pods"
// volumeName gets volume name from volume annotation key, example:
// gvisor.dev/spec/mount/NAME/share
// dev.gvisor.spec.mount.NAME.share
func volumeName(k string) string {
return strings.SplitN(strings.TrimPrefix(k, volumeKeyPrefix), "/", 2)[0]
return strings.SplitN(strings.TrimPrefix(k, volumeKeyPrefix), ".", 2)[0]
}
// volumeFieldName gets volume field name from volume annotation key, example:
// `type` is the field of gvisor.dev/spec/mount/NAME/type
// `type` is the field of dev.gvisor.spec.mount.NAME.type
func volumeFieldName(k string) string {
parts := strings.Split(strings.TrimPrefix(k, volumeKeyPrefix), "/")
parts := strings.Split(strings.TrimPrefix(k, volumeKeyPrefix), ".")
return parts[len(parts)-1]
}
@@ -69,7 +69,7 @@ func isVolumeKey(k string) bool {
// volumeSourceKey constructs the annotation key for volume source.
func volumeSourceKey(volume string) string {
return volumeKeyPrefix + volume + "/source"
return volumeKeyPrefix + volume + ".source"
}
// volumePath searches the volume path in the kubelet pod directory.
+35 -35
View File
@@ -62,19 +62,19 @@ func TestUpdateVolumeAnnotations(t *testing.T) {
Annotations: map[string]string{
annotations.SandboxLogDir: testLogDirPath,
annotations.ContainerType: annotations.ContainerTypeSandbox,
"gvisor.dev/spec/mount/" + testVolumeName + "/share": "pod",
"gvisor.dev/spec/mount/" + testVolumeName + "/type": "tmpfs",
"gvisor.dev/spec/mount/" + testVolumeName + "/options": "ro",
"dev.gvisor.spec.mount." + testVolumeName + ".share": "pod",
"dev.gvisor.spec.mount." + testVolumeName + ".type": "tmpfs",
"dev.gvisor.spec.mount." + testVolumeName + ".options": "ro",
},
},
expected: &specs.Spec{
Annotations: map[string]string{
annotations.SandboxLogDir: testLogDirPath,
annotations.ContainerType: annotations.ContainerTypeSandbox,
"gvisor.dev/spec/mount/" + testVolumeName + "/share": "pod",
"gvisor.dev/spec/mount/" + testVolumeName + "/type": "tmpfs",
"gvisor.dev/spec/mount/" + testVolumeName + "/options": "ro",
"gvisor.dev/spec/mount/" + testVolumeName + "/source": testVolumePath,
"dev.gvisor.spec.mount." + testVolumeName + ".share": "pod",
"dev.gvisor.spec.mount." + testVolumeName + ".type": "tmpfs",
"dev.gvisor.spec.mount." + testVolumeName + ".options": "ro",
"dev.gvisor.spec.mount." + testVolumeName + ".source": testVolumePath,
},
},
expectUpdate: true,
@@ -85,19 +85,19 @@ func TestUpdateVolumeAnnotations(t *testing.T) {
Annotations: map[string]string{
annotations.SandboxLogDir: testLegacyLogDirPath,
annotations.ContainerType: annotations.ContainerTypeSandbox,
"gvisor.dev/spec/mount/" + testVolumeName + "/share": "pod",
"gvisor.dev/spec/mount/" + testVolumeName + "/type": "tmpfs",
"gvisor.dev/spec/mount/" + testVolumeName + "/options": "ro",
"dev.gvisor.spec.mount." + testVolumeName + ".share": "pod",
"dev.gvisor.spec.mount." + testVolumeName + ".type": "tmpfs",
"dev.gvisor.spec.mount." + testVolumeName + ".options": "ro",
},
},
expected: &specs.Spec{
Annotations: map[string]string{
annotations.SandboxLogDir: testLegacyLogDirPath,
annotations.ContainerType: annotations.ContainerTypeSandbox,
"gvisor.dev/spec/mount/" + testVolumeName + "/share": "pod",
"gvisor.dev/spec/mount/" + testVolumeName + "/type": "tmpfs",
"gvisor.dev/spec/mount/" + testVolumeName + "/options": "ro",
"gvisor.dev/spec/mount/" + testVolumeName + "/source": testVolumePath,
"dev.gvisor.spec.mount." + testVolumeName + ".share": "pod",
"dev.gvisor.spec.mount." + testVolumeName + ".type": "tmpfs",
"dev.gvisor.spec.mount." + testVolumeName + ".options": "ro",
"dev.gvisor.spec.mount." + testVolumeName + ".source": testVolumePath,
},
},
expectUpdate: true,
@@ -121,9 +121,9 @@ func TestUpdateVolumeAnnotations(t *testing.T) {
},
Annotations: map[string]string{
annotations.ContainerType: annotations.ContainerTypeContainer,
"gvisor.dev/spec/mount/" + testVolumeName + "/share": "pod",
"gvisor.dev/spec/mount/" + testVolumeName + "/type": "tmpfs",
"gvisor.dev/spec/mount/" + testVolumeName + "/options": "ro",
"dev.gvisor.spec.mount." + testVolumeName + ".share": "pod",
"dev.gvisor.spec.mount." + testVolumeName + ".type": "tmpfs",
"dev.gvisor.spec.mount." + testVolumeName + ".options": "ro",
},
},
expected: &specs.Spec{
@@ -143,9 +143,9 @@ func TestUpdateVolumeAnnotations(t *testing.T) {
},
Annotations: map[string]string{
annotations.ContainerType: annotations.ContainerTypeContainer,
"gvisor.dev/spec/mount/" + testVolumeName + "/share": "pod",
"gvisor.dev/spec/mount/" + testVolumeName + "/type": "tmpfs",
"gvisor.dev/spec/mount/" + testVolumeName + "/options": "ro",
"dev.gvisor.spec.mount." + testVolumeName + ".share": "pod",
"dev.gvisor.spec.mount." + testVolumeName + ".type": "tmpfs",
"dev.gvisor.spec.mount." + testVolumeName + ".options": "ro",
},
},
expectUpdate: true,
@@ -163,9 +163,9 @@ func TestUpdateVolumeAnnotations(t *testing.T) {
},
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",
"dev.gvisor.spec.mount." + testVolumeName + ".share": "container",
"dev.gvisor.spec.mount." + testVolumeName + ".type": "bind",
"dev.gvisor.spec.mount." + testVolumeName + ".options": "ro",
},
},
expected: &specs.Spec{
@@ -179,9 +179,9 @@ func TestUpdateVolumeAnnotations(t *testing.T) {
},
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",
"dev.gvisor.spec.mount." + testVolumeName + ".share": "container",
"dev.gvisor.spec.mount." + testVolumeName + ".type": "bind",
"dev.gvisor.spec.mount." + testVolumeName + ".options": "ro",
},
},
expectUpdate: true,
@@ -191,17 +191,17 @@ func TestUpdateVolumeAnnotations(t *testing.T) {
spec: &specs.Spec{
Annotations: map[string]string{
annotations.ContainerType: annotations.ContainerTypeSandbox,
"gvisor.dev/spec/mount/" + testVolumeName + "/share": "pod",
"gvisor.dev/spec/mount/" + testVolumeName + "/type": "tmpfs",
"gvisor.dev/spec/mount/" + testVolumeName + "/options": "ro",
"dev.gvisor.spec.mount." + testVolumeName + ".share": "pod",
"dev.gvisor.spec.mount." + testVolumeName + ".type": "tmpfs",
"dev.gvisor.spec.mount." + testVolumeName + ".options": "ro",
},
},
expected: &specs.Spec{
Annotations: map[string]string{
annotations.ContainerType: annotations.ContainerTypeSandbox,
"gvisor.dev/spec/mount/" + testVolumeName + "/share": "pod",
"gvisor.dev/spec/mount/" + testVolumeName + "/type": "tmpfs",
"gvisor.dev/spec/mount/" + testVolumeName + "/options": "ro",
"dev.gvisor.spec.mount." + testVolumeName + ".share": "pod",
"dev.gvisor.spec.mount." + testVolumeName + ".type": "tmpfs",
"dev.gvisor.spec.mount." + testVolumeName + ".options": "ro",
},
},
},
@@ -211,9 +211,9 @@ func TestUpdateVolumeAnnotations(t *testing.T) {
Annotations: map[string]string{
annotations.SandboxLogDir: testLogDirPath,
annotations.ContainerType: annotations.ContainerTypeSandbox,
"gvisor.dev/spec/mount/notexist/share": "pod",
"gvisor.dev/spec/mount/notexist/type": "tmpfs",
"gvisor.dev/spec/mount/notexist/options": "ro",
"dev.gvisor.spec.mount.notexist.share": "pod",
"dev.gvisor.spec.mount.notexist.type": "tmpfs",
"dev.gvisor.spec.mount.notexist.options": "ro",
},
},
expectErr: true,