mirror of https://github.com/k3s-io/k3s
Merge pull request #178 from vmarmol/add-external-mounts
Adding support for external mountspull/6/head
commit
168ec29f54
|
@ -45,6 +45,8 @@ type VolumeMount struct {
|
||||||
Name string `yaml:"name,omitempty" json:"name,omitempty"`
|
Name string `yaml:"name,omitempty" json:"name,omitempty"`
|
||||||
ReadOnly bool `yaml:"readOnly,omitempty" json:"readOnly,omitempty"`
|
ReadOnly bool `yaml:"readOnly,omitempty" json:"readOnly,omitempty"`
|
||||||
MountPath string `yaml:"mountPath,omitempty" json:"mountPath,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
|
// EnvVar represents an environment variable present in a Container
|
||||||
|
|
|
@ -255,8 +255,14 @@ func makeVolumesAndBinds(container *api.Container) (map[string]struct{}, []strin
|
||||||
volumes := map[string]struct{}{}
|
volumes := map[string]struct{}{}
|
||||||
binds := []string{}
|
binds := []string{}
|
||||||
for _, volume := range container.VolumeMounts {
|
for _, volume := range container.VolumeMounts {
|
||||||
volumes[volume.MountPath] = struct{}{}
|
var basePath string
|
||||||
basePath := "/exports/" + volume.Name + ":" + volume.MountPath
|
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 {
|
if volume.ReadOnly {
|
||||||
basePath += ":ro"
|
basePath += ":ro"
|
||||||
}
|
}
|
||||||
|
|
|
@ -632,26 +632,32 @@ func TestMakeVolumesAndBinds(t *testing.T) {
|
||||||
MountPath: "/mnt/path2",
|
MountPath: "/mnt/path2",
|
||||||
Name: "disk2",
|
Name: "disk2",
|
||||||
ReadOnly: true,
|
ReadOnly: true,
|
||||||
|
MountType: "LOCAL",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MountPath: "/mnt/path3",
|
||||||
|
Name: "disk3",
|
||||||
|
ReadOnly: false,
|
||||||
|
MountType: "HOST",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
volumes, binds := makeVolumesAndBinds(&container)
|
volumes, binds := makeVolumesAndBinds(&container)
|
||||||
if len(volumes) != len(container.VolumeMounts) ||
|
|
||||||
len(binds) != len(container.VolumeMounts) {
|
expectedVolumes := []string{"/mnt/path", "/mnt/path2"}
|
||||||
t.Errorf("Unexpected volumes and binds: %#v %#v. Container was: %#v", volumes, binds, container)
|
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 {
|
for _, expectedVolume := range expectedVolumes {
|
||||||
expectedBind := "/exports/" + volume.Name + ":" + volume.MountPath
|
if _, ok := volumes[expectedVolume]; !ok {
|
||||||
if volume.ReadOnly {
|
t.Errorf("Volumes map is missing key: %s. %#v", expectedVolume, volumes)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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) {
|
func TestMakePortsAndBindings(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue