feat: Introduce Application trait, not too sure how it will evolve but it makes sense, at the very least to identify the Application, also some minor refactoring #73
| @ -21,6 +21,7 @@ pub enum InterpretName { | |||||||
|     OPNSense, |     OPNSense, | ||||||
|     K3dInstallation, |     K3dInstallation, | ||||||
|     TenantInterpret, |     TenantInterpret, | ||||||
|  |     Application, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl std::fmt::Display for InterpretName { | impl std::fmt::Display for InterpretName { | ||||||
| @ -37,6 +38,7 @@ impl std::fmt::Display for InterpretName { | |||||||
|             InterpretName::OPNSense => f.write_str("OPNSense"), |             InterpretName::OPNSense => f.write_str("OPNSense"), | ||||||
|             InterpretName::K3dInstallation => f.write_str("K3dInstallation"), |             InterpretName::K3dInstallation => f.write_str("K3dInstallation"), | ||||||
|             InterpretName::TenantInterpret => f.write_str("Tenant"), |             InterpretName::TenantInterpret => f.write_str("Tenant"), | ||||||
|  |             InterpretName::Application => f.write_str("Application"), | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -34,6 +34,17 @@ pub struct Inventory { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl Inventory { | impl Inventory { | ||||||
|  |     pub fn empty() -> Self { | ||||||
|  |         Self { | ||||||
|  |             location: Location::new("Empty".to_string(), "location".to_string()), | ||||||
|  |             switch: vec![], | ||||||
|  |             firewall: vec![], | ||||||
|  |             worker_host: vec![], | ||||||
|  |             storage_host: vec![], | ||||||
|  |             control_plane_host: vec![], | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     pub fn autoload() -> Self { |     pub fn autoload() -> Self { | ||||||
|         Self { |         Self { | ||||||
|             location: Location::test_building(), |             location: Location::test_building(), | ||||||
|  | |||||||
| @ -1,7 +1,14 @@ | |||||||
| use async_trait::async_trait; | use async_trait::async_trait; | ||||||
| use log::info; | use log::info; | ||||||
|  | use serde_json::Value; | ||||||
| 
 | 
 | ||||||
| use crate::{modules::application::ApplicationFeature, topology::Topology}; | use crate::{ | ||||||
|  |     data::Version, | ||||||
|  |     inventory::Inventory, | ||||||
|  |     modules::{application::ApplicationFeature, helm::chart::HelmChartScore}, | ||||||
|  |     score::Score, | ||||||
|  |     topology::{HelmCommand, Topology, Url}, | ||||||
|  | }; | ||||||
| 
 | 
 | ||||||
| /// ContinuousDelivery in Harmony provides this functionality :
 | /// ContinuousDelivery in Harmony provides this functionality :
 | ||||||
| ///
 | ///
 | ||||||
| @ -34,12 +41,44 @@ use crate::{modules::application::ApplicationFeature, topology::Topology}; | |||||||
| pub struct ContinuousDelivery {} | pub struct ContinuousDelivery {} | ||||||
| 
 | 
 | ||||||
| #[async_trait] | #[async_trait] | ||||||
| impl<T: Topology + 'static> ApplicationFeature<T> for ContinuousDelivery { | impl<T: Topology + HelmCommand + 'static> ApplicationFeature<T> for ContinuousDelivery { | ||||||
|     async fn ensure_installed(&self, _topology: &T) -> Result<(), String> { |     async fn ensure_installed(&self, topology: &T) -> Result<(), String> { | ||||||
|         info!("Installing ContinuousDelivery feature"); |         info!("Installing ContinuousDelivery feature"); | ||||||
|         todo!() |         let cd_server = HelmChartScore { | ||||||
|  |             namespace: todo!( | ||||||
|  |                 "ArgoCD Helm chart with proper understanding of Tenant, see how Will did it for Monitoring for now" | ||||||
|  |             ), | ||||||
|  |             release_name: todo!("argocd helm chart whatever"), | ||||||
|  |             chart_name: todo!(), | ||||||
|  |             chart_version: todo!(), | ||||||
|  |             values_overrides: todo!(), | ||||||
|  |             values_yaml: todo!(), | ||||||
|  |             create_namespace: todo!(), | ||||||
|  |             install_only: todo!(), | ||||||
|  |             repository: todo!(), | ||||||
|  |         }; | ||||||
|  |         let interpret = cd_server.create_interpret(); | ||||||
|  |         interpret.execute(&Inventory::empty(), topology); | ||||||
|  | 
 | ||||||
|  |         todo!("1. Create ArgoCD score that installs argo using helm chart, see if Taha's already done it
 | ||||||
|  |             2. Package app (docker image, helm chart) | ||||||
|  |             3. Push to registry if staging or prod | ||||||
|  |             4. Poke Argo | ||||||
|  |             5. Ensure app is up")
 | ||||||
|     } |     } | ||||||
|     fn name(&self) -> String { |     fn name(&self) -> String { | ||||||
|         "ContinuousDelivery".to_string() |         "ContinuousDelivery".to_string() | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | /// For now this is entirely bound to K8s / ArgoCD, will have to be revisited when we support
 | ||||||
|  | /// more CD systems
 | ||||||
|  | pub struct CDApplicationConfig { | ||||||
|  |     version: Version, | ||||||
|  |     helm_chart_url: Url, | ||||||
|  |     values_overrides: Value, | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | pub trait ContinuousDeliveryApplication { | ||||||
|  |     fn get_config(&self) -> CDApplicationConfig; | ||||||
|  | } | ||||||
|  | |||||||
| @ -33,7 +33,8 @@ impl<T: Topology + std::fmt::Debug> Interpret<T> for ApplicationInterpret<T> { | |||||||
|     ) -> Result<Outcome, InterpretError> { |     ) -> Result<Outcome, InterpretError> { | ||||||
|         let app_name = self.application.name(); |         let app_name = self.application.name(); | ||||||
|         info!( |         info!( | ||||||
|             "Preparing features {} for application {app_name}", |             "Preparing {} features [{}] for application {app_name}", | ||||||
|  |             self.features.len(), | ||||||
|             self.features |             self.features | ||||||
|                 .iter() |                 .iter() | ||||||
|                 .map(|f| f.name()) |                 .map(|f| f.name()) | ||||||
| @ -54,15 +55,17 @@ impl<T: Topology + std::fmt::Debug> Interpret<T> for ApplicationInterpret<T> { | |||||||
|                 } |                 } | ||||||
|             }; |             }; | ||||||
|         } |         } | ||||||
|         todo!("Do I need to do anything more than this here??") |         todo!( | ||||||
|  |             "Do I need to do anything more than this here?? I feel like the Application trait itself should expose something like ensure_ready but its becoming redundant. We'll see as this evolves." | ||||||
|  |         ) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn get_name(&self) -> InterpretName { |     fn get_name(&self) -> InterpretName { | ||||||
|         todo!() |         InterpretName::Application | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn get_version(&self) -> Version { |     fn get_version(&self) -> Version { | ||||||
|         todo!() |         Version::from("1.0.0").unwrap() | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn get_status(&self) -> InterpretStatus { |     fn get_status(&self) -> InterpretStatus { | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user