From 05cd1cc7a010d789ba6b2f6659a97e72e3fc11cd Mon Sep 17 00:00:00 2001 From: stevenhorsman Date: Wed, 15 Sep 2021 18:04:41 +0100 Subject: [PATCH] agent: Add CreateContainer support for pre-pulled bundle - Add a check in setup_bundle to see if the bundle already exists and if it does then skip the setup. This commit is cherry-picked from https://github.com/kata-containers/kata-containers/commit/44ed3ab80ee13413815d07f6a80a6e92fe3e8a93. The reason that k8s-kill-all-process-in-container.bats failed is that deletion of the directory `/root/kata-containers/cid/rootfs` failed during removing container because it was mounted twice (one in image-rs and one in set_bundle ) and only unmounted once in removing container. Fixes: #9664 Signed-off-by: ChengyuZhu6 Co-authored-by: Dave Hay Signed-off-by: stevenhorsman --- src/agent/src/rpc.rs | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/agent/src/rpc.rs b/src/agent/src/rpc.rs index aa598bc7ca..16d7d1137a 100644 --- a/src/agent/src/rpc.rs +++ b/src/agent/src/rpc.rs @@ -1926,15 +1926,23 @@ pub fn setup_bundle(cid: &str, spec: &mut Spec) -> Result { let config_path = bundle_path.join("config.json"); let rootfs_path = bundle_path.join("rootfs"); - fs::create_dir_all(&rootfs_path)?; - baremount( - spec_root_path, - &rootfs_path, - "bind", - MsFlags::MS_BIND, - "", - &sl(), - )?; + let rootfs_exists = Path::new(&rootfs_path).exists(); + info!( + sl(), + "The rootfs_path is {:?} and exists: {}", rootfs_path, rootfs_exists + ); + + if !rootfs_exists { + fs::create_dir_all(&rootfs_path)?; + baremount( + spec_root_path, + &rootfs_path, + "bind", + MsFlags::MS_BIND, + "", + &sl(), + )?; + } let rootfs_path_name = rootfs_path .to_str()