Skip to content

Commit e99f5cc

Browse files
authored
Merge pull request #1518 from cgwalters/drop-store-abstraction
store: Remove dynamic abstraction
2 parents 1324091 + 82057f8 commit e99f5cc

File tree

3 files changed

+58
-143
lines changed

3 files changed

+58
-143
lines changed

crates/lib/src/status.rs

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ use ostree_ext::container as ostree_container;
1313
use ostree_ext::container_utils::ostree_booted;
1414
use ostree_ext::keyfileext::KeyFileExt;
1515
use ostree_ext::oci_spec;
16+
use ostree_ext::oci_spec::image::Digest;
17+
use ostree_ext::oci_spec::image::ImageConfiguration;
1618
use ostree_ext::ostree;
19+
use ostree_ext::sysroot::SysrootLock;
1720

1821
use crate::cli::OutputFormat;
22+
use crate::spec::ImageStatus;
1923
use crate::spec::{BootEntry, BootOrder, Host, HostSpec, HostStatus, HostType};
2024
use crate::spec::{ImageReference, ImageSignature};
21-
use crate::store::{CachedImageStatus, ContainerImageStore, Storage};
25+
use crate::store::{CachedImageStatus, Storage};
2226

2327
impl From<ostree_container::SignatureSource> for ImageSignature {
2428
fn from(sig: ostree_container::SignatureSource) -> Self {
@@ -109,41 +113,81 @@ pub(crate) fn labels_of_config(
109113
config.config().as_ref().and_then(|c| c.labels().as_ref())
110114
}
111115

116+
/// Convert between a subset of ostree-ext metadata and the exposed spec API.
117+
fn create_imagestatus(
118+
image: ImageReference,
119+
manifest_digest: &Digest,
120+
config: &ImageConfiguration,
121+
) -> ImageStatus {
122+
let labels = labels_of_config(config);
123+
let timestamp = labels
124+
.and_then(|l| {
125+
l.get(oci_spec::image::ANNOTATION_CREATED)
126+
.map(|s| s.as_str())
127+
})
128+
.or_else(|| config.created().as_deref())
129+
.and_then(bootc_utils::try_deserialize_timestamp);
130+
131+
let version = ostree_container::version_for_config(config).map(ToOwned::to_owned);
132+
let architecture = config.architecture().to_string();
133+
ImageStatus {
134+
image,
135+
version,
136+
timestamp,
137+
image_digest: manifest_digest.to_string(),
138+
architecture,
139+
}
140+
}
141+
142+
fn imagestatus(
143+
sysroot: &SysrootLock,
144+
deployment: &ostree::Deployment,
145+
image: ostree_container::OstreeImageReference,
146+
) -> Result<CachedImageStatus> {
147+
let repo = &sysroot.repo();
148+
let imgstate = ostree_container::store::query_image_commit(repo, &deployment.csum())?;
149+
let image = ImageReference::from(image);
150+
let cached = imgstate
151+
.cached_update
152+
.map(|cached| create_imagestatus(image.clone(), &cached.manifest_digest, &cached.config));
153+
let imagestatus = create_imagestatus(image, &imgstate.manifest_digest, &imgstate.configuration);
154+
155+
Ok(CachedImageStatus {
156+
image: Some(imagestatus),
157+
cached_update: cached,
158+
})
159+
}
160+
112161
/// Given an OSTree deployment, parse out metadata into our spec.
113162
#[context("Reading deployment metadata")]
114163
fn boot_entry_from_deployment(
115164
sysroot: &Storage,
116165
deployment: &ostree::Deployment,
117166
) -> Result<BootEntry> {
118167
let (
119-
store,
120168
CachedImageStatus {
121169
image,
122170
cached_update,
123171
},
124172
incompatible,
125173
) = if let Some(origin) = deployment.origin().as_ref() {
126174
let incompatible = crate::utils::origin_has_rpmostree_stuff(origin);
127-
let (store, cached_imagestatus) = if incompatible {
175+
let cached_imagestatus = if incompatible {
128176
// If there are local changes, we can't represent it as a bootc compatible image.
129-
(None, CachedImageStatus::default())
177+
CachedImageStatus::default()
130178
} else if let Some(image) = get_image_origin(origin)? {
131-
let store = deployment.store()?;
132-
let store = store.as_ref().unwrap_or(&sysroot.store);
133-
let spec = Some(store.spec());
134-
let status = store.imagestatus(sysroot, deployment, image)?;
135-
136-
(spec, status)
179+
imagestatus(sysroot, deployment, image)?
137180
} else {
138181
// The deployment isn't using a container image
139-
(None, CachedImageStatus::default())
182+
CachedImageStatus::default()
140183
};
141-
(store, cached_imagestatus, incompatible)
184+
(cached_imagestatus, incompatible)
142185
} else {
143186
// The deployment has no origin at all (this generally shouldn't happen)
144-
(None, CachedImageStatus::default(), false)
187+
(CachedImageStatus::default(), false)
145188
};
146189

190+
let store = Some(crate::spec::Store::OstreeContainer);
147191
let r = BootEntry {
148192
image,
149193
cached_update,

crates/lib/src/store/mod.rs

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
11
use std::cell::OnceCell;
2-
use std::env;
32
use std::ops::Deref;
43
use std::sync::Arc;
54

65
use anyhow::{Context, Result};
76
use cap_std_ext::cap_std;
87
use cap_std_ext::cap_std::fs::{Dir, DirBuilder, DirBuilderExt as _};
98
use cap_std_ext::dirext::CapStdExtDirExt;
10-
use clap::ValueEnum;
119
use fn_error_context::context;
1210

13-
use ostree_ext::container::OstreeImageReference;
14-
use ostree_ext::keyfileext::KeyFileExt;
11+
use composefs;
1512
use ostree_ext::sysroot::SysrootLock;
16-
use ostree_ext::{composefs, ostree};
1713
use rustix::fs::Mode;
1814

1915
use crate::lsm;
2016
use crate::spec::ImageStatus;
2117
use crate::utils::deployment_fd;
2218

23-
mod ostree_container;
24-
2519
/// See https://github.com/containers/composefs-rs/issues/159
2620
pub type ComposefsRepository =
2721
composefs::repository::Repository<composefs::fsverity::Sha512HashValue>;
@@ -50,10 +44,6 @@ pub(crate) struct Storage {
5044

5145
/// Our runtime state
5246
run: Dir,
53-
54-
/// This is a stub abstraction that tries to hide ostree
55-
/// that we aren't really using right now
56-
pub store: Box<dyn ContainerImageStoreImpl>,
5747
}
5848

5949
#[derive(Default)]
@@ -62,21 +52,6 @@ pub(crate) struct CachedImageStatus {
6252
pub cached_update: Option<ImageStatus>,
6353
}
6454

65-
pub(crate) trait ContainerImageStore {
66-
fn store(&self) -> Result<Option<Box<dyn ContainerImageStoreImpl>>>;
67-
}
68-
69-
pub(crate) trait ContainerImageStoreImpl {
70-
fn spec(&self) -> crate::spec::Store;
71-
72-
fn imagestatus(
73-
&self,
74-
sysroot: &SysrootLock,
75-
deployment: &ostree::Deployment,
76-
image: OstreeImageReference,
77-
) -> Result<CachedImageStatus>;
78-
}
79-
8055
impl Deref for Storage {
8156
type Target = SysrootLock;
8257

@@ -88,15 +63,6 @@ impl Deref for Storage {
8863
impl Storage {
8964
pub fn new(sysroot: SysrootLock, run: &Dir) -> Result<Self> {
9065
let run = run.try_clone()?;
91-
let store = match env::var("BOOTC_STORAGE") {
92-
Ok(val) => crate::spec::Store::from_str(&val, true).unwrap_or_else(|_| {
93-
let default = crate::spec::Store::default();
94-
tracing::warn!("Unknown BOOTC_STORAGE option {val}, falling back to {default:?}");
95-
default
96-
}),
97-
Err(_) => crate::spec::Store::default(),
98-
};
99-
let store = load(store);
10066

10167
// ostree has historically always relied on
10268
// having ostree -> sysroot/ostree as a symlink in the image to
@@ -119,7 +85,6 @@ impl Storage {
11985
sysroot,
12086
run,
12187
composefs: Default::default(),
122-
store,
12388
imgstore: Default::default(),
12489
})
12590
}
@@ -190,25 +155,3 @@ impl Storage {
190155
.map_err(Into::into)
191156
}
192157
}
193-
194-
impl ContainerImageStore for ostree::Deployment {
195-
fn store<'a>(&self) -> Result<Option<Box<dyn ContainerImageStoreImpl>>> {
196-
if let Some(origin) = self.origin().as_ref() {
197-
if let Some(store) = origin.optional_string("bootc", "backend")? {
198-
let store =
199-
crate::spec::Store::from_str(&store, true).map_err(anyhow::Error::msg)?;
200-
Ok(Some(load(store)))
201-
} else {
202-
Ok(None)
203-
}
204-
} else {
205-
Ok(None)
206-
}
207-
}
208-
}
209-
210-
pub(crate) fn load(ty: crate::spec::Store) -> Box<dyn ContainerImageStoreImpl> {
211-
match ty {
212-
crate::spec::Store::OstreeContainer => Box::new(ostree_container::OstreeContainerStore),
213-
}
214-
}

crates/lib/src/store/ostree_container.rs

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
 (0)