runtime-rs: add the sandbox init for sandbox api

For the processing of init sandbox, the init of task
api has some more special processing procedures than
the init of sandbox api, so these two types of init
are separated here.

Signed-off-by: Fupan Li <fupan.lfp@antgroup.com>
This commit is contained in:
Fupan Li
2025-02-05 11:24:10 +08:00
committed by Pavel Mores
parent be40646d04
commit 65e908a584

View File

@@ -145,11 +145,6 @@ impl RuntimeHandlerManagerInner {
spec: Option<&oci::Spec>,
options: &Option<Vec<u8>>,
) -> Result<()> {
// return if runtime instance has init
if self.runtime_instance.is_some() {
return Ok(());
}
#[cfg(feature = "linux")]
LinuxContainer::init().context("init linux container")?;
#[cfg(feature = "wasm")]
@@ -299,6 +294,7 @@ impl RuntimeHandlerManager {
Ok(inner.get_kata_tracer())
}
//init the sandbox for the normal task api
#[instrument]
async fn task_init_runtime_instance(
&self,
@@ -306,6 +302,14 @@ impl RuntimeHandlerManager {
state: &spec::State,
options: &Option<Vec<u8>>,
) -> Result<()> {
let mut inner: tokio::sync::RwLockWriteGuard<'_, RuntimeHandlerManagerInner> =
self.inner.write().await;
// return if runtime instance has init
if inner.runtime_instance.is_some() {
return Ok(());
}
let mut dns: Vec<String> = vec![];
let spec_mounts = spec.mounts().clone().unwrap_or_default();
@@ -345,9 +349,6 @@ impl RuntimeHandlerManager {
network_created,
};
let mut inner: tokio::sync::RwLockWriteGuard<'_, RuntimeHandlerManagerInner> =
self.inner.write().await;
let sandbox_config = SandboxConfig {
sandbox_id: inner.id.clone(),
dns,
@@ -361,15 +362,15 @@ impl RuntimeHandlerManager {
inner.try_init(sandbox_config, Some(spec), options).await
}
//init the sandbox for the sandbox api
#[instrument]
async fn init_runtime_instance(
&self,
sandbox_config: SandboxConfig,
spec: Option<&oci::Spec>,
options: &Option<Vec<u8>>,
) -> Result<()> {
async fn sandbox_init_runtime_instance(&self, sandbox_config: SandboxConfig) -> Result<()> {
let mut inner = self.inner.write().await;
inner.try_init(sandbox_config, spec, options).await
// return if runtime instance has init
if inner.runtime_instance.is_some() {
return Ok(());
}
inner.try_init(sandbox_config, None, &None).await
}
#[instrument(parent = &*(ROOTSPAN))]