diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 3669bcb..84977b7 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -11,7 +11,7 @@ use handlers::*; #[actix_web::main] async fn main() -> std::io::Result<()> { let service = Arc::new( - Service::new("/run/containerd/containerd.sock".to_string()) + Service::new("/run/containerd/containerd.sock") .await .unwrap(), ); diff --git a/crates/service/src/lib.rs b/crates/service/src/lib.rs index dd1b351..89cea62 100644 --- a/crates/service/src/lib.rs +++ b/crates/service/src/lib.rs @@ -49,8 +49,8 @@ pub struct Service { } impl Service { - pub async fn new(endpoint: String) -> Result { - let client = Client::from_path(endpoint).await.unwrap(); + pub async fn new(socket_path: &str) -> Result { + let client = Client::from_path(socket_path).await.unwrap(); Ok(Service { client: Arc::new(client), netns_map: GLOBAL_NETNS_MAP.clone(), @@ -73,8 +73,13 @@ impl Service { map.remove(cid); } - async fn prepare_snapshot(&self, cid: &str, ns: &str) -> Result, Err> { - let parent_snapshot = self.get_parent_snapshot(cid, ns).await?; + async fn prepare_snapshot( + &self, + cid: &str, + ns: &str, + img_name: &str, + ) -> Result, Err> { + let parent_snapshot = self.get_parent_snapshot(img_name, ns).await?; let req = PrepareSnapshotRequest { snapshotter: "overlayfs".to_string(), key: cid.to_string(), @@ -98,7 +103,7 @@ impl Service { _ => ns, }; - let _mount = self.prepare_snapshot(cid, ns).await?; + let _mount = self.prepare_snapshot(cid, ns, image_name).await?; let (env, args) = self.get_env_and_args(image_name, ns).await?; let spec_path = generate_spec(cid, ns, args, env).unwrap(); let spec = fs::read_to_string(spec_path).unwrap(); @@ -548,11 +553,11 @@ impl Service { ::serde_json::from_slice(&resp).unwrap() } - pub async fn get_img_config(&self, name: &str, ns: &str) -> Option { + pub async fn get_img_config(&self, img_name: &str, ns: &str) -> Option { let mut c = self.client.images(); let req = GetImageRequest { - name: name.to_string(), + name: img_name.to_string(), }; let resp = c .get(with_namespace!(req, ns)) @@ -560,7 +565,7 @@ impl Service { .map_err(|e| { eprintln!( "Failed to get the config of {} in namespace {}: {}", - name, ns, e + img_name, ns, e ); e }) @@ -583,7 +588,7 @@ impl Service { .map_err(|e| { eprintln!( "Failed to read content for {} in namespace {}: {}", - name, ns, e + img_name, ns, e ); e }) @@ -594,13 +599,13 @@ impl Service { .map_err(|e| { eprintln!( "Failed to read message for {} in namespace {}: {}", - name, ns, e + img_name, ns, e ); e }) .ok()? .ok_or_else(|| { - eprintln!("No data found for {} in namespace {}", name, ns); + eprintln!("No data found for {} in namespace {}", img_name, ns); std::io::Error::new(std::io::ErrorKind::NotFound, "No data found") }) .ok()? @@ -629,8 +634,11 @@ impl Service { Some(img_config) } - async fn get_parent_snapshot(&self, name: &str, ns: &str) -> Result { - let img_config = self.get_img_config(name, ns).await.unwrap(); + async fn get_parent_snapshot(&self, img_name: &str, ns: &str) -> Result { + let img_config = match self.get_img_config(img_name, ns).await { + Some(config) => config, + None => return Err("Failed to get image configuration".into()), + }; let mut iter = img_config.rootfs().diff_ids().iter(); let mut ret = iter