@@ -22,10 +22,11 @@ for dir in %s; do
22
22
fi
23
23
done
24
24
`
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
+ `
29
30
30
31
DefaultVolumesDir = "/var/lib/origin/openshift.local.volumes"
31
32
DefaultConfigDir = "/var/lib/origin/openshift.local.config"
@@ -72,11 +73,17 @@ func (h *HostHelper) CanUseNsenterMounter() (bool, error) {
72
73
// EnsureVolumeShare ensures that the host Docker machine has a shared directory that can be used
73
74
// for OpenShift volumes
74
75
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 )
80
87
}
81
88
return nil
82
89
}
@@ -178,35 +185,6 @@ func (h *HostHelper) EnsureHostDirectories(createVolumeShare bool) error {
178
185
return nil
179
186
}
180
187
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
-
210
188
func (h * HostHelper ) runner () * run.Runner {
211
189
return h .runHelper .New ()
212
190
}
0 commit comments