|
|
|
|
@@ -1,4 +1,4 @@
|
|
|
|
|
use std::{process::Command, sync::Arc};
|
|
|
|
|
use std::{io::Error, process::Command, sync::Arc};
|
|
|
|
|
|
|
|
|
|
use async_trait::async_trait;
|
|
|
|
|
use inquire::Confirm;
|
|
|
|
|
@@ -15,7 +15,11 @@ use crate::{
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
use super::{
|
|
|
|
|
k8s::K8sClient, tenant::{k8s::K8sTenantManager, ResourceLimits, TenantConfig, TenantManager, TenantNetworkPolicy}, HelmCommand, K8sclient, Topology
|
|
|
|
|
HelmCommand, K8sclient, Topology,
|
|
|
|
|
k8s::K8sClient,
|
|
|
|
|
tenant::{
|
|
|
|
|
ResourceLimits, TenantConfig, TenantManager, TenantNetworkPolicy, k8s::K8sTenantManager,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct K8sState {
|
|
|
|
|
@@ -32,10 +36,9 @@ enum K8sSource {
|
|
|
|
|
|
|
|
|
|
pub struct K8sAnywhereTopology {
|
|
|
|
|
k8s_state: OnceCell<Option<K8sState>>,
|
|
|
|
|
tenant_manager: K8sTenantManager,
|
|
|
|
|
tenant_manager: OnceCell<K8sTenantManager>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
|
impl K8sclient for K8sAnywhereTopology {
|
|
|
|
|
async fn k8s_client(&self) -> Result<Arc<K8sClient>, String> {
|
|
|
|
|
@@ -57,6 +60,7 @@ impl K8sAnywhereTopology {
|
|
|
|
|
pub fn new() -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
k8s_state: OnceCell::new(),
|
|
|
|
|
tenant_manager: OnceCell::new(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -165,6 +169,15 @@ impl K8sAnywhereTopology {
|
|
|
|
|
|
|
|
|
|
Ok(Some(state))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_k8s_tenant_manager(&self) -> Result<&K8sTenantManager, ExecutorError> {
|
|
|
|
|
match self.tenant_manager.get() {
|
|
|
|
|
Some(t) => Ok(t),
|
|
|
|
|
None => Err(ExecutorError::UnexpectedError(
|
|
|
|
|
"K8sTenantManager not available".to_string(),
|
|
|
|
|
)),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct K8sAnywhereConfig {
|
|
|
|
|
@@ -219,7 +232,9 @@ impl HelmCommand for K8sAnywhereTopology {}
|
|
|
|
|
#[async_trait]
|
|
|
|
|
impl TenantManager for K8sAnywhereTopology {
|
|
|
|
|
async fn provision_tenant(&self, config: &TenantConfig) -> Result<(), ExecutorError> {
|
|
|
|
|
self.tenant_manager.provision_tenant(config).await
|
|
|
|
|
self.get_k8s_tenant_manager()?
|
|
|
|
|
.provision_tenant(config)
|
|
|
|
|
.await
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn update_tenant_resource_limits(
|
|
|
|
|
@@ -227,7 +242,9 @@ impl TenantManager for K8sAnywhereTopology {
|
|
|
|
|
tenant_name: &str,
|
|
|
|
|
new_limits: &ResourceLimits,
|
|
|
|
|
) -> Result<(), ExecutorError> {
|
|
|
|
|
self.tenant_manager.update_tenant_resource_limits(tenant_name, new_limits).await
|
|
|
|
|
self.get_k8s_tenant_manager()?
|
|
|
|
|
.update_tenant_resource_limits(tenant_name, new_limits)
|
|
|
|
|
.await
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn update_tenant_network_policy(
|
|
|
|
|
@@ -235,10 +252,14 @@ impl TenantManager for K8sAnywhereTopology {
|
|
|
|
|
tenant_name: &str,
|
|
|
|
|
new_policy: &TenantNetworkPolicy,
|
|
|
|
|
) -> Result<(), ExecutorError> {
|
|
|
|
|
self.tenant_manager.update_tenant_network_policy(tenant_name, new_policy).await
|
|
|
|
|
self.get_k8s_tenant_manager()?
|
|
|
|
|
.update_tenant_network_policy(tenant_name, new_policy)
|
|
|
|
|
.await
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn deprovision_tenant(&self, tenant_name: &str) -> Result<(), ExecutorError> {
|
|
|
|
|
self.tenant_manager.deprovision_tenant(tenant_name).await
|
|
|
|
|
self.get_k8s_tenant_manager()?
|
|
|
|
|
.deprovision_tenant(tenant_name)
|
|
|
|
|
.await
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|