Compare commits
	
		
			No commits in common. "2ff3f4afa9687f022869b1393041bbe59f0ebd0e" and "2f6a11ead734244b05e1c69cc06b0b225dc9f8ad" have entirely different histories.
		
	
	
		
			2ff3f4afa9
			...
			2f6a11ead7
		
	
		
@ -21,7 +21,6 @@ pub enum InterpretName {
 | 
			
		||||
    OPNSense,
 | 
			
		||||
    K3dInstallation,
 | 
			
		||||
    TenantInterpret,
 | 
			
		||||
    Application,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl std::fmt::Display for InterpretName {
 | 
			
		||||
@ -38,7 +37,6 @@ impl std::fmt::Display for InterpretName {
 | 
			
		||||
            InterpretName::OPNSense => f.write_str("OPNSense"),
 | 
			
		||||
            InterpretName::K3dInstallation => f.write_str("K3dInstallation"),
 | 
			
		||||
            InterpretName::TenantInterpret => f.write_str("Tenant"),
 | 
			
		||||
            InterpretName::Application => f.write_str("Application"),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -34,17 +34,6 @@ pub struct 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 {
 | 
			
		||||
        Self {
 | 
			
		||||
            location: Location::test_building(),
 | 
			
		||||
 | 
			
		||||
@ -1,14 +1,7 @@
 | 
			
		||||
use async_trait::async_trait;
 | 
			
		||||
use log::info;
 | 
			
		||||
use serde_json::Value;
 | 
			
		||||
 | 
			
		||||
use crate::{
 | 
			
		||||
    data::Version,
 | 
			
		||||
    inventory::Inventory,
 | 
			
		||||
    modules::{application::ApplicationFeature, helm::chart::HelmChartScore},
 | 
			
		||||
    score::Score,
 | 
			
		||||
    topology::{HelmCommand, Topology, Url},
 | 
			
		||||
};
 | 
			
		||||
use crate::{modules::application::ApplicationFeature, topology::Topology};
 | 
			
		||||
 | 
			
		||||
/// ContinuousDelivery in Harmony provides this functionality :
 | 
			
		||||
///
 | 
			
		||||
@ -41,44 +34,9 @@ use crate::{
 | 
			
		||||
pub struct ContinuousDelivery {}
 | 
			
		||||
 | 
			
		||||
#[async_trait]
 | 
			
		||||
impl<T: Topology + HelmCommand + 'static> ApplicationFeature<T> for ContinuousDelivery {
 | 
			
		||||
    async fn ensure_installed(&self, topology: &T) -> Result<(), String> {
 | 
			
		||||
impl<T: Topology + 'static> ApplicationFeature<T> for ContinuousDelivery {
 | 
			
		||||
    async fn ensure_installed(&self, _topology: &T) -> Result<(), String> {
 | 
			
		||||
        info!("Installing ContinuousDelivery feature");
 | 
			
		||||
        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 {
 | 
			
		||||
        "ContinuousDelivery".to_string()
 | 
			
		||||
        todo!()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// 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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -36,7 +36,4 @@ impl<T: Topology + K8sclient + 'static> ApplicationFeature<T> for PublicEndpoint
 | 
			
		||||
        );
 | 
			
		||||
        todo!()
 | 
			
		||||
    }
 | 
			
		||||
    fn name(&self) -> String {
 | 
			
		||||
        "PublicEndpoint".to_string()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -15,7 +15,4 @@ impl<T: Topology + HelmCommand + 'static> ApplicationFeature<T> for Monitoring {
 | 
			
		||||
        info!("Ensuring monitoring is available for application");
 | 
			
		||||
        todo!("create and execute k8s prometheus score, depends on Will's work")
 | 
			
		||||
    }
 | 
			
		||||
    fn name(&self) -> String {
 | 
			
		||||
        "Monitoring".to_string()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,11 +1,9 @@
 | 
			
		||||
mod feature;
 | 
			
		||||
pub mod features;
 | 
			
		||||
mod rust;
 | 
			
		||||
pub use feature::*;
 | 
			
		||||
use log::info;
 | 
			
		||||
pub use rust::*;
 | 
			
		||||
 | 
			
		||||
use async_trait::async_trait;
 | 
			
		||||
use serde::Serialize;
 | 
			
		||||
 | 
			
		||||
use crate::{
 | 
			
		||||
    data::{Id, Version},
 | 
			
		||||
@ -14,14 +12,9 @@ use crate::{
 | 
			
		||||
    topology::Topology,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
pub trait Application: std::fmt::Debug + Send + Sync {
 | 
			
		||||
    fn name(&self) -> String;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Debug)]
 | 
			
		||||
pub struct ApplicationInterpret<T: Topology + std::fmt::Debug> {
 | 
			
		||||
    features: Vec<Box<dyn ApplicationFeature<T>>>,
 | 
			
		||||
    application: Box<dyn Application>,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[async_trait]
 | 
			
		||||
@ -31,21 +24,7 @@ impl<T: Topology + std::fmt::Debug> Interpret<T> for ApplicationInterpret<T> {
 | 
			
		||||
        _inventory: &Inventory,
 | 
			
		||||
        topology: &T,
 | 
			
		||||
    ) -> Result<Outcome, InterpretError> {
 | 
			
		||||
        let app_name = self.application.name();
 | 
			
		||||
        info!(
 | 
			
		||||
            "Preparing {} features [{}] for application {app_name}",
 | 
			
		||||
            self.features.len(),
 | 
			
		||||
            self.features
 | 
			
		||||
                .iter()
 | 
			
		||||
                .map(|f| f.name())
 | 
			
		||||
                .collect::<Vec<String>>()
 | 
			
		||||
                .join(", ")
 | 
			
		||||
        );
 | 
			
		||||
        for feature in self.features.iter() {
 | 
			
		||||
            info!(
 | 
			
		||||
                "Installing feature {} for application {app_name}",
 | 
			
		||||
                feature.name()
 | 
			
		||||
            );
 | 
			
		||||
            let _ = match feature.ensure_installed(topology).await {
 | 
			
		||||
                Ok(()) => (),
 | 
			
		||||
                Err(msg) => {
 | 
			
		||||
@ -55,17 +34,15 @@ impl<T: Topology + std::fmt::Debug> Interpret<T> for ApplicationInterpret<T> {
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
        }
 | 
			
		||||
        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."
 | 
			
		||||
        )
 | 
			
		||||
        todo!("Do I need to do anything more than this here??")
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn get_name(&self) -> InterpretName {
 | 
			
		||||
        InterpretName::Application
 | 
			
		||||
        todo!()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn get_version(&self) -> Version {
 | 
			
		||||
        Version::from("1.0.0").unwrap()
 | 
			
		||||
        todo!()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn get_status(&self) -> InterpretStatus {
 | 
			
		||||
@ -76,3 +53,40 @@ impl<T: Topology + std::fmt::Debug> Interpret<T> for ApplicationInterpret<T> {
 | 
			
		||||
        todo!()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// An ApplicationFeature provided by harmony, such as Backups, Monitoring, MultisiteAvailability,
 | 
			
		||||
/// ContinuousIntegration, ContinuousDelivery
 | 
			
		||||
#[async_trait]
 | 
			
		||||
pub trait ApplicationFeature<T: Topology>:
 | 
			
		||||
    std::fmt::Debug + Send + Sync + ApplicationFeatureClone<T>
 | 
			
		||||
{
 | 
			
		||||
    async fn ensure_installed(&self, topology: &T) -> Result<(), String>;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
trait ApplicationFeatureClone<T: Topology> {
 | 
			
		||||
    fn clone_box(&self) -> Box<dyn ApplicationFeature<T>>;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<A, T: Topology> ApplicationFeatureClone<T> for A
 | 
			
		||||
where
 | 
			
		||||
    A: ApplicationFeature<T> + Clone + 'static,
 | 
			
		||||
{
 | 
			
		||||
    fn clone_box(&self) -> Box<dyn ApplicationFeature<T>> {
 | 
			
		||||
        Box::new(self.clone())
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T: Topology> Serialize for Box<dyn ApplicationFeature<T>> {
 | 
			
		||||
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
 | 
			
		||||
    where
 | 
			
		||||
        S: serde::Serializer,
 | 
			
		||||
    {
 | 
			
		||||
        todo!()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T: Topology> Clone for Box<dyn ApplicationFeature<T>> {
 | 
			
		||||
    fn clone(&self) -> Self {
 | 
			
		||||
        self.clone_box()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -5,7 +5,7 @@ use crate::{
 | 
			
		||||
    topology::{Topology, Url},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
use super::{Application, ApplicationFeature, ApplicationInterpret};
 | 
			
		||||
use super::{ApplicationFeature, ApplicationInterpret, features::ContinuousDelivery};
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Serialize, Clone)]
 | 
			
		||||
pub struct RustWebappScore<T: Topology + Clone + Serialize> {
 | 
			
		||||
@ -18,9 +18,6 @@ impl<T: Topology + std::fmt::Debug + Clone + Serialize + 'static> Score<T> for R
 | 
			
		||||
    fn create_interpret(&self) -> Box<dyn crate::interpret::Interpret<T>> {
 | 
			
		||||
        Box::new(ApplicationInterpret {
 | 
			
		||||
            features: self.features.clone(),
 | 
			
		||||
            application: Box::new(RustWebapp {
 | 
			
		||||
                name: self.name.clone(),
 | 
			
		||||
            }),
 | 
			
		||||
        })
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -28,14 +25,3 @@ impl<T: Topology + std::fmt::Debug + Clone + Serialize + 'static> Score<T> for R
 | 
			
		||||
        format!("{}-RustWebapp", self.name)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Debug)]
 | 
			
		||||
struct RustWebapp {
 | 
			
		||||
    name: String,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Application for RustWebapp {
 | 
			
		||||
    fn name(&self) -> String {
 | 
			
		||||
        self.name.clone()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user