Skip to content

Commit 06c65e8

Browse files
author
OpenShift Bot
authored
Merge pull request #15088 from csrwng/clusterup_host_volumedir
Merged by openshift-bot
2 parents 83efc33 + 71a9ca3 commit 06c65e8

File tree

1 file changed

+16
-38
lines changed

1 file changed

+16
-38
lines changed

pkg/bootstrap/docker/host/host.go

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ for dir in %s; do
2222
fi
2323
done
2424
`
25-
cmdCreateVolumesDirBindMount = "grep /var/lib/origin /rootfs/proc/1/mountinfo || " +
26-
"nsenter --mount=/rootfs/proc/1/ns/mnt mount -o bind %[1]s %[1]s"
27-
cmdCreateVolumesDirShare = "grep %[1]s /rootfs/proc/1/mountinfo | grep shared || " +
28-
"nsenter --mount=/rootfs/proc/1/ns/mnt mount --make-shared %[1]s"
25+
ensureVolumeShareCmd = `#/bin/bash
26+
nsenter --mount=/rootfs/proc/1/ns/mnt mkdir -p %[1]s
27+
grep -F %[1]s /rootfs/proc/1/mountinfo || nsenter --mount=/rootfs/proc/1/ns/mnt mount -o bind %[1]s %[1]s
28+
grep -F %[1]s /rootfs/proc/1/mountinfo | grep shared || nsenter --mount=/rootfs/proc/1/ns/mnt mount --make-shared %[1]s
29+
`
2930

3031
DefaultVolumesDir = "/var/lib/origin/openshift.local.volumes"
3132
DefaultConfigDir = "/var/lib/origin/openshift.local.config"
@@ -72,11 +73,17 @@ func (h *HostHelper) CanUseNsenterMounter() (bool, error) {
7273
// EnsureVolumeShare ensures that the host Docker machine has a shared directory that can be used
7374
// for OpenShift volumes
7475
func (h *HostHelper) EnsureVolumeShare() error {
75-
if err := h.ensureVolumesDirBindMount(); err != nil {
76-
return err
77-
}
78-
if err := h.ensureVolumesDirShare(); err != nil {
79-
return err
76+
cmd := fmt.Sprintf(ensureVolumeShareCmd, h.volumesDir)
77+
rc, err := h.runner().
78+
Image(h.image).
79+
DiscardContainer().
80+
HostPid().
81+
Privileged().
82+
Bind("/proc:/rootfs/proc:ro").
83+
Entrypoint("/bin/bash").
84+
Command("-c", cmd).Run()
85+
if err != nil || rc != 0 {
86+
return errors.NewError("cannot create volume share").WithCause(err)
8087
}
8188
return nil
8289
}
@@ -178,35 +185,6 @@ func (h *HostHelper) EnsureHostDirectories(createVolumeShare bool) error {
178185
return nil
179186
}
180187

181-
func (h *HostHelper) hostPidCmd(cmd string) (int, error) {
182-
return h.runner().
183-
Image(h.image).
184-
DiscardContainer().
185-
HostPid().
186-
Privileged().
187-
Bind("/proc:/rootfs/proc:ro").
188-
Entrypoint("/bin/bash").
189-
Command("-c", cmd).Run()
190-
}
191-
192-
func (h *HostHelper) ensureVolumesDirBindMount() error {
193-
cmd := fmt.Sprintf(cmdCreateVolumesDirBindMount, h.volumesDir)
194-
rc, err := h.hostPidCmd(cmd)
195-
if err != nil || rc != 0 {
196-
return errors.NewError("cannot create volumes dir mount").WithCause(err)
197-
}
198-
return nil
199-
}
200-
201-
func (h *HostHelper) ensureVolumesDirShare() error {
202-
cmd := fmt.Sprintf(cmdCreateVolumesDirShare, h.volumesDir)
203-
rc, err := h.hostPidCmd(cmd)
204-
if err != nil || rc != 0 {
205-
return errors.NewError("cannot create volumes dir share").WithCause(err)
206-
}
207-
return nil
208-
}
209-
210188
func (h *HostHelper) runner() *run.Runner {
211189
return h.runHelper.New()
212190
}

0 commit comments

Comments
 (0)