From 5e51f7490cb8282d100ae23d380efd5694447c2e Mon Sep 17 00:00:00 2001 From: Taha Hawa Date: Thu, 29 May 2025 15:41:57 -0400 Subject: [PATCH] Update request quota --- harmony/src/domain/topology/tenant/k8s.rs | 67 +++++++++++------------ 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/harmony/src/domain/topology/tenant/k8s.rs b/harmony/src/domain/topology/tenant/k8s.rs index 24837a0..08ea7a4 100644 --- a/harmony/src/domain/topology/tenant/k8s.rs +++ b/harmony/src/domain/topology/tenant/k8s.rs @@ -21,49 +21,46 @@ impl TenantManager for K8sTenantManager { "metadata": { "labels": { "harmony.nationtech.io/tenant.id": config.id, - "name": config.name, - + "harmony.nationtech.io/tenant.name": config.name, }, "name": config.name, }, } ); - todo!("Validate that when tenant already exists (by id) that name has not changed"); + todo!("Validate that when tenant already exists (by id) that name has not changed"); - let namespace: Namespace = serde_json::from_value(namespace).unwrap(); + let namespace: Namespace = serde_json::from_value(namespace).unwrap(); + let resource_quota = json!( + { + "apiVersion": "v1", + "kind": "List", + "items": [ + { + "apiVersion": "v1", + "kind": "ResourceQuota", + "metadata": { + "name": config.name, + "labels": { + "harmony.nationtech.io/tenant.id": config.id, + "harmony.nationtech.io/tenant.name": config.name, + }, + "namespace": config.name, + }, + "spec": { + "hard": { + "limits.cpu": format!("{:.0}",config.resource_limits.cpu_limit_cores), + "limits.memory": format!("{:.3}Gi", config.resource_limits.memory_limit_gb), + "requests.cpu": format!("{:.0}",config.resource_limits.cpu_request_cores), + "requests.memory": format!("{:.3}Gi", config.resource_limits.memory_request_gb), + "requests.storage": format!("{:.3}", config.resource_limits.storage_total_gb) + } + } + } + ] + } - let resource_quota = json!( - { - "apiVersion": "v1", - "kind": "List", - "items": [ - { - "apiVersion": "v1", - "kind": "ResourceQuota", - "metadata": { - "name": config.name - }, - "spec": { - "hard": { - "cpu": config.resource_limits.cpu_limit_cores, - "memory": format!("{:.3}Gi", config.resource_limits.memory_limit_gb), - }, - "scopeSelector": { - "matchExpressions": [ - { - "operator": "In", - "scopeName": "PriorityClass", - "values": ["high"] - } - ] - } - } - } - ] - } - - ); + ); } async fn update_tenant_resource_limits(