agent/image: export the image service singleton instance

Export the image service singleton instance.

Signed-off-by: Jiang Liu <gerry@linux.alibaba.com>
This commit is contained in:
Jiang Liu
2023-08-12 11:02:50 +08:00
parent 624d3c063a
commit 81980388d4
2 changed files with 14 additions and 5 deletions

View File

@@ -36,14 +36,20 @@ const KATA_CC_IMAGE_WORK_DIR: &str = "/run/image/";
const KATA_CC_PAUSE_BUNDLE: &str = "/pause_bundle";
const CONFIG_JSON: &str = "config.json";
#[rustfmt::skip]
lazy_static! {
pub static ref IMAGE_SERVICE: Mutex<Option<ImageService>> = Mutex::new(None);
}
// Convenience function to obtain the scope logger.
fn sl() -> slog::Logger {
slog_scope::logger().new(o!("subsystem" => "cgroups"))
}
#[derive(Clone)]
pub struct ImageService {
sandbox: Arc<Mutex<Sandbox>>,
attestation_agent_started: AtomicBool,
attestation_agent_started: Arc<AtomicBool>,
image_client: Arc<Mutex<ImageClient>>,
container_count: Arc<AtomicU16>,
}
@@ -67,7 +73,7 @@ impl ImageService {
Self {
sandbox,
attestation_agent_started: AtomicBool::new(false),
attestation_agent_started: Arc::new(AtomicBool::new(false)),
image_client: Arc::new(Mutex::new(image_client)),
container_count: Arc::new(AtomicU16::new(0)),
}

View File

@@ -207,7 +207,8 @@ impl AgentService {
"receive createcontainer, storages: {:?}", &req.storages
);
// Merge the image bundle OCI spec into the container creation request OCI spec.
// In case of pulling image inside guest, we need to merge the image bundle OCI spec
// into the container creation request OCI spec.
self.merge_bundle_oci(&mut oci).await?;
// Some devices need some extra processing (the ones invoked with
@@ -1773,9 +1774,11 @@ pub async fn start(
let health_service = Box::new(HealthService {}) as Box<dyn health_ttrpc::Health + Send + Sync>;
let hservice = health_ttrpc::create_health(Arc::new(health_service));
let image_service = image_rpc::ImageService::new(s);
*image_rpc::IMAGE_SERVICE.lock().await = Some(image_service.clone());
let image_service =
Box::new(image_rpc::ImageService::new(s)) as Box<dyn image_ttrpc::Image + Send + Sync>;
let iservice = image_ttrpc::create_image(Arc::new(image_service));
Arc::new(Box::new(image_service) as Box<dyn image_ttrpc::Image + Send + Sync>);
let iservice = image_ttrpc::create_image(image_service);
let server = TtrpcServer::new()
.bind(server_address)?