-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prep for multiple container image stores
For now, this is effectively a no-op as it only implements a store for the current ostree container implementation. Beyond some minor code movement and plumbing, this also only handles the store implementation backing the `bootc status` command. Additional image store functionality (check, pull, delete, etc.) will be added in future changes in order to keep things smaller and more manageable. Signed-off-by: John Eckersberg <[email protected]>
- Loading branch information
Showing
8 changed files
with
232 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ pub(crate) mod metadata; | |
mod reboot; | ||
mod reexec; | ||
mod status; | ||
mod store; | ||
mod task; | ||
mod utils; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
use std::env; | ||
use std::ops::Deref; | ||
|
||
use anyhow::Result; | ||
use clap::ValueEnum; | ||
|
||
use ostree_ext::container::OstreeImageReference; | ||
use ostree_ext::keyfileext::KeyFileExt; | ||
use ostree_ext::ostree; | ||
use ostree_ext::sysroot::SysrootLock; | ||
|
||
use crate::spec::ImageStatus; | ||
|
||
mod ostree_container; | ||
|
||
pub(crate) struct Storage { | ||
pub sysroot: SysrootLock, | ||
pub store: Box<dyn ContainerImageStoreImpl>, | ||
} | ||
|
||
#[derive(Default)] | ||
pub(crate) struct CachedImageStatus { | ||
pub image: Option<ImageStatus>, | ||
pub cached_update: Option<ImageStatus>, | ||
} | ||
|
||
pub(crate) trait ContainerImageStore { | ||
fn store(&self) -> Result<Option<Box<dyn ContainerImageStoreImpl>>>; | ||
} | ||
|
||
pub(crate) trait ContainerImageStoreImpl { | ||
fn spec(&self) -> crate::spec::Store; | ||
|
||
fn imagestatus( | ||
&self, | ||
sysroot: &SysrootLock, | ||
deployment: &ostree::Deployment, | ||
image: OstreeImageReference, | ||
) -> Result<CachedImageStatus>; | ||
} | ||
|
||
impl Deref for Storage { | ||
type Target = SysrootLock; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.sysroot | ||
} | ||
} | ||
|
||
impl Storage { | ||
pub fn new(sysroot: SysrootLock) -> Self { | ||
let store = match env::var("BOOTC_STORAGE") { | ||
Ok(val) => crate::spec::Store::from_str(&val, true).unwrap_or_else(|_| { | ||
let default = crate::spec::Store::default(); | ||
tracing::warn!("Unknown BOOTC_STORAGE option {val}, falling back to {default:?}"); | ||
default | ||
}), | ||
Err(_) => crate::spec::Store::default(), | ||
}; | ||
|
||
let store = load(store); | ||
|
||
Self { sysroot, store } | ||
} | ||
} | ||
|
||
impl ContainerImageStore for ostree::Deployment { | ||
fn store<'a>(&self) -> Result<Option<Box<dyn ContainerImageStoreImpl>>> { | ||
if let Some(origin) = self.origin().as_ref() { | ||
if let Some(store) = origin.optional_string("bootc", "backend")? { | ||
let store = | ||
crate::spec::Store::from_str(&store, true).map_err(anyhow::Error::msg)?; | ||
Ok(Some(load(store))) | ||
} else { | ||
Ok(None) | ||
} | ||
} else { | ||
Ok(None) | ||
} | ||
} | ||
} | ||
|
||
pub(crate) fn load(ty: crate::spec::Store) -> Box<dyn ContainerImageStoreImpl> { | ||
match ty { | ||
crate::spec::Store::OstreeContainer => Box::new(ostree_container::OstreeContainerStore), | ||
} | ||
} |
Oops, something went wrong.