Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions crates/openshell-core/src/driver_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ pub const LABEL_SANDBOX_NAME: &str = "openshell.ai/sandbox-name";
/// Container/pod label carrying the sandbox namespace.
pub const LABEL_SANDBOX_NAMESPACE: &str = "openshell.ai/sandbox-namespace";

// ---------------------------------------------------------------------------

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made constants public and reusable.

// Sandbox condition reason strings set by compute drivers.
// ---------------------------------------------------------------------------

/// Ready-condition reason when a container exits on its own (e.g. SIGTERM
/// from a machine restart, OOM kill, application crash).
pub const CONDITION_EXITED: &str = "ContainerExited";

/// Ready-condition reason when a container is explicitly stopped via the
/// runtime API (e.g. `podman stop`, gateway-initiated shutdown).
pub const CONDITION_STOPPED: &str = "ContainerStopped";

// ---------------------------------------------------------------------------

/// Path to the sandbox supervisor binary inside the container image.
Expand Down
2 changes: 1 addition & 1 deletion crates/openshell-driver-docker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2801,7 +2801,7 @@ fn container_ready_condition(
("False", "ContainerPaused", "Container is paused", false)
}
ContainerSummaryStateEnum::EXITED => {
("False", "ContainerExited", "Container exited", false)
("False", openshell_core::driver_utils::CONDITION_EXITED, "Container exited", false)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use public constant here

}
ContainerSummaryStateEnum::DEAD => ("False", "ContainerDead", "Container is dead", false),
}
Expand Down
19 changes: 19 additions & 0 deletions crates/openshell-driver-podman/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,25 @@ impl PodmanComputeDriver {
}
}

/// Resume an exited sandbox container. Returns `Ok(true)` if the
/// container exists and was (re)started, `Ok(false)` if it is gone.
pub async fn resume_sandbox(&self, sandbox_name: &str) -> Result<bool, ComputeDriverError> {
let name = container::container_name(sandbox_name);
let inspect = match self.client.inspect_container(&name).await {
Ok(i) => i,
Err(PodmanApiError::NotFound(_)) => return Ok(false),
Err(e) => return Err(ComputeDriverError::from(e)),
};
if inspect.state.running {
return Ok(true);
}
match self.client.start_container(&name).await {
Ok(()) => Ok(true),
Err(PodmanApiError::NotFound(_)) => Ok(false),
Err(e) => Err(ComputeDriverError::from(e)),
}
}

/// Fetch a single sandbox by name.
pub async fn get_sandbox(
&self,
Expand Down
3 changes: 1 addition & 2 deletions crates/openshell-driver-podman/src/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ use tracing::{debug, info, warn};
// Condition reason constants shared across event-building paths.
const CONDITION_RUNNING: &str = "ContainerRunning";
const CONDITION_STARTING: &str = "ContainerStarting";
const CONDITION_EXITED: &str = "ContainerExited";
const CONDITION_STOPPED: &str = "ContainerStopped";
use openshell_core::driver_utils::{CONDITION_EXITED, CONDITION_STOPPED};

pub type WatchStream =
Pin<Box<dyn Stream<Item = Result<WatchSandboxesEvent, ComputeDriverError>> + Send>>;
Expand Down
Loading
Loading