in modules/python/clusterloader2/autoscale/autoscale.py [0:0]
def calculate_cpu_request_for_clusterloader2(node_label_selector, node_count, pod_count, warmup_deployment, cl2_config_dir):
client = KubernetesClient(os.path.expanduser("~/.kube/config"))
timeout = 10 # 10 minutes
nodes = []
try:
nodes = client.wait_for_nodes_ready(1, timeout, label_selector=node_label_selector)
if len(nodes) == 0:
raise Exception(f"No nodes found with label selector: {node_label_selector}")
except Exception as e:
raise Exception(f"Error while getting nodes: {e}") from e
node = nodes[0]
allocatable_cpu = node.status.allocatable["cpu"]
logger.info(f"Node {node.metadata.name} has allocatable cpu of {allocatable_cpu}")
cpu_value = int(allocatable_cpu.replace("m", ""))
allocated_cpu, _ = client.get_daemonsets_pods_allocated_resources("kube-system", node.metadata.name)
logger.info(f"Node {node.metadata.name} has allocated cpu of {allocated_cpu}")
cpu_value -= allocated_cpu
# Remove warmup deployment cpu request from the total cpu value
if warmup_deployment in ["true", "True"]:
cpu_value -= 100
cleanup_warmup_deployment_for_karpeneter(cl2_config_dir)
# Calculate the cpu request for each pod
pods_per_node = pod_count // node_count
cpu_request = cpu_value // pods_per_node
return cpu_request