add event to track progress of interprets, change a bunch of info! to debug!
All checks were successful
Run Check Script / check (pull_request) Successful in -34s
All checks were successful
Run Check Script / check (pull_request) Successful in -34s
This commit is contained in:
parent
ff7801a7c1
commit
49f1e56599
@ -2,7 +2,7 @@ use log::debug;
|
|||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use tokio::sync::broadcast;
|
use tokio::sync::broadcast;
|
||||||
|
|
||||||
use super::interpret::InterpretStatus;
|
use super::interpret::{InterpretError, InterpretStatus, Outcome};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum HarmonyEvent {
|
pub enum HarmonyEvent {
|
||||||
@ -12,7 +12,17 @@ pub enum HarmonyEvent {
|
|||||||
},
|
},
|
||||||
TopologyPrepared {
|
TopologyPrepared {
|
||||||
name: String,
|
name: String,
|
||||||
status: InterpretStatus,
|
outcome: Outcome,
|
||||||
|
},
|
||||||
|
InterpretExecutionStarted {
|
||||||
|
name: String,
|
||||||
|
topology: String,
|
||||||
|
message: String,
|
||||||
|
},
|
||||||
|
InterpretExecutionFinished {
|
||||||
|
topology: String,
|
||||||
|
name: String,
|
||||||
|
outcome: Result<Outcome, InterpretError>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
use std::sync::{Arc, Mutex, RwLock};
|
use std::sync::{Arc, Mutex, RwLock};
|
||||||
|
|
||||||
use log::{info, warn};
|
use log::{debug, info, warn};
|
||||||
|
|
||||||
use crate::instrumentation::{self, HarmonyEvent};
|
use crate::instrumentation::{self, HarmonyEvent};
|
||||||
|
|
||||||
@ -47,17 +47,11 @@ impl<T: Topology> Maestro<T> {
|
|||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
instrumentation::instrument(HarmonyEvent::TopologyPrepared {
|
|
||||||
name: self.topology.name().to_string(),
|
|
||||||
status: InterpretStatus::SUCCESS,
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let outcome = self.topology.ensure_ready().await?;
|
let outcome = self.topology.ensure_ready().await?;
|
||||||
|
|
||||||
instrumentation::instrument(HarmonyEvent::TopologyPrepared {
|
instrumentation::instrument(HarmonyEvent::TopologyPrepared {
|
||||||
name: self.topology.name().to_string(),
|
name: self.topology.name().to_string(),
|
||||||
status: outcome.status.clone(),
|
outcome: outcome.clone(),
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
@ -93,11 +87,11 @@ impl<T: Topology> Maestro<T> {
|
|||||||
self.topology.name(),
|
self.topology.name(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
info!("Running score {score:?}");
|
debug!("Running score {score:?}");
|
||||||
let interpret = score.create_interpret();
|
let interpret = score.create_interpret();
|
||||||
info!("Launching interpret {interpret:?}");
|
debug!("Launching interpret {interpret:?}");
|
||||||
let result = interpret.execute(&self.inventory, &self.topology).await;
|
let result = interpret.execute(&self.inventory, &self.topology).await;
|
||||||
info!("Got result {result:?}");
|
debug!("Got result {result:?}");
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -157,22 +157,13 @@ impl K8sAnywhereTopology {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !k8s_anywhere_config.autoinstall {
|
if !k8s_anywhere_config.autoinstall {
|
||||||
debug!("Autoinstall confirmation prompt");
|
warn!(
|
||||||
let confirmation = Confirm::new( "Harmony autoinstallation is not activated, do you wish to launch autoinstallation? :")
|
"Installation cancelled, K8sAnywhere could not initialize a valid Kubernetes client"
|
||||||
.with_default(false)
|
);
|
||||||
.prompt()
|
return Ok(None);
|
||||||
.expect("Unexpected prompt error");
|
|
||||||
debug!("Autoinstall confirmation {confirmation}");
|
|
||||||
|
|
||||||
if !confirmation {
|
|
||||||
warn!(
|
|
||||||
"Installation cancelled, K8sAnywhere could not initialize a valid Kubernetes client"
|
|
||||||
);
|
|
||||||
return Ok(None);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("Starting K8sAnywhere installation");
|
debug!("Starting K8sAnywhere installation");
|
||||||
self.try_install_k3d().await?;
|
self.try_install_k3d().await?;
|
||||||
let k3d_score = self.get_k3d_installation_score();
|
let k3d_score = self.get_k3d_installation_score();
|
||||||
// I feel like having to rely on the k3d_rs crate here is a smell
|
// I feel like having to rely on the k3d_rs crate here is a smell
|
||||||
@ -185,7 +176,7 @@ impl K8sAnywhereTopology {
|
|||||||
Ok(client) => K8sState {
|
Ok(client) => K8sState {
|
||||||
client: Arc::new(K8sClient::new(client)),
|
client: Arc::new(K8sClient::new(client)),
|
||||||
_source: K8sSource::LocalK3d,
|
_source: K8sSource::LocalK3d,
|
||||||
message: "Successfully installed K3D cluster and acquired client".to_string(),
|
message: "K8s client ready".to_string(),
|
||||||
},
|
},
|
||||||
Err(_) => todo!(),
|
Err(_) => todo!(),
|
||||||
};
|
};
|
||||||
@ -236,7 +227,7 @@ pub struct K8sAnywhereConfig {
|
|||||||
///
|
///
|
||||||
/// When enabled, autoinstall will setup a K3D cluster on the localhost. https://k3d.io/stable/
|
/// When enabled, autoinstall will setup a K3D cluster on the localhost. https://k3d.io/stable/
|
||||||
///
|
///
|
||||||
/// Default: false
|
/// Default: true
|
||||||
pub autoinstall: bool,
|
pub autoinstall: bool,
|
||||||
|
|
||||||
/// Whether to use local k3d cluster.
|
/// Whether to use local k3d cluster.
|
||||||
@ -255,7 +246,7 @@ impl K8sAnywhereConfig {
|
|||||||
use_system_kubeconfig: std::env::var("HARMONY_USE_SYSTEM_KUBECONFIG")
|
use_system_kubeconfig: std::env::var("HARMONY_USE_SYSTEM_KUBECONFIG")
|
||||||
.map_or_else(|_| false, |v| v.parse().ok().unwrap_or(false)),
|
.map_or_else(|_| false, |v| v.parse().ok().unwrap_or(false)),
|
||||||
autoinstall: std::env::var("HARMONY_AUTOINSTALL")
|
autoinstall: std::env::var("HARMONY_AUTOINSTALL")
|
||||||
.map_or_else(|_| false, |v| v.parse().ok().unwrap_or(false)),
|
.map_or_else(|_| true, |v| v.parse().ok().unwrap_or(false)),
|
||||||
// TODO harmony_profile should be managed at a more core level than this
|
// TODO harmony_profile should be managed at a more core level than this
|
||||||
harmony_profile: std::env::var("HARMONY_PROFILE").map_or_else(
|
harmony_profile: std::env::var("HARMONY_PROFILE").map_or_else(
|
||||||
|_| "dev".to_string(),
|
|_| "dev".to_string(),
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
use std::{io::Write, process::Command, sync::Arc};
|
use std::{io::Write, process::Command, sync::Arc};
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use log::{error, info};
|
use log::{debug, error};
|
||||||
use serde_yaml::Value;
|
use serde_yaml::Value;
|
||||||
use tempfile::NamedTempFile;
|
use tempfile::NamedTempFile;
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ impl<A: OCICompliant + HelmPackage> ContinuousDelivery<A> {
|
|||||||
error!("TODO hardcoded k3d bin path is wrong");
|
error!("TODO hardcoded k3d bin path is wrong");
|
||||||
let k3d_bin_path = (*HARMONY_DATA_DIR).join("k3d").join("k3d");
|
let k3d_bin_path = (*HARMONY_DATA_DIR).join("k3d").join("k3d");
|
||||||
// --- 1. Import the container image into the k3d cluster ---
|
// --- 1. Import the container image into the k3d cluster ---
|
||||||
info!(
|
debug!(
|
||||||
"Importing image '{}' into k3d cluster 'harmony'",
|
"Importing image '{}' into k3d cluster 'harmony'",
|
||||||
image_name
|
image_name
|
||||||
);
|
);
|
||||||
@ -80,7 +80,7 @@ impl<A: OCICompliant + HelmPackage> ContinuousDelivery<A> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// --- 2. Get the kubeconfig for the k3d cluster and write it to a temp file ---
|
// --- 2. Get the kubeconfig for the k3d cluster and write it to a temp file ---
|
||||||
info!("Retrieving kubeconfig for k3d cluster 'harmony'");
|
debug!("Retrieving kubeconfig for k3d cluster 'harmony'");
|
||||||
let kubeconfig_output = Command::new(&k3d_bin_path)
|
let kubeconfig_output = Command::new(&k3d_bin_path)
|
||||||
.args(["kubeconfig", "get", "harmony"])
|
.args(["kubeconfig", "get", "harmony"])
|
||||||
.output()
|
.output()
|
||||||
@ -101,7 +101,7 @@ impl<A: OCICompliant + HelmPackage> ContinuousDelivery<A> {
|
|||||||
let kubeconfig_path = temp_kubeconfig.path().to_str().unwrap();
|
let kubeconfig_path = temp_kubeconfig.path().to_str().unwrap();
|
||||||
|
|
||||||
// --- 3. Install or upgrade the Helm chart in the cluster ---
|
// --- 3. Install or upgrade the Helm chart in the cluster ---
|
||||||
info!(
|
debug!(
|
||||||
"Deploying Helm chart '{}' to namespace '{}'",
|
"Deploying Helm chart '{}' to namespace '{}'",
|
||||||
chart_url, app_name
|
chart_url, app_name
|
||||||
);
|
);
|
||||||
@ -131,7 +131,7 @@ impl<A: OCICompliant + HelmPackage> ContinuousDelivery<A> {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("Successfully deployed '{}' to local k3d cluster.", app_name);
|
debug!("Successfully deployed '{}' to local k3d cluster.", app_name);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -145,24 +145,19 @@ impl<
|
|||||||
async fn ensure_installed(&self, topology: &T) -> Result<(), String> {
|
async fn ensure_installed(&self, topology: &T) -> Result<(), String> {
|
||||||
let image = self.application.image_name();
|
let image = self.application.image_name();
|
||||||
|
|
||||||
// TODO
|
|
||||||
error!(
|
|
||||||
"TODO reverse helm chart packaging and docker image build. I put helm package first for faster iterations"
|
|
||||||
);
|
|
||||||
|
|
||||||
// TODO Write CI/CD workflow files
|
// TODO Write CI/CD workflow files
|
||||||
// we can autotedect the CI type using the remote url (default to github action for github
|
// we can autotedect the CI type using the remote url (default to github action for github
|
||||||
// url, etc..)
|
// url, etc..)
|
||||||
// Or ask for it when unknown
|
// Or ask for it when unknown
|
||||||
|
|
||||||
let helm_chart = self.application.build_push_helm_package(&image).await?;
|
let helm_chart = self.application.build_push_helm_package(&image).await?;
|
||||||
info!("Pushed new helm chart {helm_chart}");
|
debug!("Pushed new helm chart {helm_chart}");
|
||||||
|
|
||||||
error!("TODO Make building image configurable/skippable if image already exists (prompt)");
|
error!("TODO Make building image configurable/skippable if image already exists (prompt)");
|
||||||
let image = self.application.build_push_oci_image().await?;
|
let image = self.application.build_push_oci_image().await?;
|
||||||
info!("Pushed new docker image {image}");
|
debug!("Pushed new docker image {image}");
|
||||||
|
|
||||||
info!("Installing ContinuousDelivery feature");
|
debug!("Installing ContinuousDelivery feature");
|
||||||
// TODO this is a temporary hack for demo purposes, the deployment target should be driven
|
// TODO this is a temporary hack for demo purposes, the deployment target should be driven
|
||||||
// by the topology only and we should not have to know how to perform tasks like this for
|
// by the topology only and we should not have to know how to perform tasks like this for
|
||||||
// which the topology should be responsible.
|
// which the topology should be responsible.
|
||||||
@ -182,7 +177,7 @@ impl<
|
|||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
target => {
|
target => {
|
||||||
info!("Deploying to target {target:?}");
|
debug!("Deploying to target {target:?}");
|
||||||
let score = ArgoHelmScore {
|
let score = ArgoHelmScore {
|
||||||
namespace: "harmonydemo-staging".to_string(),
|
namespace: "harmonydemo-staging".to_string(),
|
||||||
openshift: false,
|
openshift: false,
|
||||||
|
|||||||
@ -5,7 +5,7 @@ mod rust;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub use feature::*;
|
pub use feature::*;
|
||||||
use log::info;
|
use log::debug;
|
||||||
pub use oci::*;
|
pub use oci::*;
|
||||||
pub use rust::*;
|
pub use rust::*;
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ impl<A: Application, T: Topology + std::fmt::Debug> Interpret<T> for Application
|
|||||||
topology: &T,
|
topology: &T,
|
||||||
) -> Result<Outcome, InterpretError> {
|
) -> Result<Outcome, InterpretError> {
|
||||||
let app_name = self.application.name();
|
let app_name = self.application.name();
|
||||||
info!(
|
debug!(
|
||||||
"Preparing {} features [{}] for application {app_name}",
|
"Preparing {} features [{}] for application {app_name}",
|
||||||
self.features.len(),
|
self.features.len(),
|
||||||
self.features
|
self.features
|
||||||
@ -46,7 +46,7 @@ impl<A: Application, T: Topology + std::fmt::Debug> Interpret<T> for Application
|
|||||||
.join(", ")
|
.join(", ")
|
||||||
);
|
);
|
||||||
for feature in self.features.iter() {
|
for feature in self.features.iter() {
|
||||||
info!(
|
debug!(
|
||||||
"Installing feature {} for application {app_name}",
|
"Installing feature {} for application {app_name}",
|
||||||
feature.name()
|
feature.name()
|
||||||
);
|
);
|
||||||
|
|||||||
@ -10,7 +10,7 @@ use dockerfile_builder::Dockerfile;
|
|||||||
use dockerfile_builder::instruction::{CMD, COPY, ENV, EXPOSE, FROM, RUN, USER, WORKDIR};
|
use dockerfile_builder::instruction::{CMD, COPY, ENV, EXPOSE, FROM, RUN, USER, WORKDIR};
|
||||||
use dockerfile_builder::instruction_builder::CopyBuilder;
|
use dockerfile_builder::instruction_builder::CopyBuilder;
|
||||||
use futures_util::StreamExt;
|
use futures_util::StreamExt;
|
||||||
use log::{debug, error, info, log_enabled};
|
use log::{debug, error, log_enabled};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use tar::Archive;
|
use tar::Archive;
|
||||||
|
|
||||||
@ -73,19 +73,19 @@ impl Application for RustWebapp {
|
|||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl HelmPackage for RustWebapp {
|
impl HelmPackage for RustWebapp {
|
||||||
async fn build_push_helm_package(&self, image_url: &str) -> Result<String, String> {
|
async fn build_push_helm_package(&self, image_url: &str) -> Result<String, String> {
|
||||||
info!("Starting Helm chart build and push for '{}'", self.name);
|
debug!("Starting Helm chart build and push for '{}'", self.name);
|
||||||
|
|
||||||
// 1. Create the Helm chart files on disk.
|
// 1. Create the Helm chart files on disk.
|
||||||
let chart_dir = self
|
let chart_dir = self
|
||||||
.create_helm_chart_files(image_url)
|
.create_helm_chart_files(image_url)
|
||||||
.map_err(|e| format!("Failed to create Helm chart files: {}", e))?;
|
.map_err(|e| format!("Failed to create Helm chart files: {}", e))?;
|
||||||
info!("Successfully created Helm chart files in {:?}", chart_dir);
|
debug!("Successfully created Helm chart files in {:?}", chart_dir);
|
||||||
|
|
||||||
// 2. Package the chart into a .tgz archive.
|
// 2. Package the chart into a .tgz archive.
|
||||||
let packaged_chart_path = self
|
let packaged_chart_path = self
|
||||||
.package_helm_chart(&chart_dir)
|
.package_helm_chart(&chart_dir)
|
||||||
.map_err(|e| format!("Failed to package Helm chart: {}", e))?;
|
.map_err(|e| format!("Failed to package Helm chart: {}", e))?;
|
||||||
info!(
|
debug!(
|
||||||
"Successfully packaged Helm chart: {}",
|
"Successfully packaged Helm chart: {}",
|
||||||
packaged_chart_path.to_string_lossy()
|
packaged_chart_path.to_string_lossy()
|
||||||
);
|
);
|
||||||
@ -94,7 +94,7 @@ impl HelmPackage for RustWebapp {
|
|||||||
let oci_chart_url = self
|
let oci_chart_url = self
|
||||||
.push_helm_chart(&packaged_chart_path)
|
.push_helm_chart(&packaged_chart_path)
|
||||||
.map_err(|e| format!("Failed to push Helm chart: {}", e))?;
|
.map_err(|e| format!("Failed to push Helm chart: {}", e))?;
|
||||||
info!("Successfully pushed Helm chart to: {}", oci_chart_url);
|
debug!("Successfully pushed Helm chart to: {}", oci_chart_url);
|
||||||
|
|
||||||
Ok(oci_chart_url)
|
Ok(oci_chart_url)
|
||||||
}
|
}
|
||||||
@ -107,20 +107,20 @@ impl OCICompliant for RustWebapp {
|
|||||||
async fn build_push_oci_image(&self) -> Result<String, String> {
|
async fn build_push_oci_image(&self) -> Result<String, String> {
|
||||||
// This function orchestrates the build and push process.
|
// This function orchestrates the build and push process.
|
||||||
// It's async to match the trait definition, though the underlying docker commands are blocking.
|
// It's async to match the trait definition, though the underlying docker commands are blocking.
|
||||||
info!("Starting OCI image build and push for '{}'", self.name);
|
debug!("Starting OCI image build and push for '{}'", self.name);
|
||||||
|
|
||||||
// 1. Build the image by calling the synchronous helper function.
|
// 1. Build the image by calling the synchronous helper function.
|
||||||
let image_tag = self.image_name();
|
let image_tag = self.image_name();
|
||||||
self.build_docker_image(&image_tag)
|
self.build_docker_image(&image_tag)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| format!("Failed to build Docker image: {}", e))?;
|
.map_err(|e| format!("Failed to build Docker image: {}", e))?;
|
||||||
info!("Successfully built Docker image: {}", image_tag);
|
debug!("Successfully built Docker image: {}", image_tag);
|
||||||
|
|
||||||
// 2. Push the image to the registry.
|
// 2. Push the image to the registry.
|
||||||
self.push_docker_image(&image_tag)
|
self.push_docker_image(&image_tag)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| format!("Failed to push Docker image: {}", e))?;
|
.map_err(|e| format!("Failed to push Docker image: {}", e))?;
|
||||||
info!("Successfully pushed Docker image to: {}", image_tag);
|
debug!("Successfully pushed Docker image to: {}", image_tag);
|
||||||
|
|
||||||
Ok(image_tag)
|
Ok(image_tag)
|
||||||
}
|
}
|
||||||
@ -159,7 +159,7 @@ impl RustWebapp {
|
|||||||
&self,
|
&self,
|
||||||
image_name: &str,
|
image_name: &str,
|
||||||
) -> Result<String, Box<dyn std::error::Error>> {
|
) -> Result<String, Box<dyn std::error::Error>> {
|
||||||
info!("Generating Dockerfile for '{}'", self.name);
|
debug!("Generating Dockerfile for '{}'", self.name);
|
||||||
let _dockerfile_path = self.build_dockerfile()?;
|
let _dockerfile_path = self.build_dockerfile()?;
|
||||||
|
|
||||||
let docker = Docker::connect_with_socket_defaults().unwrap();
|
let docker = Docker::connect_with_socket_defaults().unwrap();
|
||||||
@ -206,7 +206,7 @@ impl RustWebapp {
|
|||||||
&self,
|
&self,
|
||||||
image_tag: &str,
|
image_tag: &str,
|
||||||
) -> Result<String, Box<dyn std::error::Error>> {
|
) -> Result<String, Box<dyn std::error::Error>> {
|
||||||
info!("Pushing docker image {image_tag}");
|
debug!("Pushing docker image {image_tag}");
|
||||||
|
|
||||||
let docker = Docker::connect_with_socket_defaults().unwrap();
|
let docker = Docker::connect_with_socket_defaults().unwrap();
|
||||||
|
|
||||||
@ -535,7 +535,7 @@ spec:
|
|||||||
chart_dir: &PathBuf,
|
chart_dir: &PathBuf,
|
||||||
) -> Result<PathBuf, Box<dyn std::error::Error>> {
|
) -> Result<PathBuf, Box<dyn std::error::Error>> {
|
||||||
let chart_dirname = chart_dir.file_name().expect("Should find a chart dirname");
|
let chart_dirname = chart_dir.file_name().expect("Should find a chart dirname");
|
||||||
info!(
|
debug!(
|
||||||
"Launching `helm package {}` cli with CWD {}",
|
"Launching `helm package {}` cli with CWD {}",
|
||||||
chart_dirname.to_string_lossy(),
|
chart_dirname.to_string_lossy(),
|
||||||
&self
|
&self
|
||||||
@ -580,7 +580,7 @@ spec:
|
|||||||
let oci_push_url = format!("oci://{}/{}", *REGISTRY_URL, *REGISTRY_PROJECT);
|
let oci_push_url = format!("oci://{}/{}", *REGISTRY_URL, *REGISTRY_PROJECT);
|
||||||
let oci_pull_url = format!("{oci_push_url}/{}-chart", self.name);
|
let oci_pull_url = format!("{oci_push_url}/{}-chart", self.name);
|
||||||
|
|
||||||
info!(
|
debug!(
|
||||||
"Pushing Helm chart {} to {}",
|
"Pushing Helm chart {} to {}",
|
||||||
packaged_chart_path.to_string_lossy(),
|
packaged_chart_path.to_string_lossy(),
|
||||||
oci_push_url
|
oci_push_url
|
||||||
|
|||||||
@ -1,12 +1,13 @@
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use log::info;
|
use log::{debug, info};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::HARMONY_DATA_DIR,
|
config::HARMONY_DATA_DIR,
|
||||||
data::{Id, Version},
|
data::{Id, Version},
|
||||||
|
instrumentation::{self, HarmonyEvent},
|
||||||
interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome},
|
interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome},
|
||||||
inventory::Inventory,
|
inventory::Inventory,
|
||||||
score::Score,
|
score::Score,
|
||||||
@ -50,22 +51,38 @@ impl<T: Topology> Interpret<T> for K3dInstallationInterpret {
|
|||||||
async fn execute(
|
async fn execute(
|
||||||
&self,
|
&self,
|
||||||
_inventory: &Inventory,
|
_inventory: &Inventory,
|
||||||
_topology: &T,
|
topology: &T,
|
||||||
) -> Result<Outcome, InterpretError> {
|
) -> Result<Outcome, InterpretError> {
|
||||||
|
instrumentation::instrument(HarmonyEvent::InterpretExecutionStarted {
|
||||||
|
topology: topology.name().into(),
|
||||||
|
name: "k3d-installation".into(),
|
||||||
|
message: "installing k3d...".into(),
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let k3d = k3d_rs::K3d::new(
|
let k3d = k3d_rs::K3d::new(
|
||||||
self.score.installation_path.clone(),
|
self.score.installation_path.clone(),
|
||||||
Some(self.score.cluster_name.clone()),
|
Some(self.score.cluster_name.clone()),
|
||||||
);
|
);
|
||||||
match k3d.ensure_installed().await {
|
let outcome = match k3d.ensure_installed().await {
|
||||||
Ok(_client) => {
|
Ok(_client) => {
|
||||||
let msg = format!("k3d cluster {} is installed ", self.score.cluster_name);
|
let msg = format!("k3d cluster '{}' installed ", self.score.cluster_name);
|
||||||
info!("{msg}");
|
debug!("{msg}");
|
||||||
Ok(Outcome::success(msg))
|
Ok(Outcome::success(msg))
|
||||||
}
|
}
|
||||||
Err(msg) => Err(InterpretError::new(format!(
|
Err(msg) => Err(InterpretError::new(format!(
|
||||||
"K3dInstallationInterpret failed to ensure k3d is installed : {msg}"
|
"failed to ensure k3d is installed : {msg}"
|
||||||
))),
|
))),
|
||||||
}
|
};
|
||||||
|
|
||||||
|
instrumentation::instrument(HarmonyEvent::InterpretExecutionFinished {
|
||||||
|
topology: topology.name().into(),
|
||||||
|
name: "k3d-installation".into(),
|
||||||
|
outcome: outcome.clone(),
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
outcome
|
||||||
}
|
}
|
||||||
fn get_name(&self) -> InterpretName {
|
fn get_name(&self) -> InterpretName {
|
||||||
InterpretName::K3dInstallation
|
InterpretName::K3dInstallation
|
||||||
|
|||||||
@ -6,6 +6,8 @@ use std::{
|
|||||||
sync::{Arc, Mutex},
|
sync::{Arc, Mutex},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::progress;
|
||||||
|
|
||||||
pub fn init() -> tokio::task::JoinHandle<()> {
|
pub fn init() -> tokio::task::JoinHandle<()> {
|
||||||
configure_logger();
|
configure_logger();
|
||||||
let handle = tokio::spawn(handle_events());
|
let handle = tokio::spawn(handle_events());
|
||||||
@ -30,35 +32,78 @@ fn configure_logger() {
|
|||||||
|
|
||||||
async fn handle_events() {
|
async fn handle_events() {
|
||||||
instrumentation::subscribe("Harmony CLI Logger", {
|
instrumentation::subscribe("Harmony CLI Logger", {
|
||||||
let progresses: Arc<Mutex<HashMap<String, MultiProgress>>> =
|
let sections: Arc<Mutex<HashMap<String, MultiProgress>>> =
|
||||||
|
Arc::new(Mutex::new(HashMap::new()));
|
||||||
|
let progress_bars: Arc<Mutex<HashMap<String, ProgressBar>>> =
|
||||||
Arc::new(Mutex::new(HashMap::new()));
|
Arc::new(Mutex::new(HashMap::new()));
|
||||||
let topology_prepare_progress = Arc::new(Mutex::new(None::<ProgressBar>));
|
|
||||||
|
|
||||||
move |event| {
|
move |event| {
|
||||||
let progresses_clone = Arc::clone(&progresses);
|
let sections_clone = Arc::clone(§ions);
|
||||||
let topology_prepare_progress_clone = Arc::clone(&topology_prepare_progress);
|
let progress_bars_clone = Arc::clone(&progress_bars);
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
let mut progresses = progresses_clone.lock().unwrap();
|
let mut sections = sections_clone.lock().unwrap();
|
||||||
let mut topology_prepare_progress = topology_prepare_progress_clone.lock().unwrap();
|
let mut progress_bars = progress_bars_clone.lock().unwrap();
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
HarmonyEvent::HarmonyStarted => {}
|
HarmonyEvent::HarmonyStarted => {}
|
||||||
HarmonyEvent::PrepareTopologyStarted { name } => {
|
HarmonyEvent::PrepareTopologyStarted { name } => {
|
||||||
let multi_progress = crate::progress::new_section(format!(
|
let section = progress::new_section(format!(
|
||||||
"{} Preparing environment: {name}...",
|
"{} Preparing environment: {name}...",
|
||||||
crate::theme::EMOJI_TOPOLOGY,
|
crate::theme::EMOJI_TOPOLOGY,
|
||||||
));
|
));
|
||||||
(*progresses).insert(name, multi_progress);
|
(*sections).insert(name, section);
|
||||||
|
}
|
||||||
|
HarmonyEvent::TopologyPrepared { name, outcome } => {
|
||||||
|
let section = (*sections).get(&name).unwrap();
|
||||||
|
let progress = progress::add_spinner(section, "".into());
|
||||||
|
|
||||||
|
match outcome.status {
|
||||||
|
harmony::interpret::InterpretStatus::SUCCESS => {
|
||||||
|
progress::success(section, Some(progress), outcome.message);
|
||||||
|
}
|
||||||
|
harmony::interpret::InterpretStatus::FAILURE => {
|
||||||
|
progress::error(section, Some(progress), outcome.message);
|
||||||
|
}
|
||||||
|
harmony::interpret::InterpretStatus::RUNNING => todo!(),
|
||||||
|
harmony::interpret::InterpretStatus::QUEUED => todo!(),
|
||||||
|
harmony::interpret::InterpretStatus::BLOCKED => todo!(),
|
||||||
|
harmony::interpret::InterpretStatus::NOOP => {
|
||||||
|
progress::skip(section, Some(progress), outcome.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
HarmonyEvent::InterpretExecutionStarted {
|
||||||
|
name,
|
||||||
|
topology,
|
||||||
|
message,
|
||||||
|
} => {
|
||||||
|
let section = (*sections).get(&topology).unwrap();
|
||||||
|
let progress_bar = progress::add_spinner(section, message);
|
||||||
|
|
||||||
|
(*progress_bars).insert(name, progress_bar);
|
||||||
|
}
|
||||||
|
HarmonyEvent::InterpretExecutionFinished {
|
||||||
|
topology,
|
||||||
|
name,
|
||||||
|
outcome,
|
||||||
|
} => {
|
||||||
|
let section = (*sections).get(&topology).unwrap();
|
||||||
|
let progress_bar = (*progress_bars).get(&name).cloned();
|
||||||
|
|
||||||
|
let _ = section.clear();
|
||||||
|
|
||||||
|
match outcome {
|
||||||
|
Ok(outcome) => {
|
||||||
|
progress::success(section, progress_bar, outcome.message);
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
progress::error(section, progress_bar, err.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
(*progress_bars).remove(&name);
|
||||||
}
|
}
|
||||||
HarmonyEvent::TopologyPrepared { name, status } => match status {
|
|
||||||
harmony::interpret::InterpretStatus::SUCCESS => todo!(),
|
|
||||||
harmony::interpret::InterpretStatus::FAILURE => todo!(),
|
|
||||||
harmony::interpret::InterpretStatus::RUNNING => todo!(),
|
|
||||||
harmony::interpret::InterpretStatus::QUEUED => todo!(),
|
|
||||||
harmony::interpret::InterpretStatus::BLOCKED => todo!(),
|
|
||||||
harmony::interpret::InterpretStatus::NOOP => todo!(),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,6 +10,7 @@ pub mod theme;
|
|||||||
|
|
||||||
#[cfg(feature = "tui")]
|
#[cfg(feature = "tui")]
|
||||||
use harmony_tui;
|
use harmony_tui;
|
||||||
|
use log::debug;
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(version, about, long_about = None)]
|
#[command(version, about, long_about = None)]
|
||||||
@ -138,7 +139,7 @@ pub async fn init<T: Topology + Send + Sync + 'static>(
|
|||||||
|
|
||||||
// Run filtered scores
|
// Run filtered scores
|
||||||
for s in scores_vec {
|
for s in scores_vec {
|
||||||
println!("Running: {}", s.name());
|
debug!("Running: {}", s.name());
|
||||||
maestro.interpret(s).await?;
|
maestro.interpret(s).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -38,3 +38,13 @@ pub fn error(multi_progress: &MultiProgress, progress: Option<ProgressBar>, mess
|
|||||||
progress.set_style(crate::theme::ERROR_SPINNER_STYLE.clone());
|
progress.set_style(crate::theme::ERROR_SPINNER_STYLE.clone());
|
||||||
progress.finish_with_message(message);
|
progress.finish_with_message(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn skip(multi_progress: &MultiProgress, progress: Option<ProgressBar>, message: String) {
|
||||||
|
if let Some(progress) = progress {
|
||||||
|
multi_progress.remove(&progress)
|
||||||
|
}
|
||||||
|
|
||||||
|
let progress = multi_progress.add(ProgressBar::new_spinner());
|
||||||
|
progress.set_style(crate::theme::SKIP_SPINNER_STYLE.clone());
|
||||||
|
progress.finish_with_message(message);
|
||||||
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ use lazy_static::lazy_static;
|
|||||||
|
|
||||||
pub static EMOJI_HARMONY: Emoji<'_, '_> = Emoji("🎼", "");
|
pub static EMOJI_HARMONY: Emoji<'_, '_> = Emoji("🎼", "");
|
||||||
pub static EMOJI_SUCCESS: Emoji<'_, '_> = Emoji("✅", "");
|
pub static EMOJI_SUCCESS: Emoji<'_, '_> = Emoji("✅", "");
|
||||||
|
pub static EMOJI_SKIP: Emoji<'_, '_> = Emoji("⏭️", "");
|
||||||
pub static EMOJI_ERROR: Emoji<'_, '_> = Emoji("⚠️", "");
|
pub static EMOJI_ERROR: Emoji<'_, '_> = Emoji("⚠️", "");
|
||||||
pub static EMOJI_DEPLOY: Emoji<'_, '_> = Emoji("🚀", "");
|
pub static EMOJI_DEPLOY: Emoji<'_, '_> = Emoji("🚀", "");
|
||||||
pub static EMOJI_TOPOLOGY: Emoji<'_, '_> = Emoji("📦", "");
|
pub static EMOJI_TOPOLOGY: Emoji<'_, '_> = Emoji("📦", "");
|
||||||
@ -16,6 +17,9 @@ lazy_static! {
|
|||||||
pub static ref SUCCESS_SPINNER_STYLE: ProgressStyle = SPINNER_STYLE
|
pub static ref SUCCESS_SPINNER_STYLE: ProgressStyle = SPINNER_STYLE
|
||||||
.clone()
|
.clone()
|
||||||
.tick_strings(&[format!("{}", EMOJI_SUCCESS).as_str()]);
|
.tick_strings(&[format!("{}", EMOJI_SUCCESS).as_str()]);
|
||||||
|
pub static ref SKIP_SPINNER_STYLE: ProgressStyle = SPINNER_STYLE
|
||||||
|
.clone()
|
||||||
|
.tick_strings(&[format!("{}", EMOJI_SKIP).as_str()]);
|
||||||
pub static ref ERROR_SPINNER_STYLE: ProgressStyle = SPINNER_STYLE
|
pub static ref ERROR_SPINNER_STYLE: ProgressStyle = SPINNER_STYLE
|
||||||
.clone()
|
.clone()
|
||||||
.tick_strings(&[format!("{}", EMOJI_ERROR).as_str()]);
|
.tick_strings(&[format!("{}", EMOJI_ERROR).as_str()]);
|
||||||
|
|||||||
@ -2,7 +2,7 @@ mod downloadable_asset;
|
|||||||
use downloadable_asset::*;
|
use downloadable_asset::*;
|
||||||
|
|
||||||
use kube::Client;
|
use kube::Client;
|
||||||
use log::{debug, info, warn};
|
use log::{debug, warn};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
const K3D_BIN_FILE_NAME: &str = "k3d";
|
const K3D_BIN_FILE_NAME: &str = "k3d";
|
||||||
@ -90,7 +90,7 @@ impl K3d {
|
|||||||
let latest_release = self.get_latest_release_tag().await.unwrap();
|
let latest_release = self.get_latest_release_tag().await.unwrap();
|
||||||
|
|
||||||
let release_binary = self.get_binary_for_current_platform(latest_release).await;
|
let release_binary = self.get_binary_for_current_platform(latest_release).await;
|
||||||
info!("Foudn K3d binary to install : {release_binary:#?}");
|
debug!("Foudn K3d binary to install : {release_binary:#?}");
|
||||||
release_binary.download_to_path(self.base_dir.clone()).await
|
release_binary.download_to_path(self.base_dir.clone()).await
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,7 +175,7 @@ impl K3d {
|
|||||||
Err(_) => return Err("Could not get cluster_name, cannot initialize".to_string()),
|
Err(_) => return Err("Could not get cluster_name, cannot initialize".to_string()),
|
||||||
};
|
};
|
||||||
|
|
||||||
info!("Initializing k3d cluster '{}'", cluster_name);
|
debug!("Initializing k3d cluster '{}'", cluster_name);
|
||||||
|
|
||||||
self.create_cluster(cluster_name)?;
|
self.create_cluster(cluster_name)?;
|
||||||
self.create_kubernetes_client().await
|
self.create_kubernetes_client().await
|
||||||
@ -205,7 +205,7 @@ impl K3d {
|
|||||||
/// - `Err(String)` - Error message if any step failed
|
/// - `Err(String)` - Error message if any step failed
|
||||||
pub async fn ensure_installed(&self) -> Result<Client, String> {
|
pub async fn ensure_installed(&self) -> Result<Client, String> {
|
||||||
if !self.is_installed() {
|
if !self.is_installed() {
|
||||||
info!("K3d is not installed, downloading latest release");
|
debug!("K3d is not installed, downloading latest release");
|
||||||
self.download_latest_release()
|
self.download_latest_release()
|
||||||
.await
|
.await
|
||||||
.map_err(|e| format!("Failed to download k3d: {}", e))?;
|
.map_err(|e| format!("Failed to download k3d: {}", e))?;
|
||||||
@ -216,13 +216,13 @@ impl K3d {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !self.is_cluster_initialized() {
|
if !self.is_cluster_initialized() {
|
||||||
info!("Cluster is not initialized, initializing now");
|
debug!("Cluster is not initialized, initializing now");
|
||||||
return self.initialize_cluster().await;
|
return self.initialize_cluster().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.start_cluster().await?;
|
self.start_cluster().await?;
|
||||||
|
|
||||||
info!("K3d and cluster are already properly set up");
|
debug!("K3d and cluster are already properly set up");
|
||||||
self.create_kubernetes_client().await
|
self.create_kubernetes_client().await
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -325,12 +325,11 @@ impl K3d {
|
|||||||
return Err(format!("Failed to create cluster: {}", stderr));
|
return Err(format!("Failed to create cluster: {}", stderr));
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("Successfully created k3d cluster '{}'", cluster_name);
|
debug!("Successfully created k3d cluster '{}'", cluster_name);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create_kubernetes_client(&self) -> Result<Client, String> {
|
async fn create_kubernetes_client(&self) -> Result<Client, String> {
|
||||||
warn!("TODO this method is way too dumb, it should make sure that the client is connected to the k3d cluster actually represented by this instance, not just any default client");
|
|
||||||
Client::try_default()
|
Client::try_default()
|
||||||
.await
|
.await
|
||||||
.map_err(|e| format!("Failed to create Kubernetes client: {}", e))
|
.map_err(|e| format!("Failed to create Kubernetes client: {}", e))
|
||||||
@ -352,7 +351,7 @@ impl K3d {
|
|||||||
return Err(format!("Failed to start cluster: {}", stderr));
|
return Err(format!("Failed to start cluster: {}", stderr));
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("Successfully started k3d cluster '{}'", cluster_name);
|
debug!("Successfully started k3d cluster '{}'", cluster_name);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user