diff --git a/examples/lamp/src/main.rs b/examples/lamp/src/main.rs index 74df0d8..14180cc 100644 --- a/examples/lamp/src/main.rs +++ b/examples/lamp/src/main.rs @@ -4,7 +4,7 @@ use harmony::{ maestro::Maestro, modules::{ lamp::{LAMPConfig, LAMPScore}, - monitoring::monitoring_alerting::{AlertChannel, MonitoringAlertingStackScore}, + monitoring::monitoring_alerting::MonitoringAlertingStackScore, }, topology::{K8sAnywhereTopology, Url}, }; @@ -43,9 +43,6 @@ async fn main() { .await .unwrap(); - let url = url::Url::parse("https://discord.com/api/webhooks/dummy_channel/dummy_token") - .expect("invalid URL"); - let mut monitoring_stack_score = MonitoringAlertingStackScore::new(); monitoring_stack_score.namespace = Some(lamp_stack.config.namespace.clone()); diff --git a/harmony/src/domain/topology/k8s.rs b/harmony/src/domain/topology/k8s.rs index cfaae1f..c0b3b38 100644 --- a/harmony/src/domain/topology/k8s.rs +++ b/harmony/src/domain/topology/k8s.rs @@ -2,7 +2,7 @@ use derive_new::new; use k8s_openapi::{ClusterResourceScope, NamespaceResourceScope}; use kube::{ Api, Client, Config, Error, Resource, - api::PostParams, + api::{Patch, PatchParams, PostParams}, config::{KubeConfigOptions, Kubeconfig}, }; use log::{debug, error, trace}; @@ -20,7 +20,10 @@ impl K8sClient { }) } - pub async fn apply(&self, resource: &K, ns: Option<&str>) -> Result + /// Apply a resource in namespace + /// + /// See `kubectl apply` for more information on the expected behavior of this function + pub async fn apply(&self, resource: &K, namespace: Option<&str>) -> Result where K: Resource + Clone + std::fmt::Debug + DeserializeOwned + serde::Serialize, ::Scope: ApplyStrategy, @@ -29,12 +32,20 @@ impl K8sClient { debug!( "Applying resource {:?} with ns {:?}", resource.meta().name, - ns + namespace ); trace!("{:#?}", serde_json::to_string(resource)); - let api: Api = <::Scope as ApplyStrategy>::get_api(&self.client, ns); - api.create(&PostParams::default(), &resource).await + let api: Api = <::Scope as ApplyStrategy>::get_api(&self.client, namespace); + // api.create(&PostParams::default(), &resource).await + let patch_params = PatchParams::apply("harmony"); + let name = resource + .meta() + .name + .as_ref() + .expect("K8s Resource should have a name"); + api.patch(name, &patch_params, &Patch::Apply(resource)) + .await } pub async fn apply_many(&self, resource: &Vec, ns: Option<&str>) -> Result, Error>