diff --git a/harmony/src/domain/topology/monitoring_alerting.rs b/harmony/src/domain/topology/monitoring_alerting.rs index 3dee18c..fa60f37 100644 --- a/harmony/src/domain/topology/monitoring_alerting.rs +++ b/harmony/src/domain/topology/monitoring_alerting.rs @@ -1,5 +1,6 @@ +use std::sync::Arc; + use log::warn; -use serde::Serialize; use tokio::sync::OnceCell; use k8s_openapi::api::core::v1::Pod; @@ -18,7 +19,7 @@ use crate::{ score::Score, }; -use super::{HelmCommand, K8sAnywhereTopology, Topology}; +use super::{HelmCommand, K8sAnywhereTopology, Topology, k8s::K8sClient}; #[derive(Clone, Debug)] struct MonitoringState { @@ -28,19 +29,12 @@ struct MonitoringState { #[derive(Debug)] pub struct MonitoringAlertingTopology { monitoring_state: OnceCell>, - namespace: String, - monitoring_stack: Vec>>, } impl MonitoringAlertingTopology { - pub fn new( - namespace: String, - monitoring_stack: Vec>>, - ) -> Self { + pub fn new() -> Self { Self { monitoring_state: OnceCell::new(), - namespace, - monitoring_stack, } } @@ -81,31 +75,8 @@ impl MonitoringAlertingTopology { Ok(None) } - - async fn try_install_monitoring_stack( - &self, - ) -> Result, InterpretError> { - let inventory = Inventory::autoload(); - let topology = K8sAnywhereTopology::new(); - let mut maestro = match Maestro::initialize(inventory, topology).await { - Ok(m) => m, - Err(e) => { - println!("failed to initialize Maestro: {}", e); - std::process::exit(1); - } - }; - maestro.register_all(vec![Box::new(MonitoringAlertingStackScore::new(self.monitoring_stack.clone(), self.namespace.clone()))]); - let state = match self.get_monitoring_state().await { - Ok(_) => MonitoringState { - message: "Monitoring Stack Ready".to_string(), - }, - Err(_) => todo!(), - }; - Ok(Some(state)) - } } - impl Clone for Box> { fn clone(&self) -> Box> { self.clone_box() @@ -119,15 +90,16 @@ impl Topology for MonitoringAlertingTopology { } async fn ensure_ready(&self) -> Result { - let state = if let Some(state) = self.get_monitoring_state().await? { - state - } else { - self.try_install_monitoring_stack() - .await? - .ok_or_else(|| InterpretError::new("Failed to install monitoring stack".into()))? - }; + if let Some(state) = self.get_monitoring_state().await? { + // Monitoring stack is already ready — stop app. + println!("{}", state.message); + std::process::exit(0); + } - Ok(Outcome::success(state.message)) + // Monitoring not found — proceed with installation. + Ok(Outcome::success( + "Monitoring stack installation started.".to_string(), + )) } } diff --git a/harmony/src/modules/monitoring/kube_prometheus.rs b/harmony/src/modules/monitoring/kube_prometheus.rs index 8cfbcf3..52dcee9 100644 --- a/harmony/src/modules/monitoring/kube_prometheus.rs +++ b/harmony/src/modules/monitoring/kube_prometheus.rs @@ -38,5 +38,8 @@ additionalPrometheusRules: .unwrap(), chart_version: None, values_overrides: None, + values_yaml: Some(values.to_string()), + create_namespace: true, + install_only: true, } } diff --git a/harmony/src/modules/monitoring/monitoring_alerting.rs b/harmony/src/modules/monitoring/monitoring_alerting.rs index 2bc0cb4..7622f86 100644 --- a/harmony/src/modules/monitoring/monitoring_alerting.rs +++ b/harmony/src/modules/monitoring/monitoring_alerting.rs @@ -5,10 +5,9 @@ use crate::{ data::{Id, Version}, interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, inventory::Inventory, - maestro::{self, Maestro}, - modules::helm::chart::HelmChartScore, + maestro::Maestro, score::{CloneBoxScore, Score}, - topology::{K8sclient, Topology, monitoring_alerting::MonitoringAlertingTopology}, + topology::{HelmCommand, Topology, monitoring_alerting::MonitoringAlertingTopology}, }; use super::kube_prometheus::kube_prometheus_score; @@ -20,8 +19,14 @@ pub struct MonitoringAlertingStackScore { } impl MonitoringAlertingStackScore { - pub fn new(monitoring_stack: Vec>>, namespace: String) -> Self { - Self { monitoring_stack, namespace } + pub fn new( + monitoring_stack: Vec>>, + namespace: String, + ) -> Self { + Self { + monitoring_stack, + namespace, + } } } @@ -29,10 +34,8 @@ impl Default for MonitoringAlertingStackScore { fn default() -> Self { let ns = "monitoring"; Self { - monitoring_stack: vec![ - Box::new(kube_prometheus_score(ns)) as Box> - ], - namespace: ns.to_string() + monitoring_stack: vec![Box::new(kube_prometheus_score(ns))], + namespace: ns.to_string(), } } } @@ -66,7 +69,7 @@ impl Serialize for MonitoringAlertingStackScore { } } -impl Score for MonitoringAlertingStackScore { +impl Score for MonitoringAlertingStackScore { fn create_interpret(&self) -> Box> { Box::new(MonitoringAlertingStackInterpret { score: MonitoringAlertingStackScore { @@ -91,14 +94,14 @@ struct MonitoringAlertingStackInterpret { } #[async_trait] -impl Interpret for MonitoringAlertingStackInterpret { +impl Interpret for MonitoringAlertingStackInterpret { async fn execute( &self, _inventory: &Inventory, _topology: &T, ) -> Result { let inventory = Inventory::autoload(); - let topology = MonitoringAlertingTopology::new(self.score.namespace.clone(), self.score.monitoring_stack.clone()); + let topology = MonitoringAlertingTopology::new(); let mut maestro = match Maestro::initialize(inventory, topology).await { Ok(m) => m, Err(e) => { @@ -106,9 +109,12 @@ impl Interpret for MonitoringAlertingStackInterpret { std::process::exit(1); } }; - Ok(Outcome::success(format!("monitoring stack installed in {} namespace",self.score.namespace ))) + maestro.register_all(self.score.monitoring_stack.clone()); + Ok(Outcome::success(format!( + "monitoring stack installed in {} namespace", + self.score.namespace + ))) } - fn get_name(&self) -> InterpretName { todo!()