chore: modified build config to be able to pass namespace to the config

This commit is contained in:
Willem 2025-05-15 15:19:40 -04:00
parent b4c6848433
commit eb8a8a2e04
3 changed files with 21 additions and 26 deletions

View File

@ -43,8 +43,8 @@ async fn main() {
.await .await
.unwrap(); .unwrap();
let monitoring_stack_score = let mut monitoring_stack_score = MonitoringAlertingStackScore::new();
MonitoringAlertingStackScore::new_with_ns(&lamp_stack.config.namespace); monitoring_stack_score.namespace = Some(lamp_stack.config.namespace.clone());
maestro.register_all(vec![Box::new(lamp_stack), Box::new(monitoring_stack_score)]); maestro.register_all(vec![Box::new(lamp_stack), Box::new(monitoring_stack_score)]);
// Here we bootstrap the CLI, this gives some nice features if you need them // Here we bootstrap the CLI, this gives some nice features if you need them

View File

@ -4,7 +4,7 @@ use std::{collections::HashMap, str::FromStr};
use crate::modules::helm::chart::HelmChartScore; use crate::modules::helm::chart::HelmChartScore;
pub fn kube_prometheus_score(config: &KubePrometheusConfig) -> HelmChartScore { pub fn kube_prometheus_helm_chart_score(config: &KubePrometheusConfig) -> HelmChartScore {
//TODO this should be make into a rule with default formatting that can be easily passed as a vec //TODO this should be make into a rule with default formatting that can be easily passed as a vec
//to the overrides or something leaving the user to deal with formatting here seems bad //to the overrides or something leaving the user to deal with formatting here seems bad
let values = r#" let values = r#"

View File

@ -9,7 +9,7 @@ use crate::{
topology::{HelmCommand, Topology}, topology::{HelmCommand, Topology},
}; };
use super::{config::KubePrometheusConfig, kube_prometheus::kube_prometheus_score}; use super::{config::KubePrometheusConfig, kube_prometheus::kube_prometheus_helm_chart_score};
#[derive(Debug, Clone, Serialize)] #[derive(Debug, Clone, Serialize)]
pub enum AlertChannel { pub enum AlertChannel {
@ -33,9 +33,17 @@ pub enum Stack {
pub struct MonitoringAlertingStackScore { pub struct MonitoringAlertingStackScore {
pub alert_channel: Option<AlertChannel>, pub alert_channel: Option<AlertChannel>,
pub monitoring_stack: Stack, pub monitoring_stack: Stack,
pub namespace: Option<String>,
} }
impl MonitoringAlertingStackScore { impl MonitoringAlertingStackScore {
pub fn new() -> Self {
Self {
alert_channel: None,
monitoring_stack: Stack::KubePrometheusStack,
namespace: None,
}
}
fn match_alert_channel(&self, config: &mut KubePrometheusConfig) { fn match_alert_channel(&self, config: &mut KubePrometheusConfig) {
if let Some(alert_channel) = &self.alert_channel { if let Some(alert_channel) = &self.alert_channel {
match alert_channel { match alert_channel {
@ -55,25 +63,13 @@ impl MonitoringAlertingStackScore {
} }
} }
} }
} fn build_kube_prometheus_helm_chart_config(&self) -> KubePrometheusConfig {
// pub fn new_with_ns(ns: &str) -> Self { let mut config = KubePrometheusConfig::new();
// let mut config = KubePrometheusConfig::default(); self.match_alert_channel(&mut config);
// let namespace = ns.to_string(); if let Some(ns) = &self.namespace {
// config.namespace = namespace; config.namespace = ns.clone();
// let score = kube_prometheus_score(&config);
// Self {
// alert_channel: None,
// monitoring_stack: Some(Stack::KubePrometheusStack),
// }
// }
//}
impl Default for MonitoringAlertingStackScore {
fn default() -> Self {
Self {
alert_channel: None,
monitoring_stack: Stack::KubePrometheusStack,
} }
config
} }
} }
@ -81,10 +77,9 @@ impl<T: Topology + HelmCommand> Score<T> for MonitoringAlertingStackScore {
fn create_interpret(&self) -> Box<dyn Interpret<T>> { fn create_interpret(&self) -> Box<dyn Interpret<T>> {
match &self.monitoring_stack { match &self.monitoring_stack {
Stack::KubePrometheusStack => { Stack::KubePrometheusStack => {
let mut config = KubePrometheusConfig::new(); let config = self.build_kube_prometheus_helm_chart_config();
self.match_alert_channel(&mut config); let helm_chart = kube_prometheus_helm_chart_score(&config);
let score = kube_prometheus_score(&config); helm_chart.create_interpret()
score.create_interpret()
} }
Stack::OtherStack => { Stack::OtherStack => {
todo!() todo!()