From 4bb6d5cc8e74d915d47d7b44528efae7cffbb98b Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 28 Oct 2022 09:35:13 -0400 Subject: [PATCH] Remove requirement for `coreos-assembler.basearch` This is aiming to increase compatibility of zincati with systems that aren't derived from Fedora CoreOS (e.g. IoT, desktop systems, etc.) Additionally, even in the FCOS case, when one derives a container image from FCOS, the final build isn't generated by coreos-assembler and hence the ostree commit won't have this metadata. In the end - I can't think of a use case for even trying to have zincati managing an image for a different architecture than the one it's compiled for. So, copy the code I wrote for oci-spec-rs which maps from the Rust architecture to the GNU one. xref https://github.com/containers/oci-spec-rs/commit/52e450e631a212769df4dcd5b7904d942d246d24 --- docs/development/os-metadata.md | 1 - src/identity/mod.rs | 14 ++++++++++++-- src/rpm_ostree/cli_status.rs | 16 ---------------- src/rpm_ostree/mod.rs | 4 +--- 4 files changed, 13 insertions(+), 22 deletions(-) diff --git a/docs/development/os-metadata.md b/docs/development/os-metadata.md index 5c5d6220..a99a48b6 100644 --- a/docs/development/os-metadata.md +++ b/docs/development/os-metadata.md @@ -30,7 +30,6 @@ Booted deployment must provide several mandatory metadata entries: * `checksum`: OSTree commit revision * `version`: OS version * under `base-commit-meta`: - * `coreos-assembler.basearch`: base architecture * `fedora-coreos.stream`: update stream All those metadata entries must exist with a non-empty string value. diff --git a/src/identity/mod.rs b/src/identity/mod.rs index 0a60a11d..f39a89fd 100644 --- a/src/identity/mod.rs +++ b/src/identity/mod.rs @@ -93,8 +93,7 @@ impl Identity { pub fn try_default() -> Result { // Invoke rpm-ostree to get the status of the currently booted deployment. let status = rpm_ostree::invoke_cli_status(true)?; - let basearch = rpm_ostree::parse_basearch(&status) - .context("failed to introspect OS base architecture")?; + let basearch = crate::identity::current_architeture().to_string(); let current_os = rpm_ostree::parse_booted(&status).context("failed to introspect booted OS image")?; let node_uuid = { @@ -190,6 +189,17 @@ fn compute_node_uuid(app_id: &id128::Id128) -> Result { Ok(id) } +// Translate the architecture we were compiled for to the +// output from the `arch` command that is used for RPM and +// coreos-assembler builds. +pub(crate) fn current_architeture() -> &'static str { + match std::env::consts::ARCH { + "powerpc64" if cfg!(target_endian = "big") => "ppc64", + "powerpc64" if cfg!(target_endian = "little") => "ppc64le", + o => o, + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/rpm_ostree/cli_status.rs b/src/rpm_ostree/cli_status.rs index d2c14785..179f0a60 100644 --- a/src/rpm_ostree/cli_status.rs +++ b/src/rpm_ostree/cli_status.rs @@ -61,8 +61,6 @@ pub struct DeploymentJson { /// Metadata from base commit (only fields relevant to zincati). #[derive(Clone, Debug, Deserialize)] struct BaseCommitMetaJson { - #[serde(rename = "coreos-assembler.basearch")] - basearch: String, #[serde(rename = "fedora-coreos.stream")] stream: String, } @@ -85,12 +83,6 @@ impl DeploymentJson { } } -/// Parse base architecture for booted deployment from status object. -pub fn parse_basearch(status: &StatusJson) -> Result { - let json = booted_json(status)?; - Ok(json.base_metadata.basearch) -} - /// Parse the booted deployment from status object. pub fn parse_booted(status: &StatusJson) -> Result { let json = booted_json(status)?; @@ -157,7 +149,6 @@ fn booted_json(status: &StatusJson) -> Result { ensure!(!booted.base_revision().is_empty(), "empty base revision"); ensure!(!booted.version.is_empty(), "empty version"); - ensure!(!booted.base_metadata.basearch.is_empty(), "empty basearch"); Ok(booted) } @@ -244,13 +235,6 @@ mod tests { } } - #[test] - fn mock_booted_basearch() { - let status = mock_status("tests/fixtures/rpm-ostree-status.json").unwrap(); - let booted = booted_json(&status).unwrap(); - assert_eq!(booted.base_metadata.basearch, "x86_64"); - } - #[test] fn mock_booted_updates_stream() { let status = mock_status("tests/fixtures/rpm-ostree-status.json").unwrap(); diff --git a/src/rpm_ostree/mod.rs b/src/rpm_ostree/mod.rs index e1c31595..621882de 100644 --- a/src/rpm_ostree/mod.rs +++ b/src/rpm_ostree/mod.rs @@ -1,9 +1,7 @@ mod cli_deploy; mod cli_finalize; mod cli_status; -pub use cli_status::{ - invoke_cli_status, parse_basearch, parse_booted, parse_booted_updates_stream, -}; +pub use cli_status::{invoke_cli_status, parse_booted, parse_booted_updates_stream}; mod actor; pub use actor::{