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.
pull/8777/head
Anders F Björklund 2020-07-20 21:50:13 +02:00
parent bf38785070
commit 2a9e9b2425
2 changed files with 15 additions and 0 deletions

View File

@ -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
}

View File

@ -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
}