Create host path is mount source does not exist.

Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
Lantao Liu 2017-09-12 00:58:34 +00:00
parent 9558ff2001
commit 6cd0f77c4e

View File

@ -18,6 +18,7 @@ package server
import ( import (
"fmt" "fmt"
"os"
"strings" "strings"
"time" "time"
@ -484,6 +485,16 @@ func addOCIBindMounts(g *generate.Generator, mounts []*runtime.Mount, mountLabel
for _, mount := range mounts { for _, mount := range mounts {
dst := mount.GetContainerPath() dst := mount.GetContainerPath()
src := mount.GetHostPath() src := mount.GetHostPath()
// Create the host path if it doesn't exist.
// TODO(random-liu): Add CRI validation test for this case.
if _, err := os.Stat(src); err != nil {
if !os.IsNotExist(err) {
return fmt.Errorf("failed to stat %q: %v", src, err)
}
if err := os.MkdirAll(src, 0755); err != nil {
return fmt.Errorf("failed to mkdir %q: %v", src, err)
}
}
options := []string{"rbind"} options := []string{"rbind"}
switch mount.GetPropagation() { switch mount.GetPropagation() {
case runtime.MountPropagation_PROPAGATION_PRIVATE: case runtime.MountPropagation_PROPAGATION_PRIVATE: