Expose typed Prepared Lower failures
This commit is contained in:
parent
ee9201b057
commit
30cd36dcdd
1 changed files with 694 additions and 249 deletions
|
|
@ -17,7 +17,7 @@ use lazaret_linux::filesystem::namespace_identity;
|
|||
use lazaret_linux::platform::{PlatformObservation, check_platform};
|
||||
use lazaret_prepared_lower::{
|
||||
IdMap, IdMapRange, OciRegistryTransport, Platform, PreparedDestination,
|
||||
PreparedDestinationKind, PreparedLowerStore, RegistryCredentials,
|
||||
PreparedDestinationKind, PreparedLowerError, PreparedLowerStore, RegistryCredentials,
|
||||
};
|
||||
use lazaret_runtime_supervisor::network::{DnsProbeTarget, NetworkProbeRequest, TcpProbeTarget};
|
||||
use lazaret_runtime_supervisor::sandbox::{
|
||||
|
|
@ -36,18 +36,37 @@ use crate::sandbox_init::PRIVATE_SANDBOX_INIT_ROLE;
|
|||
const NETWORK_NAMESPACE_PATH: &str = "/proc/self/ns/net";
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RuntimeSelectionError(String);
|
||||
pub enum RuntimeSelectionError {
|
||||
PreparedLower(PreparedLowerError),
|
||||
Other(String),
|
||||
}
|
||||
|
||||
impl fmt::Display for RuntimeSelectionError {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
formatter.write_str(&self.0)
|
||||
match self {
|
||||
Self::PreparedLower(error) => error.fmt(formatter),
|
||||
Self::Other(message) => formatter.write_str(message),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for RuntimeSelectionError {}
|
||||
impl std::error::Error for RuntimeSelectionError {
|
||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||
match self {
|
||||
Self::PreparedLower(error) => Some(error),
|
||||
Self::Other(_) => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PreparedLowerError> for RuntimeSelectionError {
|
||||
fn from(error: PreparedLowerError) -> Self {
|
||||
Self::PreparedLower(error)
|
||||
}
|
||||
}
|
||||
|
||||
fn failure(error: impl fmt::Display) -> RuntimeSelectionError {
|
||||
RuntimeSelectionError(error.to_string())
|
||||
RuntimeSelectionError::Other(error.to_string())
|
||||
}
|
||||
|
||||
pub struct InstalledProductPaths<'a> {
|
||||
|
|
@ -149,8 +168,7 @@ async fn select_runtime_for_platform(
|
|||
Err(error) => return Err(failure(error)),
|
||||
}
|
||||
let prepared =
|
||||
PreparedLowerStore::under_storage_root(configuration.storage_root(), catalog.clone())
|
||||
.map_err(failure)?;
|
||||
PreparedLowerStore::under_storage_root(configuration.storage_root(), catalog.clone())?;
|
||||
recover_before_cold_start(configuration, &store, &catalog, &prepared).map_err(failure)?;
|
||||
let image = OciRegistryTransport
|
||||
.pull_confined(
|
||||
|
|
@ -161,7 +179,7 @@ async fn select_runtime_for_platform(
|
|||
random_id()?,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| failure(format!("pulling configured anonymous OCI image: {error:#}")))?;
|
||||
.map_err(RuntimeSelectionError::PreparedLower)?;
|
||||
let artifact = prepared
|
||||
.prepare_transported(
|
||||
PrepareOperationId::new(random_id()?),
|
||||
|
|
@ -169,10 +187,10 @@ async fn select_runtime_for_platform(
|
|||
rootless_id_map(),
|
||||
prepared_destinations(configuration),
|
||||
)
|
||||
.map_err(failure)?;
|
||||
.map_err(RuntimeSelectionError::PreparedLower)?;
|
||||
let artifact_authority = prepared
|
||||
.open_artifact_authority(&artifact)
|
||||
.map_err(failure)?;
|
||||
.map_err(RuntimeSelectionError::PreparedLower)?;
|
||||
let artifact_label = PathBuf::from(std::ffi::OsString::from_vec(
|
||||
configuration
|
||||
.storage_root()
|
||||
|
|
@ -184,7 +202,9 @@ async fn select_runtime_for_platform(
|
|||
.join(PathBuf::from(std::ffi::OsString::from_vec(
|
||||
artifact.path.as_bytes().to_vec(),
|
||||
)));
|
||||
image.cleanup().map_err(failure)?;
|
||||
image
|
||||
.cleanup()
|
||||
.map_err(RuntimeSelectionError::PreparedLower)?;
|
||||
|
||||
let next_generation = next_generation(&store)?;
|
||||
let (coordinator_id, network_sidecar_id, sandbox_id) = distinct_generation_ids()?;
|
||||
|
|
|
|||
Loading…
Reference in a new issue