Skip to content

Commit

Permalink
Merge pull request #15088 from csrwng/clusterup_host_volumedir
Browse files Browse the repository at this point in the history
Merged by openshift-bot
  • Loading branch information
OpenShift Bot authored Jul 7, 2017
2 parents 83efc33 + 71a9ca3 commit 06c65e8
Showing 1 changed file with 16 additions and 38 deletions.
54 changes: 16 additions & 38 deletions pkg/bootstrap/docker/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ for dir in %s; do
fi
done
`
cmdCreateVolumesDirBindMount = "grep /var/lib/origin /rootfs/proc/1/mountinfo || " +
"nsenter --mount=/rootfs/proc/1/ns/mnt mount -o bind %[1]s %[1]s"
cmdCreateVolumesDirShare = "grep %[1]s /rootfs/proc/1/mountinfo | grep shared || " +
"nsenter --mount=/rootfs/proc/1/ns/mnt mount --make-shared %[1]s"
ensureVolumeShareCmd = `#/bin/bash
nsenter --mount=/rootfs/proc/1/ns/mnt mkdir -p %[1]s
grep -F %[1]s /rootfs/proc/1/mountinfo || nsenter --mount=/rootfs/proc/1/ns/mnt mount -o bind %[1]s %[1]s
grep -F %[1]s /rootfs/proc/1/mountinfo | grep shared || nsenter --mount=/rootfs/proc/1/ns/mnt mount --make-shared %[1]s
`

DefaultVolumesDir = "/var/lib/origin/openshift.local.volumes"
DefaultConfigDir = "/var/lib/origin/openshift.local.config"
Expand Down Expand Up @@ -72,11 +73,17 @@ func (h *HostHelper) CanUseNsenterMounter() (bool, error) {
// EnsureVolumeShare ensures that the host Docker machine has a shared directory that can be used
// for OpenShift volumes
func (h *HostHelper) EnsureVolumeShare() error {
if err := h.ensureVolumesDirBindMount(); err != nil {
return err
}
if err := h.ensureVolumesDirShare(); err != nil {
return err
cmd := fmt.Sprintf(ensureVolumeShareCmd, h.volumesDir)
rc, err := h.runner().
Image(h.image).
DiscardContainer().
HostPid().
Privileged().
Bind("/proc:/rootfs/proc:ro").
Entrypoint("/bin/bash").
Command("-c", cmd).Run()
if err != nil || rc != 0 {
return errors.NewError("cannot create volume share").WithCause(err)
}
return nil
}
Expand Down Expand Up @@ -178,35 +185,6 @@ func (h *HostHelper) EnsureHostDirectories(createVolumeShare bool) error {
return nil
}

func (h *HostHelper) hostPidCmd(cmd string) (int, error) {
return h.runner().
Image(h.image).
DiscardContainer().
HostPid().
Privileged().
Bind("/proc:/rootfs/proc:ro").
Entrypoint("/bin/bash").
Command("-c", cmd).Run()
}

func (h *HostHelper) ensureVolumesDirBindMount() error {
cmd := fmt.Sprintf(cmdCreateVolumesDirBindMount, h.volumesDir)
rc, err := h.hostPidCmd(cmd)
if err != nil || rc != 0 {
return errors.NewError("cannot create volumes dir mount").WithCause(err)
}
return nil
}

func (h *HostHelper) ensureVolumesDirShare() error {
cmd := fmt.Sprintf(cmdCreateVolumesDirShare, h.volumesDir)
rc, err := h.hostPidCmd(cmd)
if err != nil || rc != 0 {
return errors.NewError("cannot create volumes dir share").WithCause(err)
}
return nil
}

func (h *HostHelper) runner() *run.Runner {
return h.runHelper.New()
}

0 comments on commit 06c65e8

Please sign in to comment.