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"`
|
||||
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
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -632,26 +632,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) {
|
||||
|
|
Loading…
Reference in New Issue