Namespace "local" volume mounts by ContainerManifest ID on disk

Local volume mounts in a pod should result in host mounted directories
which are namespaced by the ContainerManifest ID.
pull/6/head
Dan Mace 2014-07-09 14:39:03 -04:00
parent 9408bd77ec
commit 00df67b0bf
2 changed files with 5 additions and 5 deletions

View File

@ -289,7 +289,7 @@ func makeEnvironmentVariables(container *api.Container) []string {
return result return result
} }
func makeVolumesAndBinds(container *api.Container) (map[string]struct{}, []string) { func makeVolumesAndBinds(manifestId string, container *api.Container) (map[string]struct{}, []string) {
volumes := map[string]struct{}{} volumes := map[string]struct{}{}
binds := []string{} binds := []string{}
for _, volume := range container.VolumeMounts { for _, volume := range container.VolumeMounts {
@ -299,7 +299,7 @@ func makeVolumesAndBinds(container *api.Container) (map[string]struct{}, []strin
basePath = fmt.Sprintf("%s:%s", volume.MountPath, volume.MountPath) basePath = fmt.Sprintf("%s:%s", volume.MountPath, volume.MountPath)
} else { } else {
volumes[volume.MountPath] = struct{}{} volumes[volume.MountPath] = struct{}{}
basePath = fmt.Sprintf("/exports/%s:%s", volume.Name, volume.MountPath) basePath = fmt.Sprintf("/exports/%s/%s:%s", manifestId, volume.Name, volume.MountPath)
} }
if volume.ReadOnly { if volume.ReadOnly {
basePath += ":ro" basePath += ":ro"
@ -364,7 +364,7 @@ func parseImageName(image string) (string, string) {
// Run a single container from a manifest. Returns the docker container ID // Run a single container from a manifest. Returns the docker container ID
func (kl *Kubelet) runContainer(manifest *api.ContainerManifest, container *api.Container, netMode string) (id DockerID, err error) { func (kl *Kubelet) runContainer(manifest *api.ContainerManifest, container *api.Container, netMode string) (id DockerID, err error) {
envVariables := makeEnvironmentVariables(container) envVariables := makeEnvironmentVariables(container)
volumes, binds := makeVolumesAndBinds(container) volumes, binds := makeVolumesAndBinds(manifest.ID, container)
exposedPorts, portBindings := makePortsAndBindings(container) exposedPorts, portBindings := makePortsAndBindings(container)
opts := docker.CreateContainerOptions{ opts := docker.CreateContainerOptions{

View File

@ -505,10 +505,10 @@ func TestMakeVolumesAndBinds(t *testing.T) {
}, },
}, },
} }
volumes, binds := makeVolumesAndBinds(&container) volumes, binds := makeVolumesAndBinds("pod", &container)
expectedVolumes := []string{"/mnt/path", "/mnt/path2"} expectedVolumes := []string{"/mnt/path", "/mnt/path2"}
expectedBinds := []string{"/exports/disk:/mnt/path", "/exports/disk2:/mnt/path2:ro", "/mnt/path3:/mnt/path3"} expectedBinds := []string{"/exports/pod/disk:/mnt/path", "/exports/pod/disk2:/mnt/path2:ro", "/mnt/path3:/mnt/path3"}
if len(volumes) != len(expectedVolumes) { if len(volumes) != len(expectedVolumes) {
t.Errorf("Unexpected volumes. Expected %#v got %#v. Container was: %#v", expectedVolumes, volumes, container) t.Errorf("Unexpected volumes. Expected %#v got %#v. Container was: %#v", expectedVolumes, volumes, container)
} }