summaryrefslogtreecommitdiffhomepage
path: root/pkg/v1
diff options
context:
space:
mode:
authorFabricio Voznika <fvoznika@google.com>2019-12-05 16:36:24 -0800
committerGitHub <noreply@github.com>2019-12-05 16:36:24 -0800
commite83ba107367ac3a25725d8857c2ba3cc9adbeb71 (patch)
tree1f5251266af09d1a5733b7f1ad0a806e566f47d3 /pkg/v1
parent757adfa287c17d925aec7976a86986bd5b52229c (diff)
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'.
Diffstat (limited to 'pkg/v1')
-rw-r--r--pkg/v1/utils/volumes.go12
-rw-r--r--pkg/v1/utils/volumes_test.go70
2 files changed, 41 insertions, 41 deletions
diff --git a/pkg/v1/utils/volumes.go b/pkg/v1/utils/volumes.go
index 02a70a8b6..61adeaa54 100644
--- a/pkg/v1/utils/volumes.go
+++ b/pkg/v1/utils/volumes.go
@@ -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.
diff --git a/pkg/v1/utils/volumes_test.go b/pkg/v1/utils/volumes_test.go
index 8a6a30ef1..472cd6e86 100644
--- a/pkg/v1/utils/volumes_test.go
+++ b/pkg/v1/utils/volumes_test.go
@@ -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,