From 6cd0f77c4e53457323b2db96e7ecc869d807e06b Mon Sep 17 00:00:00 2001 From: Lantao Liu Date: Tue, 12 Sep 2017 00:58:34 +0000 Subject: [PATCH] Create host path is mount source does not exist. Signed-off-by: Lantao Liu --- pkg/server/container_create.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/server/container_create.go b/pkg/server/container_create.go index 80ff32bec..d76644df8 100644 --- a/pkg/server/container_create.go +++ b/pkg/server/container_create.go @@ -18,6 +18,7 @@ package server import ( "fmt" + "os" "strings" "time" @@ -484,6 +485,16 @@ func addOCIBindMounts(g *generate.Generator, mounts []*runtime.Mount, mountLabel for _, mount := range mounts { dst := mount.GetContainerPath() 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"} switch mount.GetPropagation() { case runtime.MountPropagation_PROPAGATION_PRIVATE: