Compare commits
	
		
			No commits in common. "ef5ec4a131d12d757b7db67a92fa512d8c55a1ea" and "d1678b529eed3d77fa9b0a4b84ffbb71972f2250" have entirely different histories.
		
	
	
		
			ef5ec4a131
			...
			d1678b529e
		
	
		
@ -38,7 +38,7 @@ async fn main() {
 | 
				
			|||||||
    // that automatically adapt to each environment grade.
 | 
					    // that automatically adapt to each environment grade.
 | 
				
			||||||
    let mut maestro = Maestro::<K8sAnywhereTopology>::initialize(
 | 
					    let mut maestro = Maestro::<K8sAnywhereTopology>::initialize(
 | 
				
			||||||
        Inventory::autoload(),
 | 
					        Inventory::autoload(),
 | 
				
			||||||
        K8sAnywhereTopology::from_env(),
 | 
					        K8sAnywhereTopology::new(),
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    .await
 | 
					    .await
 | 
				
			||||||
    .unwrap();
 | 
					    .unwrap();
 | 
				
			||||||
 | 
				
			|||||||
@ -18,7 +18,7 @@ async fn main() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    let mut maestro = Maestro::<K8sAnywhereTopology>::initialize(
 | 
					    let mut maestro = Maestro::<K8sAnywhereTopology>::initialize(
 | 
				
			||||||
        Inventory::autoload(),
 | 
					        Inventory::autoload(),
 | 
				
			||||||
        K8sAnywhereTopology::from_env(),
 | 
					        K8sAnywhereTopology::new(),
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    .await
 | 
					    .await
 | 
				
			||||||
    .unwrap();
 | 
					    .unwrap();
 | 
				
			||||||
 | 
				
			|||||||
@ -2,7 +2,7 @@ use std::{process::Command, sync::Arc};
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
use async_trait::async_trait;
 | 
					use async_trait::async_trait;
 | 
				
			||||||
use inquire::Confirm;
 | 
					use inquire::Confirm;
 | 
				
			||||||
use log::{debug, info, warn};
 | 
					use log::{info, warn};
 | 
				
			||||||
use tokio::sync::OnceCell;
 | 
					use tokio::sync::OnceCell;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::{
 | 
					use crate::{
 | 
				
			||||||
@ -38,7 +38,6 @@ enum K8sSource {
 | 
				
			|||||||
pub struct K8sAnywhereTopology {
 | 
					pub struct K8sAnywhereTopology {
 | 
				
			||||||
    k8s_state: OnceCell<Option<K8sState>>,
 | 
					    k8s_state: OnceCell<Option<K8sState>>,
 | 
				
			||||||
    tenant_manager: OnceCell<K8sTenantManager>,
 | 
					    tenant_manager: OnceCell<K8sTenantManager>,
 | 
				
			||||||
    config: K8sAnywhereConfig,
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[async_trait]
 | 
					#[async_trait]
 | 
				
			||||||
@ -59,19 +58,10 @@ impl K8sclient for K8sAnywhereTopology {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl K8sAnywhereTopology {
 | 
					impl K8sAnywhereTopology {
 | 
				
			||||||
    pub fn from_env() -> Self {
 | 
					    pub fn new() -> Self {
 | 
				
			||||||
        Self {
 | 
					        Self {
 | 
				
			||||||
            k8s_state: OnceCell::new(),
 | 
					            k8s_state: OnceCell::new(),
 | 
				
			||||||
            tenant_manager: OnceCell::new(),
 | 
					            tenant_manager: OnceCell::new(),
 | 
				
			||||||
            config: K8sAnywhereConfig::from_env(),
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    pub fn with_config(config: K8sAnywhereConfig) -> Self {
 | 
					 | 
				
			||||||
        Self {
 | 
					 | 
				
			||||||
            k8s_state: OnceCell::new(),
 | 
					 | 
				
			||||||
            tenant_manager: OnceCell::new(),
 | 
					 | 
				
			||||||
            config,
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -112,10 +102,22 @@ impl K8sAnywhereTopology {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async fn try_get_or_install_k8s_client(&self) -> Result<Option<K8sState>, InterpretError> {
 | 
					    async fn try_get_or_install_k8s_client(&self) -> Result<Option<K8sState>, InterpretError> {
 | 
				
			||||||
        let k8s_anywhere_config = &self.config;
 | 
					        let k8s_anywhere_config = K8sAnywhereConfig {
 | 
				
			||||||
 | 
					            kubeconfig: std::env::var("KUBECONFIG").ok().map(|v| v.to_string()),
 | 
				
			||||||
 | 
					            use_system_kubeconfig: std::env::var("HARMONY_USE_SYSTEM_KUBECONFIG")
 | 
				
			||||||
 | 
					                .map_or_else(|_| false, |v| v.parse().ok().unwrap_or(false)),
 | 
				
			||||||
 | 
					            autoinstall: std::env::var("HARMONY_AUTOINSTALL")
 | 
				
			||||||
 | 
					                .map_or_else(|_| false, |v| v.parse().ok().unwrap_or(false)),
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if let Some(kubeconfig) = &k8s_anywhere_config.kubeconfig {
 | 
					        if k8s_anywhere_config.use_system_kubeconfig {
 | 
				
			||||||
            debug!("Loading kubeconfig {kubeconfig}");
 | 
					            match self.try_load_system_kubeconfig().await {
 | 
				
			||||||
 | 
					                Some(_client) => todo!(),
 | 
				
			||||||
 | 
					                None => todo!(),
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if let Some(kubeconfig) = k8s_anywhere_config.kubeconfig {
 | 
				
			||||||
            match self.try_load_kubeconfig(&kubeconfig).await {
 | 
					            match self.try_load_kubeconfig(&kubeconfig).await {
 | 
				
			||||||
                Some(client) => {
 | 
					                Some(client) => {
 | 
				
			||||||
                    return Ok(Some(K8sState {
 | 
					                    return Ok(Some(K8sState {
 | 
				
			||||||
@ -132,14 +134,6 @@ impl K8sAnywhereTopology {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if k8s_anywhere_config.use_system_kubeconfig {
 | 
					 | 
				
			||||||
            debug!("Loading system kubeconfig");
 | 
					 | 
				
			||||||
            match self.try_load_system_kubeconfig().await {
 | 
					 | 
				
			||||||
                Some(_client) => todo!(),
 | 
					 | 
				
			||||||
                None => todo!(),
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        info!("No kubernetes configuration found");
 | 
					        info!("No kubernetes configuration found");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if !k8s_anywhere_config.autoinstall {
 | 
					        if !k8s_anywhere_config.autoinstall {
 | 
				
			||||||
@ -203,37 +197,25 @@ impl K8sAnywhereTopology {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub struct K8sAnywhereConfig {
 | 
					struct K8sAnywhereConfig {
 | 
				
			||||||
    /// The path of the KUBECONFIG file that Harmony should use to interact with the Kubernetes
 | 
					    /// The path of the KUBECONFIG file that Harmony should use to interact with the Kubernetes
 | 
				
			||||||
    /// cluster
 | 
					    /// cluster
 | 
				
			||||||
    ///
 | 
					    ///
 | 
				
			||||||
    /// Default : None
 | 
					    /// Default : None
 | 
				
			||||||
    pub kubeconfig: Option<String>,
 | 
					    kubeconfig: Option<String>,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// Whether to use the system KUBECONFIG, either the environment variable or the file in the
 | 
					    /// Whether to use the system KUBECONFIG, either the environment variable or the file in the
 | 
				
			||||||
    /// default or configured location
 | 
					    /// default or configured location
 | 
				
			||||||
    ///
 | 
					    ///
 | 
				
			||||||
    /// Default : false
 | 
					    /// Default : false
 | 
				
			||||||
    pub use_system_kubeconfig: bool,
 | 
					    use_system_kubeconfig: bool,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// Whether to install automatically a kubernetes cluster
 | 
					    /// Whether to install automatically a kubernetes cluster
 | 
				
			||||||
    ///
 | 
					    ///
 | 
				
			||||||
    /// When enabled, autoinstall will setup a K3D cluster on the localhost. https://k3d.io/stable/
 | 
					    /// When enabled, autoinstall will setup a K3D cluster on the localhost. https://k3d.io/stable/
 | 
				
			||||||
    ///
 | 
					    ///
 | 
				
			||||||
    /// Default: true
 | 
					    /// Default: true
 | 
				
			||||||
    pub autoinstall: bool,
 | 
					    autoinstall: bool,
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
impl K8sAnywhereConfig {
 | 
					 | 
				
			||||||
    fn from_env() -> Self {
 | 
					 | 
				
			||||||
        Self {
 | 
					 | 
				
			||||||
            kubeconfig: std::env::var("KUBECONFIG").ok().map(|v| v.to_string()),
 | 
					 | 
				
			||||||
            use_system_kubeconfig: std::env::var("HARMONY_USE_SYSTEM_KUBECONFIG")
 | 
					 | 
				
			||||||
                .map_or_else(|_| false, |v| v.parse().ok().unwrap_or(false)),
 | 
					 | 
				
			||||||
            autoinstall: std::env::var("HARMONY_AUTOINSTALL")
 | 
					 | 
				
			||||||
                .map_or_else(|_| false, |v| v.parse().ok().unwrap_or(false)),
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[async_trait]
 | 
					#[async_trait]
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user