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
2 changes: 0 additions & 2 deletions crates/openshell-gateway/src/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ use crate::local_driver::LocalDriver;
pub const DOCKER: LocalDriver = LocalDriver {
name: "docker",
drop_legacy_keys: |_| {},
// The in-process driver did not retry an unreachable daemon.
retry_unavailable: None,
};

/// Detect Docker by starting its driver with the operator's table, so a
Expand Down
22 changes: 9 additions & 13 deletions crates/openshell-gateway/src/local_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ pub struct LocalDriver {
/// Removes keys earlier releases accepted that the driver's strict table no
/// longer does. The gateway warns about each, so the driver can reject them.
pub drop_legacy_keys: fn(&mut toml::map::Map<String, toml::Value>),
/// Start a named driver again this often while its backend is unreachable.
/// Drivers that never retried leave it unset.
pub retry_unavailable: Option<UnavailableRetry>,
}

/// The gateway's view of a driver's table: where its binary is, and the table
Expand Down Expand Up @@ -163,13 +160,9 @@ impl LocalDriver {
socket_dir,
log_level: gateway_log_level,
};
let outcome = match self.retry_unavailable {
Some(retry) => {
launcher::launch_tolerating_unavailable(request, configure, on_exit, retry)
.await?
}
None => launcher::launch(request, configure, on_exit).await?,
};
let outcome =
launcher::launch_tolerating_unavailable(request, configure, on_exit, BACKEND_RETRY)
.await?;
match outcome {
LaunchOutcome::Launched(launched) => launched,
LaunchOutcome::InvalidConfig(reason) => {
Expand Down Expand Up @@ -203,6 +196,9 @@ impl LocalDriver {
}
}

/// How long to wait between starts while a named driver's backend is down.
#[cfg(feature = "compute-driver-podman")]
pub const BACKEND_RETRY_DELAY: std::time::Duration = std::time::Duration::from_secs(2);
/// How often a named driver is started while its backend is unreachable, such
/// as a socket restarting during a package upgrade.
const BACKEND_RETRY: UnavailableRetry = UnavailableRetry {
attempts: 6,
delay: std::time::Duration::from_secs(2),
};
12 changes: 1 addition & 11 deletions crates/openshell-gateway/src/podman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,11 @@

use openshell_server::{DriverDetection, DriverDetectionContext};

use crate::launcher::UnavailableRetry;
use crate::local_driver::{BACKEND_RETRY_DELAY, LocalDriver};

/// How many times a named Podman is started while its socket is unreachable.
/// This keeps the bounded tolerance the in-process driver had, such as
/// `podman.socket` restarting during a package upgrade.
const START_ATTEMPTS: u32 = 6;
use crate::local_driver::LocalDriver;

pub const PODMAN: LocalDriver = LocalDriver {
name: "podman",
drop_legacy_keys: drop_legacy_gateway_port,
retry_unavailable: Some(UnavailableRetry {
attempts: START_ATTEMPTS,
delay: BACKEND_RETRY_DELAY,
}),
};

/// `main` accepted `gateway_port` and overwrote it with the gateway's
Expand Down
2 changes: 1 addition & 1 deletion docs/how-it-works/gateways/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1569,7 +1569,7 @@ The gateway owns the admission policy (`allow_driver_config` and `resource_admis

Set `driver_dir` in `[openshell.gateway]`. A `driver_dir` in a driver table is deprecated: the gateway removes it with a warning and uses it only when `[openshell.gateway]` sets none. The gateway looks for the driver binary in `driver_dir`, then in `~/.local/libexec/openshell`, `/usr/libexec/openshell`, `/usr/local/libexec/openshell`, and `/usr/local/libexec`, then next to the gateway binary.

When no driver is selected, the gateway tries Kubernetes, then Podman, then Docker. For Podman and Docker it starts the driver with the operator's table, so a configured `socket_path` is honored. The first driver that binds its socket is kept and configured, so detection never starts a driver it then stops. For Docker it does the same with the Docker table. A table that is invalid, or a socket that is not reachable, moves detection to the next candidate and logs the reason. A driver that crashes or times out stops startup. If a driver is selected by name, any such failure stops startup, except that Podman is started again a few times while its socket is unreachable, as the in-process driver retried.
When no driver is selected, the gateway tries Kubernetes, then Podman, then Docker. For Podman and Docker it starts the driver with the operator's table, so a configured `socket_path` is honored. The first driver that binds its socket is kept and configured, so detection never starts a driver it then stops. For Docker it does the same with the Docker table. A table that is invalid, or a socket that is not reachable, moves detection to the next candidate and logs the reason. A driver that crashes or times out stops startup. If a driver is selected by name, any such failure stops startup, except that the driver is started again up to six times, two seconds apart, while its backend is unreachable.

On shutdown, the gateway stops sandboxes through each launched driver and then releases the driver with the launch protocol's `Shutdown` call. A driver defers a `SIGTERM` or `SIGINT` that reaches it from elsewhere, such as the signal a service manager sends to every process of the gateway's unit, until the gateway releases it, the gateway exits, or 30 seconds pass. Sandboxes therefore stop even when the whole unit is signalled.

Expand Down
Loading