From a5ce872287fa0ce3bda361a47fd47b8dd57f1497 Mon Sep 17 00:00:00 2001 From: Alex Lyn Date: Thu, 30 Apr 2026 16:42:28 +0800 Subject: [PATCH] runtime-rs: Align sandbox status with CRI expectations Update the sandbox status reporting to align with containerd/CRI requirements. This commit aims to address issue of `State Mapping` Previously, internal state strings were returned, which containerd could not recognize, causing running sandboxes to be misinterpreted as SANDBOX_NOTREADY. This maps internal states to CRI constants: - Running -> SANDBOX_READY - Init | Stopped -> SANDBOX_NOTREADY These changes ensure the sandbox status is both accurately interpreted and fully compliant with the expected interface. Signed-off-by: Alex Lyn --- .../crates/runtimes/virt_container/src/sandbox.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/runtime-rs/crates/runtimes/virt_container/src/sandbox.rs b/src/runtime-rs/crates/runtimes/virt_container/src/sandbox.rs index a956509448..55d055047f 100644 --- a/src/runtime-rs/crates/runtimes/virt_container/src/sandbox.rs +++ b/src/runtime-rs/crates/runtimes/virt_container/src/sandbox.rs @@ -95,6 +95,15 @@ pub enum SandboxState { Stopped, } +impl SandboxState { + fn to_cri_state(self) -> &'static str { + match self { + SandboxState::Running => "SANDBOX_READY", + SandboxState::Init | SandboxState::Stopped => "SANDBOX_NOTREADY", + } + } +} + struct SandboxInner { state: SandboxState, exit_info: Option, @@ -183,7 +192,7 @@ impl VirtSandbox { self.hypervisor.clone() } - async fn record_stop(&self, exit_status: u32, exited_at: SystemTime) { + async fn record_stop(&self, exit_status: u32, exited_at: std::time::SystemTime) { let mut inner = self.inner.write().await; if inner.state == SandboxState::Stopped { return; @@ -980,9 +989,8 @@ impl Sandbox for VirtSandbox { } async fn status(&self) -> Result { - info!(sl!(), "get sandbox status"); let inner = self.inner.read().await; - let state = inner.state.to_string(); + let state = inner.state.to_cri_state().to_string(); Ok(SandboxStatus { sandbox_id: self.sid.clone(),