@@ -49,8 +49,10 @@ pub struct Service {
4949}
5050
5151impl Service {
52- pub async fn new ( endpoint : String ) -> Result < Self , Err > {
53- let client = Client :: from_path ( endpoint) . await . unwrap ( ) ;
52+ pub async fn new ( ) -> Result < Self , Err > {
53+ let client = Client :: from_path ( "/run/containerd/containerd.sock" )
54+ . await
55+ . unwrap ( ) ;
5456 Ok ( Service {
5557 client : Arc :: new ( client) ,
5658 netns_map : GLOBAL_NETNS_MAP . clone ( ) ,
@@ -73,8 +75,13 @@ impl Service {
7375 map. remove ( cid) ;
7476 }
7577
76- async fn prepare_snapshot ( & self , cid : & str , ns : & str ) -> Result < Vec < Mount > , Err > {
77- let parent_snapshot = self . get_parent_snapshot ( cid, ns) . await ?;
78+ async fn prepare_snapshot (
79+ & self ,
80+ cid : & str ,
81+ ns : & str ,
82+ img_name : & str ,
83+ ) -> Result < Vec < Mount > , Err > {
84+ let parent_snapshot = self . get_parent_snapshot ( img_name, ns) . await ?;
7885 let req = PrepareSnapshotRequest {
7986 snapshotter : "overlayfs" . to_string ( ) ,
8087 key : cid. to_string ( ) ,
@@ -98,7 +105,7 @@ impl Service {
98105 _ => ns,
99106 } ;
100107
101- let _mount = self . prepare_snapshot ( cid, ns) . await ?;
108+ let _mount = self . prepare_snapshot ( cid, ns, image_name ) . await ?;
102109 let ( env, args) = self . get_env_and_args ( image_name, ns) . await ?;
103110 let spec_path = generate_spec ( cid, ns, args, env) . unwrap ( ) ;
104111 let spec = fs:: read_to_string ( spec_path) . unwrap ( ) ;
@@ -548,19 +555,19 @@ impl Service {
548555 :: serde_json:: from_slice ( & resp) . unwrap ( )
549556 }
550557
551- pub async fn get_img_config ( & self , name : & str , ns : & str ) -> Option < ImageConfiguration > {
558+ pub async fn get_img_config ( & self , img_name : & str , ns : & str ) -> Option < ImageConfiguration > {
552559 let mut c = self . client . images ( ) ;
553560
554561 let req = GetImageRequest {
555- name : name . to_string ( ) ,
562+ name : img_name . to_string ( ) ,
556563 } ;
557564 let resp = c
558565 . get ( with_namespace ! ( req, ns) )
559566 . await
560567 . map_err ( |e| {
561568 eprintln ! (
562569 "Failed to get the config of {} in namespace {}: {}" ,
563- name , ns, e
570+ img_name , ns, e
564571 ) ;
565572 e
566573 } )
@@ -583,7 +590,7 @@ impl Service {
583590 . map_err ( |e| {
584591 eprintln ! (
585592 "Failed to read content for {} in namespace {}: {}" ,
586- name , ns, e
593+ img_name , ns, e
587594 ) ;
588595 e
589596 } )
@@ -594,13 +601,13 @@ impl Service {
594601 . map_err ( |e| {
595602 eprintln ! (
596603 "Failed to read message for {} in namespace {}: {}" ,
597- name , ns, e
604+ img_name , ns, e
598605 ) ;
599606 e
600607 } )
601608 . ok ( ) ?
602609 . ok_or_else ( || {
603- eprintln ! ( "No data found for {} in namespace {}" , name , ns) ;
610+ eprintln ! ( "No data found for {} in namespace {}" , img_name , ns) ;
604611 std:: io:: Error :: new ( std:: io:: ErrorKind :: NotFound , "No data found" )
605612 } )
606613 . ok ( ) ?
@@ -629,8 +636,8 @@ impl Service {
629636 Some ( img_config)
630637 }
631638
632- async fn get_parent_snapshot ( & self , name : & str , ns : & str ) -> Result < String , Err > {
633- let img_config = self . get_img_config ( name , ns) . await . unwrap ( ) ;
639+ async fn get_parent_snapshot ( & self , img_name : & str , ns : & str ) -> Result < String , Err > {
640+ let img_config = self . get_img_config ( img_name , ns) . await . unwrap ( ) ;
634641
635642 let mut iter = img_config. rootfs ( ) . diff_ids ( ) . iter ( ) ;
636643 let mut ret = iter
0 commit comments