From 2a9e9b2425b5fd87dc533c8566f24ec79bbefa04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Mon, 20 Jul 2020 21:50:13 +0200 Subject: [PATCH] Make sure to prepare the kic volume after creation The volume is created as empty, so make sure that we run a container to do the initial copy of /var from the image. This is to avoid race conditions later on, where the preload starts to use the created volume for packing up the tarball. --- pkg/drivers/kic/oci/oci.go | 4 ++++ pkg/drivers/kic/oci/volumes.go | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/pkg/drivers/kic/oci/oci.go b/pkg/drivers/kic/oci/oci.go index 3ef6a94cfb..e66b76597c 100644 --- a/pkg/drivers/kic/oci/oci.go +++ b/pkg/drivers/kic/oci/oci.go @@ -99,6 +99,10 @@ func PrepareContainerNode(p CreateParams) error { return errors.Wrapf(err, "creating volume for %s container", p.Name) } glog.Infof("Successfully created a %s volume %s", p.OCIBinary, p.Name) + if err := prepareVolume(p.OCIBinary, p.Image, p.Name); err != nil { + return errors.Wrapf(err, "preparing volume for %s container", p.Name) + } + glog.Infof("Successfully prepared a %s volume %s", p.OCIBinary, p.Name) return nil } diff --git a/pkg/drivers/kic/oci/volumes.go b/pkg/drivers/kic/oci/volumes.go index f3fb62d13a..f43007ec7b 100644 --- a/pkg/drivers/kic/oci/volumes.go +++ b/pkg/drivers/kic/oci/volumes.go @@ -106,3 +106,14 @@ func createVolume(ociBin string, profile string, nodeName string) error { } return nil } + +// prepareVolume will copy the initial content of the mount point by starting a container to check the expected content +func prepareVolume(ociBin string, imageName string, nodeName string) error { + cmdArgs := []string{"run", "--rm", "--entrypoint", "/usr/bin/test"} + cmdArgs = append(cmdArgs, "-v", fmt.Sprintf("%s:/var", nodeName), imageName, "-d", "/var/lib") + cmd := exec.Command(ociBin, cmdArgs...) + if _, err := runCmd(cmd); err != nil { + return err + } + return nil +} \ No newline at end of file