mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Merge pull request #383 from ironcladlou/namespace-local-mounts
Namespace "local" volume mounts by ContainerManifest ID on disk
This commit is contained in:
commit
809708ee6b
@ -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{
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user