mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-29 20:24:31 +00:00
runtime-rs: add conditional compile for virt-sandbox persist
code refactoring, add conditional compile for virt-sandbox persist Fixes: #5706 Signed-off-by: Zhongtao Hu <zhongtaohu.tim@linux.alibaba.com>
This commit is contained in:
parent
7c8d474959
commit
6b2ef66f0f
@ -20,11 +20,12 @@ use kata_types::{annotations::Annotation, config::TomlConfig};
|
||||
use linux_container::LinuxContainer;
|
||||
use persist::sandbox_persist::Persist;
|
||||
use tokio::sync::{mpsc::Sender, RwLock};
|
||||
use virt_container::sandbox::SandboxRestoreArgs;
|
||||
use virt_container::sandbox::VirtSandbox;
|
||||
use virt_container::sandbox_persist::{SandboxState, SandboxTYPE};
|
||||
#[cfg(feature = "virt")]
|
||||
use virt_container::VirtContainer;
|
||||
use virt_container::{
|
||||
sandbox::{SandboxRestoreArgs, VirtSandbox},
|
||||
sandbox_persist::SandboxState,
|
||||
VirtContainer,
|
||||
};
|
||||
#[cfg(feature = "wasm")]
|
||||
use wasm_container::WasmContainer;
|
||||
|
||||
@ -153,8 +154,19 @@ impl RuntimeHandlerManager {
|
||||
toml_config: TomlConfig::default(),
|
||||
sender,
|
||||
};
|
||||
match sandbox_state.sandbox_type {
|
||||
SandboxTYPE::VIRTCONTAINER => {
|
||||
match sandbox_state.sandbox_type.clone() {
|
||||
#[cfg(feature = "linux")]
|
||||
name if name == LinuxContainer::name() => {
|
||||
// TODO :support linux container (https://github.com/kata-containers/kata-containers/issues/4905)
|
||||
return Ok(());
|
||||
}
|
||||
#[cfg(feature = "wasm")]
|
||||
name if name == WasmContainer::name() => {
|
||||
// TODO :support wasm container (https://github.com/kata-containers/kata-containers/issues/4906)
|
||||
return Ok(());
|
||||
}
|
||||
#[cfg(feature = "virt")]
|
||||
name if name == VirtContainer::name() => {
|
||||
let sandbox = VirtSandbox::restore(sandbox_args, sandbox_state)
|
||||
.await
|
||||
.context("failed to restore the sandbox")?;
|
||||
@ -163,12 +175,7 @@ impl RuntimeHandlerManager {
|
||||
.await
|
||||
.context("failed to cleanup the resource")?;
|
||||
}
|
||||
SandboxTYPE::LINUXCONTAINER => {
|
||||
// TODO :support linux container (https://github.com/kata-containers/kata-containers/issues/4905)
|
||||
return Ok(());
|
||||
}
|
||||
SandboxTYPE::WASMCONTAINER => {
|
||||
// TODO :support wasm container (https://github.com/kata-containers/kata-containers/issues/4906)
|
||||
_ => {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ use common::{message::Message, RuntimeHandler, RuntimeInstance};
|
||||
use hypervisor::{dragonball::Dragonball, Hypervisor, HYPERVISOR_DRAGONBALL};
|
||||
use kata_types::config::{hypervisor::register_hypervisor_plugin, DragonballConfig, TomlConfig};
|
||||
use resource::ResourceManager;
|
||||
use sandbox::VIRTCONTAINER;
|
||||
use tokio::sync::mpsc::Sender;
|
||||
|
||||
unsafe impl Send for VirtContainer {}
|
||||
@ -39,7 +40,7 @@ impl RuntimeHandler for VirtContainer {
|
||||
}
|
||||
|
||||
fn name() -> String {
|
||||
"virt_container".to_string()
|
||||
VIRTCONTAINER.to_string()
|
||||
}
|
||||
|
||||
fn new_handler() -> Arc<dyn RuntimeHandler> {
|
||||
|
@ -28,8 +28,10 @@ use resource::{
|
||||
};
|
||||
use tokio::sync::{mpsc::Sender, Mutex, RwLock};
|
||||
|
||||
use crate::{health_check::HealthCheck, sandbox_persist::SandboxTYPE};
|
||||
use crate::health_check::HealthCheck;
|
||||
use persist::{self, sandbox_persist::Persist};
|
||||
|
||||
pub(crate) const VIRTCONTAINER: &str = "virt_container";
|
||||
pub struct SandboxRestoreArgs {
|
||||
pub sid: String,
|
||||
pub toml_config: TomlConfig,
|
||||
@ -303,7 +305,7 @@ impl Persist for VirtSandbox {
|
||||
/// Save a state of Sandbox
|
||||
async fn save(&self) -> Result<Self::State> {
|
||||
let sandbox_state = crate::sandbox_persist::SandboxState {
|
||||
sandbox_type: SandboxTYPE::VIRTCONTAINER,
|
||||
sandbox_type: VIRTCONTAINER.to_string(),
|
||||
resource: Some(self.resource_manager.save().await?),
|
||||
hypervisor: Some(self.hypervisor.save_state().await?),
|
||||
};
|
||||
|
@ -8,16 +8,9 @@ use hypervisor::hypervisor_persist::HypervisorState;
|
||||
use resource::resource_persist::ResourceState;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub enum SandboxTYPE {
|
||||
VIRTCONTAINER,
|
||||
LINUXCONTAINER,
|
||||
WASMCONTAINER,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct SandboxState {
|
||||
pub sandbox_type: SandboxTYPE,
|
||||
pub sandbox_type: String,
|
||||
pub resource: Option<ResourceState>,
|
||||
pub hypervisor: Option<HypervisorState>,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user