Skip to content

Commit 331a0b5

Browse files
committed
WIP async propagation for podman image inspection
1 parent fe098b3 commit 331a0b5

File tree

4 files changed

+62
-28
lines changed

4 files changed

+62
-28
lines changed

lib/src/cli.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ async fn upgrade(opts: UpgradeOpts) -> Result<()> {
497497
let sysroot = &get_locked_sysroot().await?;
498498
let repo = &sysroot.repo();
499499
let (booted_deployment, _deployments, host) =
500-
crate::status::get_status_require_booted(sysroot)?;
500+
crate::status::get_status_require_booted(sysroot).await?;
501501
let imgref = host.spec.image.as_ref();
502502
// If there's no specified image, let's be nice and check if the booted system is using rpm-ostree
503503
if imgref.is_none() {
@@ -638,7 +638,7 @@ async fn switch(opts: SwitchOpts) -> Result<()> {
638638
let sysroot = &get_locked_sysroot().await?;
639639
let repo = &sysroot.repo();
640640
let (booted_deployment, _deployments, host) =
641-
crate::status::get_status_require_booted(sysroot)?;
641+
crate::status::get_status_require_booted(sysroot).await?;
642642

643643
let new_spec = {
644644
let mut new_spec = host.spec.clone();
@@ -688,7 +688,7 @@ async fn rollback(_opts: RollbackOpts) -> Result<()> {
688688
async fn edit(opts: EditOpts) -> Result<()> {
689689
let sysroot = &get_locked_sysroot().await?;
690690
let (booted_deployment, _deployments, host) =
691-
crate::status::get_status_require_booted(sysroot)?;
691+
crate::status::get_status_require_booted(sysroot).await?;
692692
let new_host: Host = if let Some(filename) = opts.filename {
693693
let mut r = std::io::BufReader::new(std::fs::File::open(filename)?);
694694
serde_yaml::from_reader(&mut r)?

lib/src/deploy.rs

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

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

393409
let new_spec = {
394410
let mut new_spec = host.spec.clone();

lib/src/image.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub(crate) async fn push_entrypoint(source: Option<&str>, target: Option<&str>)
4747
let source = if let Some(source) = source {
4848
ImageReference::try_from(source).context("Parsing source image")?
4949
} else {
50-
let status = crate::status::get_status_require_booted(&sysroot)?;
50+
let status = crate::status::get_status_require_booted(&sysroot).await?;
5151
// SAFETY: We know it's booted
5252
let booted = status.2.status.booted.unwrap();
5353
let booted_image = booted.image.unwrap().image;

lib/src/status.rs

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use ostree_ext::sysroot::SysrootLock;
1515

1616
use crate::cli::OutputFormat;
1717
use crate::deploy::ImageState;
18+
use crate::podman;
1819
use crate::spec::{
1920
Backend, BootEntry, BootOrder, Host, HostSpec, HostStatus, HostType, ImageStatus,
2021
};
@@ -154,7 +155,7 @@ pub(crate) fn create_imagestatus(
154155

155156
/// Given an OSTree deployment, parse out metadata into our spec.
156157
#[context("Reading deployment metadata")]
157-
fn boot_entry_from_deployment(
158+
async fn boot_entry_from_deployment(
158159
sysroot: &SysrootLock,
159160
deployment: &ostree::Deployment,
160161
) -> Result<BootEntry> {
@@ -171,7 +172,11 @@ fn boot_entry_from_deployment(
171172
let csum = deployment.csum();
172173
let imgstate = match backend {
173174
Backend::Container => {
174-
todo!()
175+
// TODO: encapsulate this better
176+
let rootfs = &cap_std_ext::cap_std::fs::Dir::reopen_dir(
177+
&crate::utils::sysroot_fd_borrowed(sysroot),
178+
)?;
179+
ImageState::from(podman::podman_inspect(rootfs, &image.image).await?)
175180
}
176181
Backend::OstreeContainer => {
177182
ImageState::from(*ostree_container::store::query_image_commit(repo, &csum)?)
@@ -233,18 +238,18 @@ impl BootEntry {
233238
}
234239

235240
/// A variant of [`get_status`] that requires a booted deployment.
236-
pub(crate) fn get_status_require_booted(
241+
pub(crate) async fn get_status_require_booted(
237242
sysroot: &SysrootLock,
238243
) -> Result<(ostree::Deployment, Deployments, Host)> {
239244
let booted_deployment = sysroot.require_booted_deployment()?;
240-
let (deployments, host) = get_status(sysroot, Some(&booted_deployment))?;
245+
let (deployments, host) = get_status(sysroot, Some(&booted_deployment)).await?;
241246
Ok((booted_deployment, deployments, host))
242247
}
243248

244249
/// Gather the ostree deployment objects, but also extract metadata from them into
245250
/// a more native Rust structure.
246251
#[context("Computing status")]
247-
pub(crate) fn get_status(
252+
pub(crate) async fn get_status(
248253
sysroot: &SysrootLock,
249254
booted_deployment: Option<&ostree::Deployment>,
250255
) -> Result<(Deployments, Host)> {
@@ -283,23 +288,36 @@ pub(crate) fn get_status(
283288
other,
284289
};
285290

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

0 commit comments

Comments
 (0)