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
.unwrap();
let monitoring_stack_score =
MonitoringAlertingStackScore::new_with_ns(&lamp_stack.config.namespace);
let mut monitoring_stack_score = MonitoringAlertingStackScore::new();
monitoring_stack_score.namespace = Some(lamp_stack.config.namespace.clone());
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

View File

@ -4,7 +4,7 @@ use std::{collections::HashMap, str::FromStr};
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
//to the overrides or something leaving the user to deal with formatting here seems bad
let values = r#"

View File

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