From 58c25041b2618be2f9220653855c857b47c91f85 Mon Sep 17 00:00:00 2001 From: yihuaf Date: Fri, 14 Apr 2023 08:27:06 +0200 Subject: [PATCH 1/2] youki exec should not clean up on error Signed-off-by: yihuaf --- crates/libcontainer/src/container/builder_impl.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/libcontainer/src/container/builder_impl.rs b/crates/libcontainer/src/container/builder_impl.rs index 48ea87be9..6663130b5 100644 --- a/crates/libcontainer/src/container/builder_impl.rs +++ b/crates/libcontainer/src/container/builder_impl.rs @@ -52,12 +52,19 @@ impl<'a> ContainerBuilderImpl<'a> { pub(super) fn create(&mut self) -> Result { match self.run_container().context("failed to create container") { Ok(pid) => Ok(pid), - Err(outer) => { + Err(outer) if matches!(self.container_type, ContainerType::InitContainer) => { + // Only the init container should be cleaned up in the case of + // an error. if let Err(inner) = self.cleanup_container() { return Err(outer.context(inner)); } Err(outer) } + Err(outer) => { + // In the cases of tenant containers, we should not clean up. + // Simply returns the error here. + Err(outer) + } } } From a822e88b1b1a99ade2b295b3ca78f8ec083b8cc7 Mon Sep 17 00:00:00 2001 From: yihuaf Date: Fri, 14 Apr 2023 16:47:35 +0200 Subject: [PATCH 2/2] address review Signed-off-by: yihuaf --- crates/libcontainer/src/container/builder_impl.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/crates/libcontainer/src/container/builder_impl.rs b/crates/libcontainer/src/container/builder_impl.rs index 6663130b5..4410b3783 100644 --- a/crates/libcontainer/src/container/builder_impl.rs +++ b/crates/libcontainer/src/container/builder_impl.rs @@ -52,17 +52,15 @@ impl<'a> ContainerBuilderImpl<'a> { pub(super) fn create(&mut self) -> Result { match self.run_container().context("failed to create container") { Ok(pid) => Ok(pid), - Err(outer) if matches!(self.container_type, ContainerType::InitContainer) => { + Err(outer) => { // Only the init container should be cleaned up in the case of // an error. - if let Err(inner) = self.cleanup_container() { - return Err(outer.context(inner)); + if matches!(self.container_type, ContainerType::InitContainer) { + if let Err(inner) = self.cleanup_container() { + return Err(outer.context(inner)); + } } - Err(outer) - } - Err(outer) => { - // In the cases of tenant containers, we should not clean up. - // Simply returns the error here. + Err(outer) } }