forked from NationTech/harmony
		
	wip: Clean up some unnecessary bits in the Tenant module and move manager to its own file
This commit is contained in:
		
							parent
							
								
									895fb02f4e
								
							
						
					
					
						commit
						bf16566b4e
					
				| @ -7,6 +7,12 @@ use serde::Serialize; | |||||||
| use super::{IpAddress, LogicalHost}; | use super::{IpAddress, LogicalHost}; | ||||||
| use crate::executors::ExecutorError; | use crate::executors::ExecutorError; | ||||||
| 
 | 
 | ||||||
|  | impl std::fmt::Debug for dyn LoadBalancer { | ||||||
|  |     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||||||
|  |         f.write_fmt(format_args!("LoadBalancer {}", self.get_ip())) | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| #[async_trait] | #[async_trait] | ||||||
| pub trait LoadBalancer: Send + Sync { | pub trait LoadBalancer: Send + Sync { | ||||||
|     fn get_ip(&self) -> IpAddress; |     fn get_ip(&self) -> IpAddress; | ||||||
| @ -32,11 +38,6 @@ pub trait LoadBalancer: Send + Sync { | |||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl std::fmt::Debug for dyn LoadBalancer { |  | ||||||
|     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |  | ||||||
|         f.write_fmt(format_args!("LoadBalancer {}", self.get_ip())) |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| #[derive(Debug, PartialEq, Clone, Serialize)] | #[derive(Debug, PartialEq, Clone, Serialize)] | ||||||
| pub struct LoadBalancerService { | pub struct LoadBalancerService { | ||||||
|     pub backend_servers: Vec<BackendServer>, |     pub backend_servers: Vec<BackendServer>, | ||||||
|  | |||||||
| @ -3,6 +3,7 @@ mod host_binding; | |||||||
| mod http; | mod http; | ||||||
| mod k8s_anywhere; | mod k8s_anywhere; | ||||||
| mod localhost; | mod localhost; | ||||||
|  | pub mod tenant; | ||||||
| pub use k8s_anywhere::*; | pub use k8s_anywhere::*; | ||||||
| pub use localhost::*; | pub use localhost::*; | ||||||
| pub mod k8s; | pub mod k8s; | ||||||
|  | |||||||
							
								
								
									
										65
									
								
								harmony/src/domain/topology/tenant/manager.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										65
									
								
								harmony/src/domain/topology/tenant/manager.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,65 @@ | |||||||
|  | use super::*; | ||||||
|  | use async_trait::async_trait; | ||||||
|  | 
 | ||||||
|  | use crate::executors::ExecutorError; | ||||||
|  | 
 | ||||||
|  | #[async_trait] | ||||||
|  | pub trait TenantManager: Send + Sync + std::fmt::Debug { | ||||||
|  |     /// Provisions a new tenant based on the provided configuration.
 | ||||||
|  |     /// This operation should be idempotent; if a tenant with the same `config.name`
 | ||||||
|  |     /// already exists and matches the config, it will succeed without changes.
 | ||||||
|  |     /// If it exists but differs, it will be updated, or return an error if the update
 | ||||||
|  |     /// action is not supported
 | ||||||
|  |     ///
 | ||||||
|  |     /// # Arguments
 | ||||||
|  |     /// * `config`: The desired configuration for the new tenant.
 | ||||||
|  |     ///
 | ||||||
|  |     /// # Returns
 | ||||||
|  |     /// A `TenantContext` representing the provisioned tenant.
 | ||||||
|  |     async fn provision_tenant(&self, config: &TenantConfig) | ||||||
|  |     -> Result<TenantContext, ExecutorError>; | ||||||
|  | 
 | ||||||
|  |     /// Retrieves the current details and context of an existing tenant.
 | ||||||
|  |     ///
 | ||||||
|  |     /// # Arguments
 | ||||||
|  |     /// * `tenant_name`: The logical name of the tenant to retrieve.
 | ||||||
|  |     ///
 | ||||||
|  |     /// # Returns
 | ||||||
|  |     /// An `Option<TenantContext>`, which is `None` if the tenant does not exist.
 | ||||||
|  |     async fn get_tenant_details( | ||||||
|  |         &self, | ||||||
|  |         tenant_name: &str, | ||||||
|  |     ) -> Result<Option<TenantContext>, ExecutorError>; | ||||||
|  | 
 | ||||||
|  |     /// Updates the resource limits for an existing tenant.
 | ||||||
|  |     ///
 | ||||||
|  |     /// # Arguments
 | ||||||
|  |     /// * `tenant_name`: The logical name of the tenant to update.
 | ||||||
|  |     /// * `new_limits`: The new set of resource limits to apply.
 | ||||||
|  |     async fn update_tenant_resource_limits( | ||||||
|  |         &self, | ||||||
|  |         tenant_name: &str, | ||||||
|  |         new_limits: &ResourceLimits, | ||||||
|  |     ) -> Result<(), ExecutorError>; | ||||||
|  | 
 | ||||||
|  |     /// Updates the high-level network isolation policy for an existing tenant.
 | ||||||
|  |     ///
 | ||||||
|  |     /// # Arguments
 | ||||||
|  |     /// * `tenant_name`: The logical name of the tenant to update.
 | ||||||
|  |     /// * `new_policy`: The new network policy to apply.
 | ||||||
|  |     async fn update_tenant_network_policy( | ||||||
|  |         &self, | ||||||
|  |         tenant_name: &str, | ||||||
|  |         new_policy: &TenantNetworkPolicy, | ||||||
|  |     ) -> Result<(), ExecutorError>; | ||||||
|  | 
 | ||||||
|  |     /// Decommissions an existing tenant, removing its isolated context and associated resources.
 | ||||||
|  |     /// This operation should be idempotent.
 | ||||||
|  |     ///
 | ||||||
|  |     /// # Arguments
 | ||||||
|  |     /// * `tenant_name`: The logical name of the tenant to deprovision.
 | ||||||
|  |     async fn deprovision_tenant(&self, tenant_name: &str) -> Result<(), ExecutorError>; | ||||||
|  | 
 | ||||||
|  |     /// Lists the logical names of all tenants currently managed by this `TenantManager` instance.
 | ||||||
|  |     async fn list_tenant_names(&self) -> Result<Vec<String>, ExecutorError>; | ||||||
|  | } | ||||||
| @ -1,3 +1,7 @@ | |||||||
|  | mod manager; | ||||||
|  | pub use manager::*; | ||||||
|  | use serde::{Deserialize, Serialize}; | ||||||
|  | 
 | ||||||
| use std::collections::HashMap; | use std::collections::HashMap; | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] // Assuming serde for Scores
 | #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] // Assuming serde for Scores
 | ||||||
| @ -32,29 +36,12 @@ pub struct TenantContext { | |||||||
|     /// The logical name of the tenant, matching `TenantConfig.name`.
 |     /// The logical name of the tenant, matching `TenantConfig.name`.
 | ||||||
|     pub name: String, |     pub name: String, | ||||||
| 
 | 
 | ||||||
|     /// Current operational status of the tenant.
 |  | ||||||
|     pub status: TenantStatus, |  | ||||||
| 
 |  | ||||||
|     /// Effective resource limits currently applied to the tenant.
 |     /// Effective resource limits currently applied to the tenant.
 | ||||||
|     /// This might differ slightly from requested if the provider adjusted them.
 |     /// This might differ slightly from requested if the provider adjusted them.
 | ||||||
|     pub effective_resource_limits: ResourceLimits, |     pub effective_resource_limits: ResourceLimits, | ||||||
| 
 | 
 | ||||||
|     /// Effective network policy currently applied.
 |     /// Effective network policy currently applied.
 | ||||||
|     pub effective_network_policy: TenantNetworkPolicy, |     pub effective_network_policy: TenantNetworkPolicy, | ||||||
| 
 |  | ||||||
|     /// Additional provider-specific data or endpoints relevant to the tenant.
 |  | ||||||
|     /// (e.g., K8s API server endpoint scoped to the namespace, if applicable).
 |  | ||||||
|     pub provider_specific_data: HashMap<String, String>, |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] |  | ||||||
| pub enum TenantStatus { |  | ||||||
|     Provisioning, |  | ||||||
|     Active, |  | ||||||
|     Updating, |  | ||||||
|     Deleting, |  | ||||||
|     Error(String), |  | ||||||
|     Unknown, |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)] | #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)] | ||||||
| @ -75,15 +62,10 @@ pub struct ResourceLimits { | |||||||
|     pub persistent_volume_claim_count: Option<u32>, |     pub persistent_volume_claim_count: Option<u32>, | ||||||
|     // /// Optional: Storage limits per class, if needed for more granular control.
 |     // /// Optional: Storage limits per class, if needed for more granular control.
 | ||||||
|     // pub storage_gb_per_class: Option<HashMap<String, u64>>,
 |     // pub storage_gb_per_class: Option<HashMap<String, u64>>,
 | ||||||
| 
 |  | ||||||
|     /// Maximum number of load balancers.
 |     /// Maximum number of load balancers.
 | ||||||
|     pub load_balancer_count: Option<u32>, |     pub load_balancer_count: Option<u32>, | ||||||
|     /// Maximum number of public IP addresses.
 |     /// Maximum number of public IP addresses.
 | ||||||
|     pub public_ip_count: Option<u32>, |     pub public_ip_count: Option<u32>, | ||||||
| 
 |  | ||||||
|     /// Provider-specific or custom quotas (e.g., "gpu_count:2", "snapshot_count:10").
 |  | ||||||
|     /// Values are strings to accommodate various provider formats.
 |  | ||||||
|     pub custom_quotas: HashMap<String, String>, |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] | #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] | ||||||
| @ -93,17 +75,12 @@ pub struct TenantNetworkPolicy { | |||||||
| 
 | 
 | ||||||
|     /// Policy for egress traffic destined for the public internet.
 |     /// Policy for egress traffic destined for the public internet.
 | ||||||
|     pub default_internet_egress: InternetEgressPolicy, |     pub default_internet_egress: InternetEgressPolicy, | ||||||
| 
 |  | ||||||
|     /// List of common cluster-internal services this tenant should be ableto access.
 |  | ||||||
|     pub allowed_cluster_services: Vec<ClusterServiceType>, |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] | #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] | ||||||
| pub enum InterTenantIngressPolicy { | pub enum InterTenantIngressPolicy { | ||||||
|     /// Deny all traffic from other tenants by default.
 |     /// Deny all traffic from other tenants by default.
 | ||||||
|     DenyAll, |     DenyAll, | ||||||
|     // Future: AllowFromSameGroup (if tenants can be logically grouped)
 |  | ||||||
|     // Future: AllowLabeled (if tenants can specify labels for selective inter-tenant comms)
 |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] | #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] | ||||||
| @ -113,74 +90,3 @@ pub enum InternetEgressPolicy { | |||||||
|     /// Deny all outbound traffic to the internet by default.
 |     /// Deny all outbound traffic to the internet by default.
 | ||||||
|     DenyAll, |     DenyAll, | ||||||
| } | } | ||||||
| 
 |  | ||||||
| #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] |  | ||||||
| pub enum ClusterServiceType { |  | ||||||
|     /// e.g., kube-dns, CoreDNS.
 |  | ||||||
|     Dns, |  | ||||||
|     /// Access to an internal image registry.
 |  | ||||||
|     InternalImageRegistry, |  | ||||||
|     /// Access to centralized monitoring endpoints (e.g., Prometheus federation).
 |  | ||||||
|     MonitoringService, |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| use async_trait::async_trait; |  | ||||||
| use serde::{Deserialize, Serialize}; |  | ||||||
| 
 |  | ||||||
| use crate::executors::ExecutorError; |  | ||||||
| 
 |  | ||||||
| #[async_trait] |  | ||||||
| pub trait TenantManager: Send + Sync + std::fmt::Debug { |  | ||||||
|     /// Provisions a new tenant based on the provided configuration.
 |  | ||||||
|     /// This operation should be idempotent; if a tenant with the same `config.name`
 |  | ||||||
|     /// already exists and matches the config, it may succeed without changes.
 |  | ||||||
|     /// If it exists but differs, it might return an error or attempt to update (TBD by implementer).
 |  | ||||||
|     ///
 |  | ||||||
|     /// # Arguments
 |  | ||||||
|     /// * `config`: The desired configuration for the new tenant.
 |  | ||||||
|     ///
 |  | ||||||
|     /// # Returns
 |  | ||||||
|     /// A `TenantContext` representing the provisioned tenant.
 |  | ||||||
|     async fn provision_tenant(&self, config: &TenantConfig) -> Result<TenantContext, ExecutorError>; |  | ||||||
| 
 |  | ||||||
|     /// Retrieves the current details and context of an existing tenant.
 |  | ||||||
|     ///
 |  | ||||||
|     /// # Arguments
 |  | ||||||
|     /// * `tenant_name`: The logical name of the tenant to retrieve.
 |  | ||||||
|     ///
 |  | ||||||
|     /// # Returns
 |  | ||||||
|     /// An `Option<TenantContext>`, which is `None` if the tenant does not exist.
 |  | ||||||
|     async fn get_tenant_details(&self, tenant_name: &str) -> Result<Option<TenantContext>, ExecutorError>; |  | ||||||
| 
 |  | ||||||
|     /// Updates the resource limits for an existing tenant.
 |  | ||||||
|     ///
 |  | ||||||
|     /// # Arguments
 |  | ||||||
|     /// * `tenant_name`: The logical name of the tenant to update.
 |  | ||||||
|     /// * `new_limits`: The new set of resource limits to apply.
 |  | ||||||
|     async fn update_tenant_resource_limits( |  | ||||||
|         &self, |  | ||||||
|         tenant_name: &str, |  | ||||||
|         new_limits: &ResourceLimits, |  | ||||||
|     ) -> Result<(), ExecutorError>; |  | ||||||
| 
 |  | ||||||
|     /// Updates the high-level network isolation policy for an existing tenant.
 |  | ||||||
|     ///
 |  | ||||||
|     /// # Arguments
 |  | ||||||
|     /// * `tenant_name`: The logical name of the tenant to update.
 |  | ||||||
|     /// * `new_policy`: The new network policy to apply.
 |  | ||||||
|     async fn update_tenant_network_policy( |  | ||||||
|         &self, |  | ||||||
|         tenant_name: &str, |  | ||||||
|         new_policy: &TenantNetworkPolicy, |  | ||||||
|     ) -> Result<(), ExecutorError>; |  | ||||||
| 
 |  | ||||||
|     /// Decommissions an existing tenant, removing its isolated context and associated resources.
 |  | ||||||
|     /// This operation should be idempotent.
 |  | ||||||
|     ///
 |  | ||||||
|     /// # Arguments
 |  | ||||||
|     /// * `tenant_name`: The logical name of the tenant to deprovision.
 |  | ||||||
|     async fn deprovision_tenant(&self, tenant_name: &str) -> Result<(), ExecutorError>; |  | ||||||
| 
 |  | ||||||
|     /// Lists the logical names of all tenants currently managed by this `TenantManager` instance.
 |  | ||||||
|     async fn list_tenant_names(&self) -> Result<Vec<String>, ExecutorError>; |  | ||||||
| } |  | ||||||
|  | |||||||
| @ -1,12 +1,9 @@ | |||||||
| use async_trait::async_trait; | use async_trait::async_trait; | ||||||
| use log::debug; | use log::debug; | ||||||
| use non_blank_string_rs::NonBlankString; |  | ||||||
| use serde::Serialize; | use serde::Serialize; | ||||||
| use std::collections::HashMap; | use std::collections::HashMap; | ||||||
| use std::env::temp_dir; |  | ||||||
| use std::ffi::OsStr; |  | ||||||
| use std::io::ErrorKind; | use std::io::ErrorKind; | ||||||
| use std::path::{Path, PathBuf}; | use std::path::PathBuf; | ||||||
| use std::process::{Command, Output}; | use std::process::{Command, Output}; | ||||||
| use temp_dir::{self, TempDir}; | use temp_dir::{self, TempDir}; | ||||||
| use temp_file::TempFile; | use temp_file::TempFile; | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user