mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-31 16:36:38 +00:00
agent: export the image service singleton instance
Export the image service singleton instance. Signed-off-by: ChengyuZhu6 <chengyu.zhu@intel.com> Co-authored-by: Jiang Liu <gerry@linux.alibaba.com> Co-authored-by: Xynnn007 <xynnn@linux.alibaba.com> Co-authored-by: stevenhorsman <steven@uk.ibm.com> Co-authored-by: wllenyj <wllenyj@linux.alibaba.com>
This commit is contained in:
committed by
Fabiano Fidêncio
parent
1f1ca6187d
commit
2b3a00f848
@@ -5,20 +5,32 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
//
|
//
|
||||||
|
|
||||||
use std::sync::Arc;
|
use anyhow::{anyhow, Result};
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
use crate::sandbox::Sandbox;
|
|
||||||
|
#[rustfmt::skip]
|
||||||
|
lazy_static! {
|
||||||
|
pub static ref IMAGE_SERVICE: Mutex<Option<ImageService>> = Mutex::new(None);
|
||||||
|
}
|
||||||
|
|
||||||
// Convenience function to obtain the scope logger.
|
// Convenience function to obtain the scope logger.
|
||||||
fn sl() -> slog::Logger {
|
fn sl() -> slog::Logger {
|
||||||
slog_scope::logger().new(o!("subsystem" => "image"))
|
slog_scope::logger().new(o!("subsystem" => "image"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ImageService {
|
#[derive(Clone)]
|
||||||
sandbox: Arc<Mutex<Sandbox>>,
|
pub struct ImageService {}
|
||||||
}
|
|
||||||
impl ImageService {
|
impl ImageService {
|
||||||
pub fn new(sandbox: Arc<Mutex<Sandbox>>) -> Self {
|
pub fn new() -> Self {
|
||||||
Self { sandbox }
|
Self {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the singleton instance of image service.
|
||||||
|
pub async fn singleton() -> Result<ImageService> {
|
||||||
|
IMAGE_SERVICE
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.clone()
|
||||||
|
.ok_or_else(|| anyhow!("image service is uninitialized"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -380,7 +380,7 @@ async fn start_sandbox(
|
|||||||
sandbox.lock().await.sender = Some(tx);
|
sandbox.lock().await.sender = Some(tx);
|
||||||
|
|
||||||
// vsock:///dev/vsock, port
|
// vsock:///dev/vsock, port
|
||||||
let mut server = rpc::start(sandbox.clone(), config.server_addr.as_str(), init_mode)?;
|
let mut server = rpc::start(sandbox.clone(), config.server_addr.as_str(), init_mode).await?;
|
||||||
server.start().await?;
|
server.start().await?;
|
||||||
|
|
||||||
rx.await?;
|
rx.await?;
|
||||||
|
@@ -1584,7 +1584,11 @@ async fn read_stream(reader: &Mutex<ReadHalf<PipeStream>>, l: usize) -> Result<V
|
|||||||
Ok(content)
|
Ok(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start(s: Arc<Mutex<Sandbox>>, server_address: &str, init_mode: bool) -> Result<TtrpcServer> {
|
pub async fn start(
|
||||||
|
s: Arc<Mutex<Sandbox>>,
|
||||||
|
server_address: &str,
|
||||||
|
init_mode: bool,
|
||||||
|
) -> Result<TtrpcServer> {
|
||||||
let agent_service = Box::new(AgentService {
|
let agent_service = Box::new(AgentService {
|
||||||
sandbox: s,
|
sandbox: s,
|
||||||
init_mode,
|
init_mode,
|
||||||
@@ -1594,6 +1598,9 @@ pub fn start(s: Arc<Mutex<Sandbox>>, server_address: &str, init_mode: bool) -> R
|
|||||||
let health_service = Box::new(HealthService {}) as Box<dyn health_ttrpc::Health + Send + Sync>;
|
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 hservice = health_ttrpc::create_health(Arc::new(health_service));
|
||||||
|
|
||||||
|
let image_service = image::ImageService::new();
|
||||||
|
*image::IMAGE_SERVICE.lock().await = Some(image_service.clone());
|
||||||
|
|
||||||
let server = TtrpcServer::new()
|
let server = TtrpcServer::new()
|
||||||
.bind(server_address)?
|
.bind(server_address)?
|
||||||
.register_service(aservice)
|
.register_service(aservice)
|
||||||
|
Reference in New Issue
Block a user