diff --git a/harmony/src/modules/application/features/monitoring.rs b/harmony/src/modules/application/features/monitoring.rs index e44679b..e8303ce 100644 --- a/harmony/src/modules/application/features/monitoring.rs +++ b/harmony/src/modules/application/features/monitoring.rs @@ -4,6 +4,7 @@ use crate::modules::application::{Application, ApplicationFeature}; use crate::modules::monitoring::application_monitoring::application_monitoring_score::ApplicationMonitoringScore; use crate::modules::monitoring::kube_prometheus::crd::crd_alertmanager_config::CRDPrometheus; +use crate::topology::MultiTargetTopology; use crate::{ inventory::Inventory, modules::monitoring::{ @@ -33,6 +34,7 @@ impl< + 'static + TenantManager + K8sclient + + MultiTargetTopology + std::fmt::Debug + PrometheusApplicationMonitoring, > ApplicationFeature for Monitoring diff --git a/harmony/src/modules/monitoring/ntfy/helm/ntfy_helm_chart.rs b/harmony/src/modules/monitoring/ntfy/helm/ntfy_helm_chart.rs index 444ecc5..6949f26 100644 --- a/harmony/src/modules/monitoring/ntfy/helm/ntfy_helm_chart.rs +++ b/harmony/src/modules/monitoring/ntfy/helm/ntfy_helm_chart.rs @@ -1,9 +1,28 @@ use non_blank_string_rs::NonBlankString; use std::str::FromStr; -use crate::modules::helm::chart::{HelmChartScore, HelmRepository}; +use crate::{ + modules::helm::chart::{HelmChartScore, HelmRepository}, + topology::DeploymentTarget, +}; + +pub fn ntfy_helm_chart_score( + namespace: String, + host: String, + target: DeploymentTarget, +) -> HelmChartScore { + // TODO not actually the correct logic, this should be fixed by using an ingresss which is the + // correct k8s standard. + // + // Another option is to delegate to the topology the ingress technology it wants to use Route, + // Ingress or other + let route_enabled = match target { + DeploymentTarget::LocalDev => false, + DeploymentTarget::Staging => true, + DeploymentTarget::Production => true, + }; + let ingress_enabled = !route_enabled; -pub fn ntfy_helm_chart_score(namespace: String, host: String) -> HelmChartScore { let values = format!( r#" replicaCount: 1 @@ -28,10 +47,10 @@ service: port: 8080 ingress: - enabled: false + enabled: {ingress_enabled} route: - enabled: true + enabled: {route_enabled} host: {host} autoscaling: diff --git a/harmony/src/modules/monitoring/ntfy/ntfy.rs b/harmony/src/modules/monitoring/ntfy/ntfy.rs index 986f8d0..d1aae83 100644 --- a/harmony/src/modules/monitoring/ntfy/ntfy.rs +++ b/harmony/src/modules/monitoring/ntfy/ntfy.rs @@ -11,7 +11,7 @@ use crate::{ inventory::Inventory, modules::monitoring::ntfy::helm::ntfy_helm_chart::ntfy_helm_chart_score, score::Score, - topology::{HelmCommand, K8sclient, Topology, k8s::K8sClient}, + topology::{k8s::K8sClient, HelmCommand, K8sclient, MultiTargetTopology, Topology}, }; #[derive(Debug, Clone, Serialize)] @@ -20,7 +20,7 @@ pub struct NtfyScore { pub host: String, } -impl Score for NtfyScore { +impl Score for NtfyScore { fn create_interpret(&self) -> Box> { Box::new(NtfyInterpret { score: self.clone(), @@ -77,7 +77,7 @@ impl NtfyInterpret { vec![ "sh", "-c", - format!("NTFY_PASSWORD={password} ntfy user add --role={role} {username}") + format!("NTFY_PASSWORD={password} ntfy user add --role={role} --ignore-exists {username}") .as_str(), ], ) @@ -89,13 +89,13 @@ impl NtfyInterpret { /// We need a ntfy interpret to wrap the HelmChartScore in order to run the score, and then bootstrap the config inside ntfy #[async_trait] -impl Interpret for NtfyInterpret { +impl Interpret for NtfyInterpret { async fn execute( &self, inventory: &Inventory, topology: &T, ) -> Result { - ntfy_helm_chart_score(self.score.namespace.clone(), self.score.host.clone()) + ntfy_helm_chart_score(self.score.namespace.clone(), self.score.host.clone(), topology.current_target()) .interpret(inventory, topology) .await?; diff --git a/harmony/src/modules/prometheus/k8s_prometheus_alerting_score.rs b/harmony/src/modules/prometheus/k8s_prometheus_alerting_score.rs index c70f5e5..0af1063 100644 --- a/harmony/src/modules/prometheus/k8s_prometheus_alerting_score.rs +++ b/harmony/src/modules/prometheus/k8s_prometheus_alerting_score.rs @@ -166,7 +166,8 @@ impl K8sPrometheusCRDAlertingInterpret { let install_output = Command::new("helm") .args([ - "install", + "upgrade", + "--install", &chart_name, tgz_path.to_str().unwrap(), "--namespace",