Skip to content

Commit

Permalink
WIP: pull the stream id from the booted coreos version
Browse files Browse the repository at this point in the history
  • Loading branch information
jbtrystram committed Jan 10, 2025
1 parent 7c601c7 commit f10a80c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 28 deletions.
3 changes: 2 additions & 1 deletion dist/polkit-1/rules.d/zincati.rules
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
polkit.addRule(function(action, subject) {
if ((action.id == "org.projectatomic.rpmostree1.deploy" ||
action.id == "org.projectatomic.rpmostree1.finalize-deployment") ||
action.id == "org.projectatomic.rpmostree1.cleanup" &&
action.id == "org.projectatomic.rpmostree1.cleanup" ||
action.id == "org.projectatomic.rpmostree1.rebase" &&
subject.user == "zincati") {
return polkit.Result.YES;
}
Expand Down
18 changes: 11 additions & 7 deletions src/cincinnati/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,10 @@ fn find_update(
.find(|(_, node)| is_same_checksum(node, &booted_depl.checksum))
{
Some(current) => current,
None => return Ok(None),
None => {
log::warn!("current deployment not found in the update graph");
return Ok(None);
}
};
drop(booted_depl);
let cur_release = Release::from_cincinnati(cur_node.clone())
Expand Down Expand Up @@ -333,13 +336,14 @@ fn find_denylisted_releases(graph: &client::Graph, depls: BTreeSet<Release>) ->

/// Check whether input node matches current checksum.
fn is_same_checksum(node: &Node, checksum: &str) -> bool {
let payload_is_checksum = node
.metadata
.get(SCHEME_KEY)
.map(|v| v == CHECKSUM_SCHEME)
.unwrap_or(false);
let payload_type = node.metadata.get(SCHEME_KEY);

payload_is_checksum && node.payload == checksum
if let Some(scheme) = payload_type {
(scheme.as_str() == OCI_SCHEME || scheme.as_str() == CHECKSUM_SCHEME)
&& node.payload == checksum
} else {
false
}
}

/// Check whether input node is a dead-end; if so, return the reason.
Expand Down
54 changes: 34 additions & 20 deletions src/rpm_ostree/cli_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,15 @@ impl Deployment {

/// Return the deployment base revision.
pub fn base_revision(&self) -> String {
self.base_checksum
self.container_image_reference
.clone()
.map(|pullspec| {
pullspec
.strip_prefix("ostree-unverified-registry:")
.map(|s| s.to_string())
})
.flatten()
.or(self.base_checksum.clone())
.unwrap_or_else(|| self.checksum.clone())
}
}
Expand All @@ -104,28 +111,35 @@ pub fn parse_booted(status: &Status) -> Result<Release> {

fn fedora_coreos_stream_from_deployment(deploy: &Deployment) -> Result<String> {
if deploy.base_metadata.stream.is_none() {
println!("no stream, maybe it's OCI let's try to deserialize");
fedora_coreos_stream_from_version(&deploy.version)
} else {
let stream = deploy
.base_metadata
.stream
.as_ref()
.ok_or_else(|| anyhow!("Missing `fedora-coreos.stream` in commit metadata"))?;
ensure!(!stream.is_empty(), "empty stream value");
Ok(stream.to_string())
}

if deploy.container_image_reference.is_some()

let stream = deploy
.base_metadata
.stream
.as_ref()
.ok_or_else(|| anyhow!("Missing `fedora-coreos.stream` in commit metadata"))?;
ensure!(!stream.is_empty(), "empty stream value");
Ok(stream.to_string())
}

fn fedora_coreos_stream_from_oci_manifest(deploy: &Deployment) -> Result<String> {
let stream = deploy
.base_metadata
.stream
.as_ref()
.ok_or_else(|| anyhow!("Missing `fedora-coreos.stream` in commit metadata"))?;
ensure!(!stream.is_empty(), "empty stream value");
Ok(stream.to_string())
fn fedora_coreos_stream_from_version(version: &String) -> Result<String> {
//41.20241109.3.0
let version_split: Vec<&str> = version.split('.').collect();
if version_split.len() != 4 {
return Err(anyhow!("{version} is not a valid CoreOS version ID"));
} else {
let stream_id: i32 = version_split[2]
.parse()
.map_err(|_| anyhow!("invalid Coreos version ID"))?;

match stream_id {
1 => Ok("next".to_string()),
2 => Ok("testing".to_string()),
3 => Ok("stable".to_string()),
_ => Err(anyhow!("This stream is not supported by Zincati")),
}
}
}

/// Parse updates stream for booted deployment from status object.
Expand Down

0 comments on commit f10a80c

Please sign in to comment.