diff --git a/harmony/src/domain/topology/k8s.rs b/harmony/src/domain/topology/k8s.rs index d31e5bc..dcc1307 100644 --- a/harmony/src/domain/topology/k8s.rs +++ b/harmony/src/domain/topology/k8s.rs @@ -2,7 +2,10 @@ use derive_new::new; use futures_util::StreamExt; use k8s_openapi::{ ClusterResourceScope, NamespaceResourceScope, - api::{apps::v1::Deployment, core::v1::Pod}, + api::{ + apps::v1::Deployment, + core::v1::{ObjectReference, Pod}, + }, }; use kube::{ Client, Config, Error, Resource, @@ -244,37 +247,39 @@ impl K8sClient { pub async fn apply_yaml_many( &self, + api_resource: &ApiResource, yaml: &Vec, ns: Option<&str>, ) -> Result<(), Error> { for y in yaml.iter() { - self.apply_yaml(y, ns).await?; + self.apply_yaml(api_resource, y, ns).await?; } Ok(()) } pub async fn apply_yaml( &self, + api_resource: &ApiResource, yaml: &serde_yaml::Value, ns: Option<&str>, ) -> Result<(), Error> { let obj: DynamicObject = serde_yaml::from_value(yaml.clone()).expect("TODO do not unwrap"); let name = obj.metadata.name.as_ref().expect("YAML must have a name"); - let namespace = obj - .metadata - .namespace - .as_ref() - .expect("YAML must have a namespace"); - // 4. Define the API resource type using the GVK from the object. - // The plural name 'applications' is taken from your CRD definition. - error!("This only supports argocd application harcoded, very rrrong"); - let gvk = GroupVersionKind::gvk("argoproj.io", "v1alpha1", "Application"); - let api_resource = ApiResource::from_gvk_with_plural(&gvk, "applications"); + let namespace = match ns { + Some(n) => n, + None => { + obj + .metadata + .namespace + .as_ref() + .expect("YAML must have a namespace") + }, + }; // 5. Create a dynamic API client for this resource type. let api: Api = - Api::namespaced_with(self.client.clone(), namespace, &api_resource); + Api::namespaced_with(self.client.clone(), namespace, api_resource); // 6. Apply the object to the cluster using Server-Side Apply. // This will create the resource if it doesn't exist, or update it if it does.