The CI pipeline (`./check.sh`) was failing because of test errors, which was caused by the instrumentation framework complaining that no subscribers/listeners were registered. Instead of setting up all tests to run with a dummy subscriber, move the implementation of the instrumentation behind a feature flag so that it runs only for tests. There's a catch though: the `#[cfg(test)]` directive works only when directly testing the crate. If a crate `A` depends on another crate `B`, `B` will be compiled as usual (aka not in test mode) which will not trigger the `test` flag. So we need to introduce our own `testing` feature flag for `harmony` core and import it with that flag (only during dev/test). More info: https://github.com/rust-lang/rust/issues/59168 Co-authored-by: Ian Letourneau <letourneau.ian@gmail.com> Reviewed-on: https://git.nationtech.io/NationTech/harmony/pulls/102
84 lines
2.0 KiB
Rust
84 lines
2.0 KiB
Rust
use std::path::PathBuf;
|
|
|
|
use async_trait::async_trait;
|
|
use log::debug;
|
|
use serde::Serialize;
|
|
|
|
use crate::{
|
|
config::HARMONY_DATA_DIR,
|
|
data::{Id, Version},
|
|
interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome},
|
|
inventory::Inventory,
|
|
score::Score,
|
|
topology::Topology,
|
|
};
|
|
|
|
#[derive(Debug, Clone, Serialize)]
|
|
pub struct K3DInstallationScore {
|
|
pub installation_path: PathBuf,
|
|
pub cluster_name: String,
|
|
}
|
|
|
|
impl Default for K3DInstallationScore {
|
|
fn default() -> Self {
|
|
Self {
|
|
installation_path: HARMONY_DATA_DIR.join("k3d"),
|
|
cluster_name: "harmony".to_string(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<T: Topology> Score<T> for K3DInstallationScore {
|
|
fn create_interpret(&self) -> Box<dyn Interpret<T>> {
|
|
Box::new(K3dInstallationInterpret {
|
|
score: self.clone(),
|
|
})
|
|
}
|
|
|
|
fn name(&self) -> String {
|
|
"K3dInstallationScore".into()
|
|
}
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct K3dInstallationInterpret {
|
|
score: K3DInstallationScore,
|
|
}
|
|
|
|
#[async_trait]
|
|
impl<T: Topology> Interpret<T> for K3dInstallationInterpret {
|
|
async fn execute(
|
|
&self,
|
|
_inventory: &Inventory,
|
|
_topology: &T,
|
|
) -> Result<Outcome, InterpretError> {
|
|
let k3d = k3d_rs::K3d::new(
|
|
self.score.installation_path.clone(),
|
|
Some(self.score.cluster_name.clone()),
|
|
);
|
|
|
|
match k3d.ensure_installed().await {
|
|
Ok(_client) => {
|
|
let msg = format!("k3d cluster '{}' installed ", self.score.cluster_name);
|
|
debug!("{msg}");
|
|
Ok(Outcome::success(msg))
|
|
}
|
|
Err(msg) => Err(InterpretError::new(format!(
|
|
"failed to ensure k3d is installed : {msg}"
|
|
))),
|
|
}
|
|
}
|
|
fn get_name(&self) -> InterpretName {
|
|
InterpretName::K3dInstallation
|
|
}
|
|
fn get_version(&self) -> Version {
|
|
todo!()
|
|
}
|
|
fn get_status(&self) -> InterpretStatus {
|
|
todo!()
|
|
}
|
|
fn get_children(&self) -> Vec<Id> {
|
|
todo!()
|
|
}
|
|
}
|