Skip to content

Commit 37b35d5

Browse files
committed
WIP async propagation for podman image inspection
1 parent 0ff0acb commit 37b35d5

File tree

3 files changed

+61
-27
lines changed

3 files changed

+61
-27
lines changed

lib/src/cli.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ async fn upgrade(opts: UpgradeOpts) -> Result<()> {
396396
let sysroot = &get_locked_sysroot().await?;
397397
let repo = &sysroot.repo();
398398
let (booted_deployment, _deployments, host) =
399-
crate::status::get_status_require_booted(sysroot)?;
399+
crate::status::get_status_require_booted(sysroot).await?;
400400
let imgref = host.spec.image.as_ref();
401401
// If there's no specified image, let's be nice and check if the booted system is using rpm-ostree
402402
if imgref.is_none()
@@ -525,7 +525,7 @@ async fn switch(opts: SwitchOpts) -> Result<()> {
525525
let sysroot = &get_locked_sysroot().await?;
526526
let repo = &sysroot.repo();
527527
let (booted_deployment, _deployments, host) =
528-
crate::status::get_status_require_booted(sysroot)?;
528+
crate::status::get_status_require_booted(sysroot).await?;
529529

530530
let new_spec = {
531531
let mut new_spec = host.spec.clone();
@@ -573,7 +573,7 @@ async fn edit(opts: EditOpts) -> Result<()> {
573573
prepare_for_write().await?;
574574
let sysroot = &get_locked_sysroot().await?;
575575
let (booted_deployment, _deployments, host) =
576-
crate::status::get_status_require_booted(sysroot)?;
576+
crate::status::get_status_require_booted(sysroot).await?;
577577
let new_host: Host = if let Some(filename) = opts.filename {
578578
let mut r = std::io::BufReader::new(std::fs::File::open(filename)?);
579579
serde_yaml::from_reader(&mut r)?

lib/src/deploy.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,21 @@ impl From<ostree_container::store::LayeredImageState> for ImageState {
8282
}
8383
}
8484

85+
impl From<crate::podman::PodmanInspect> for ImageState {
86+
fn from(value: crate::podman::PodmanInspect) -> Self {
87+
let version = None;
88+
let ostree_commit = "".to_owned();
89+
let created = value.created;
90+
Self {
91+
backend: Backend::Container,
92+
manifest_digest: value.digest,
93+
created,
94+
version,
95+
ostree_commit,
96+
}
97+
}
98+
}
99+
85100
impl ImageState {
86101
/// Fetch the manifest corresponding to this image. May not be available in all backends.
87102
pub(crate) fn get_manifest(
@@ -385,7 +400,8 @@ pub(crate) async fn stage(
385400
pub(crate) async fn rollback(sysroot: &SysrootLock) -> Result<()> {
386401
const ROLLBACK_JOURNAL_ID: &str = "26f3b1eb24464d12aa5e7b544a6b5468";
387402
let repo = &sysroot.repo();
388-
let (booted_deployment, deployments, host) = crate::status::get_status_require_booted(sysroot)?;
403+
let (booted_deployment, deployments, host) =
404+
crate::status::get_status_require_booted(sysroot).await?;
389405

390406
let new_spec = {
391407
let mut new_spec = host.spec.clone();

lib/src/status.rs

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::collections::VecDeque;
22

33
use crate::deploy::ImageState;
4+
use crate::podman;
45
use crate::spec::{
56
Backend, BootEntry, BootOrder, Host, HostSpec, HostStatus, HostType, ImageStatus,
67
};
@@ -152,7 +153,7 @@ pub(crate) fn create_imagestatus(
152153

153154
/// Given an OSTree deployment, parse out metadata into our spec.
154155
#[context("Reading deployment metadata")]
155-
fn boot_entry_from_deployment(
156+
async fn boot_entry_from_deployment(
156157
sysroot: &SysrootLock,
157158
deployment: &ostree::Deployment,
158159
) -> Result<BootEntry> {
@@ -169,7 +170,11 @@ fn boot_entry_from_deployment(
169170
let csum = deployment.csum();
170171
let imgstate = match backend {
171172
Backend::Container => {
172-
todo!()
173+
// TODO: encapsulate this better
174+
let rootfs = &cap_std_ext::cap_std::fs::Dir::reopen_dir(
175+
&crate::utils::sysroot_fd_borrowed(sysroot),
176+
)?;
177+
ImageState::from(podman::podman_inspect(rootfs, &image.image).await?)
173178
}
174179
Backend::OstreeContainer => {
175180
ImageState::from(*ostree_container::store::query_image_commit(repo, &csum)?)
@@ -231,18 +236,18 @@ impl BootEntry {
231236
}
232237

233238
/// A variant of [`get_status`] that requires a booted deployment.
234-
pub(crate) fn get_status_require_booted(
239+
pub(crate) async fn get_status_require_booted(
235240
sysroot: &SysrootLock,
236241
) -> Result<(ostree::Deployment, Deployments, Host)> {
237242
let booted_deployment = sysroot.require_booted_deployment()?;
238-
let (deployments, host) = get_status(sysroot, Some(&booted_deployment))?;
243+
let (deployments, host) = get_status(sysroot, Some(&booted_deployment)).await?;
239244
Ok((booted_deployment, deployments, host))
240245
}
241246

242247
/// Gather the ostree deployment objects, but also extract metadata from them into
243248
/// a more native Rust structure.
244249
#[context("Computing status")]
245-
pub(crate) fn get_status(
250+
pub(crate) async fn get_status(
246251
sysroot: &SysrootLock,
247252
booted_deployment: Option<&ostree::Deployment>,
248253
) -> Result<(Deployments, Host)> {
@@ -281,23 +286,36 @@ pub(crate) fn get_status(
281286
other,
282287
};
283288

284-
let staged = deployments
285-
.staged
286-
.as_ref()
287-
.map(|d| boot_entry_from_deployment(sysroot, d))
288-
.transpose()
289-
.context("Staged deployment")?;
290-
let booted = booted_deployment
291-
.as_ref()
292-
.map(|d| boot_entry_from_deployment(sysroot, d))
293-
.transpose()
294-
.context("Booted deployment")?;
295-
let rollback = deployments
296-
.rollback
297-
.as_ref()
298-
.map(|d| boot_entry_from_deployment(sysroot, d))
299-
.transpose()
300-
.context("Rollback deployment")?;
289+
let staged = if let Some(d) = deployments.staged.as_ref() {
290+
Some(
291+
boot_entry_from_deployment(sysroot, d)
292+
.await
293+
.context("Staged deployment")?,
294+
)
295+
} else {
296+
None
297+
};
298+
299+
let booted = if let Some(d) = booted_deployment {
300+
Some(
301+
boot_entry_from_deployment(sysroot, d)
302+
.await
303+
.context("Booted deployment")?,
304+
)
305+
} else {
306+
None
307+
};
308+
309+
let rollback = if let Some(d) = deployments.rollback.as_ref() {
310+
Some(
311+
boot_entry_from_deployment(sysroot, d)
312+
.await
313+
.context("Rollback deployment")?,
314+
)
315+
} else {
316+
None
317+
};
318+
301319
let spec = staged
302320
.as_ref()
303321
.or(booted.as_ref())
@@ -346,7 +364,7 @@ pub(crate) async fn status(opts: super::cli::StatusOpts) -> Result<()> {
346364
crate::cli::require_root()?;
347365
let sysroot = super::cli::get_locked_sysroot().await?;
348366
let booted_deployment = sysroot.booted_deployment();
349-
let (_deployments, host) = get_status(&sysroot, booted_deployment.as_ref())?;
367+
let (_deployments, host) = get_status(&sysroot, booted_deployment.as_ref()).await?;
350368
host
351369
};
352370

0 commit comments

Comments
 (0)