Skip to content

Commit

Permalink
openshift_secondary_metadata_parser: Add 'version' parsing
Browse files Browse the repository at this point in the history
Consuming the 'version' file that graph-data grew in [1], so the logs
will contain more useful error messages when the plugin is fed an
incompatible schema version.

Bumping the graph-data commit used for CI moves us to the first
main-line commit to include the 'version' file:

  cincinnati-graph-data$ git --no-pager show --date=short --format='%ad %h %s' d980578d2e b87e7c2782
  2020-03-18 d980578 Merge pull request openshift#125 from marun/unique-service-ca-serial

  2020-05-11 b87e7c2 Merge pull request openshift#233 from wking/version-file

[1]: openshift/cincinnati-graph-data#233
  • Loading branch information
wking committed Nov 5, 2020
1 parent fefff59 commit 60a9aca
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use self::cincinnati::plugins::prelude_plugin_impl::*;
use tokio::sync::Mutex as FuturesMutex;

pub static DEFAULT_OUTPUT_WHITELIST: &[&str] = &[
"version",
"channels/.+\\.ya+ml",
"blocked-edges/.+\\.ya+ml",
"raw/metadata.json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use self::cincinnati::plugins::prelude_plugin_impl::*;
use std::collections::HashSet;

pub static DEFAULT_KEY_FILTER: &str = "io.openshift.upgrades.graph";
static SUPPORTED_VERSIONS: &[&str] = &["1.0.0"];

pub mod graph_data_model {
//! This module contains the data types corresponding to the graph data files.
Expand Down Expand Up @@ -295,6 +296,24 @@ impl OpenshiftSecondaryMetadataParserPlugin {
}
}

async fn process_version(&self, data_dir: &PathBuf) -> Fallible<String> {
let path = data_dir.join("version");
let version = tokio::fs::read(&path)
.await
.context(format!("Reading {:?}", &path))?;
let string_version = String::from_utf8_lossy(&version);

if SUPPORTED_VERSIONS.contains(&string_version.trim()) {
Ok(string_version.into_owned())
} else {
Err(format_err!(
"unrecognized graph-data version {}; supported versions: {:?}",
string_version,
SUPPORTED_VERSIONS
))
}
}

async fn process_raw_metadata(
&self,
graph: &mut cincinnati::Graph,
Expand Down Expand Up @@ -563,6 +582,7 @@ impl InternalPlugin for OpenshiftSecondaryMetadataParserPlugin {
async fn run_internal(self: &Self, mut io: InternalIO) -> Fallible<InternalIO> {
let data_dir = self.get_data_directory(&io);

self.process_version(&data_dir).await?;
self.process_raw_metadata(&mut io.graph, &data_dir).await?;
self.process_blocked_edges(&mut io.graph, &data_dir).await?;
self.process_channels(&mut io.graph, &data_dir).await?;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0

0 comments on commit 60a9aca

Please sign in to comment.