mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-18 16:08:25 +00:00
Merge pull request #10045 from lifupan/cleanup_container
runtime-rs: container: fix the issue of missing cleanup container
This commit is contained in:
commit
dc97f3f540
@ -546,6 +546,18 @@ impl Container {
|
||||
pub async fn spec(&self) -> oci::Spec {
|
||||
self.spec.clone()
|
||||
}
|
||||
|
||||
pub async fn cleanup(&mut self) -> Result<()> {
|
||||
let mut inner = self.inner.write().await;
|
||||
let device_manager = self.resource_manager.get_device_manager().await;
|
||||
inner
|
||||
.cleanup_container(
|
||||
self.container_id.container_id.as_str(),
|
||||
true,
|
||||
&device_manager,
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
fn amend_spec(spec: &mut oci::Spec, disable_guest_seccomp: bool) -> Result<()> {
|
||||
|
@ -177,7 +177,7 @@ impl ContainerInner {
|
||||
}
|
||||
}
|
||||
|
||||
async fn cleanup_container(
|
||||
pub(crate) async fn cleanup_container(
|
||||
&mut self,
|
||||
cid: &str,
|
||||
force: bool,
|
||||
|
@ -70,7 +70,7 @@ impl VirtContainerManager {
|
||||
impl ContainerManager for VirtContainerManager {
|
||||
#[instrument]
|
||||
async fn create_container(&self, config: ContainerConfig, spec: oci::Spec) -> Result<PID> {
|
||||
let container = Container::new(
|
||||
let mut container = Container::new(
|
||||
self.pid,
|
||||
config.clone(),
|
||||
spec.clone(),
|
||||
@ -107,7 +107,14 @@ impl ContainerManager for VirtContainerManager {
|
||||
}
|
||||
|
||||
let mut containers = self.containers.write().await;
|
||||
container.create(spec).await.context("create")?;
|
||||
if let Err(e) = container.create(spec).await {
|
||||
if let Err(inner_e) = container.cleanup().await {
|
||||
warn!(sl!(), "failed to cleanup container {:?}", inner_e);
|
||||
}
|
||||
|
||||
return Err(e);
|
||||
}
|
||||
|
||||
containers.insert(container.container_id.to_string(), container);
|
||||
Ok(PID { pid: self.pid })
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user