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 <alex.lyn@antgroup.com>
This commit is contained in:
Alex Lyn
2026-04-30 16:42:28 +08:00
parent 7eae9d0fd6
commit a5ce872287

View File

@@ -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<SandboxExitInfo>,
@@ -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<SandboxStatus> {
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(),