From e794f539d8cc4ededd7d014b84ceeffabb7b4293 Mon Sep 17 00:00:00 2001 From: Victor Marmol Date: Thu, 19 Jun 2014 16:59:48 -0700 Subject: [PATCH] Adding support for external mounts --- pkg/api/types.go | 2 ++ pkg/kubelet/kubelet.go | 10 ++++++++-- pkg/kubelet/kubelet_test.go | 32 +++++++++++++++++++------------- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/pkg/api/types.go b/pkg/api/types.go index 29a71cde7c..2c1be46f52 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -45,6 +45,8 @@ type VolumeMount struct { Name string `yaml:"name,omitempty" json:"name,omitempty"` ReadOnly bool `yaml:"readOnly,omitempty" json:"readOnly,omitempty"` MountPath string `yaml:"mountPath,omitempty" json:"mountPath,omitempty"` + // One of: "LOCAL" (local volume) or "HOST" (external mount from the host). Default: LOCAL. + MountType string `yaml:"mountType,omitempty" json:"mountType,omitempty"` } // EnvVar represents an environment variable present in a Container diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index 620c99df7e..1a25e269c8 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -255,8 +255,14 @@ func makeVolumesAndBinds(container *api.Container) (map[string]struct{}, []strin volumes := map[string]struct{}{} binds := []string{} for _, volume := range container.VolumeMounts { - volumes[volume.MountPath] = struct{}{} - basePath := "/exports/" + volume.Name + ":" + volume.MountPath + var basePath string + if volume.MountType == "HOST" { + // Host volumes are not Docker volumes and are directly mounted from the host. + basePath = fmt.Sprintf("%s:%s", volume.MountPath, volume.MountPath) + } else { + volumes[volume.MountPath] = struct{}{} + basePath = fmt.Sprintf("/exports/%s:%s", volume.Name, volume.MountPath) + } if volume.ReadOnly { basePath += ":ro" } diff --git a/pkg/kubelet/kubelet_test.go b/pkg/kubelet/kubelet_test.go index 6eea97987e..6c7a1955b3 100644 --- a/pkg/kubelet/kubelet_test.go +++ b/pkg/kubelet/kubelet_test.go @@ -644,26 +644,32 @@ func TestMakeVolumesAndBinds(t *testing.T) { MountPath: "/mnt/path2", Name: "disk2", ReadOnly: true, + MountType: "LOCAL", + }, + { + MountPath: "/mnt/path3", + Name: "disk3", + ReadOnly: false, + MountType: "HOST", }, }, } volumes, binds := makeVolumesAndBinds(&container) - if len(volumes) != len(container.VolumeMounts) || - len(binds) != len(container.VolumeMounts) { - t.Errorf("Unexpected volumes and binds: %#v %#v. Container was: %#v", volumes, binds, container) + + expectedVolumes := []string{"/mnt/path", "/mnt/path2"} + expectedBinds := []string{"/exports/disk:/mnt/path", "/exports/disk2:/mnt/path2:ro", "/mnt/path3:/mnt/path3"} + if len(volumes) != len(expectedVolumes) { + t.Errorf("Unexpected volumes. Expected %#v got %#v. Container was: %#v", expectedVolumes, volumes, container) } - for ix, volume := range container.VolumeMounts { - expectedBind := "/exports/" + volume.Name + ":" + volume.MountPath - if volume.ReadOnly { - expectedBind = expectedBind + ":ro" - } - if binds[ix] != expectedBind { - t.Errorf("Unexpected bind. Expected %s. Found %s", expectedBind, binds[ix]) - } - if _, ok := volumes[volume.MountPath]; !ok { - t.Errorf("Map is missing key: %s. %#v", volume.MountPath, volumes) + for _, expectedVolume := range expectedVolumes { + if _, ok := volumes[expectedVolume]; !ok { + t.Errorf("Volumes map is missing key: %s. %#v", expectedVolume, volumes) } } + if len(binds) != len(expectedBinds) { + t.Errorf("Unexpected binds: Expected %# got %#v. Container was: %#v", expectedBinds, binds, container) + } + verifyStringArrayEquals(t, binds, expectedBinds) } func TestMakePortsAndBindings(t *testing.T) {