in modules/python/clusterloader2/cri/cri.py [0:0]
def override_config_clusterloader2(
node_count, node_per_step, max_pods, repeats, operation_timeout,
load_type, scale_enabled, pod_startup_latency_threshold, provider,
scrape_kubelets, override_file):
client = KubernetesClient(os.path.expanduser("~/.kube/config"))
nodes = client.get_nodes(label_selector="cri-resource-consume=true")
if len(nodes) == 0:
raise Exception("No nodes found with the label cri-resource-consume=true")
node = nodes[0]
allocatable_cpu = node.status.allocatable["cpu"]
allocatable_memory = node.status.allocatable["memory"]
logger.info(f"Node {node.metadata.name} has allocatable cpu of {allocatable_cpu} and allocatable memory of {allocatable_memory}")
cpu_value = int(allocatable_cpu.replace("m", ""))
# Bottlerocket OS SKU on EKS has allocatable_memory property in Mi. AKS and Amazon Linux (default SKUs)
# user Ki. Handling the Mi case here and converting Mi to Ki, if needed.
if "Mi" in allocatable_memory:
memory_value = int(allocatable_memory.replace("Mi", "")) * 1024
elif "Ki" in allocatable_memory:
memory_value = int(allocatable_memory.replace("Ki", ""))
else:
raise Exception("Unexpected format of allocatable memory node property")
logger.info(f"Node {node.metadata.name} has cpu value of {cpu_value} and memory value of {memory_value}")
allocated_cpu, allocated_memory = client.get_daemonsets_pods_allocated_resources("kube-system", node.metadata.name)
logger.info(f"Node {node.metadata.name} has allocated cpu of {allocated_cpu} and allocated memory of {allocated_memory}")
cpu_value -= allocated_cpu
memory_value -= allocated_memory
# Calculate request cpu and memory for each pod
pod_count = max_pods - DAEMONSETS_PER_NODE_MAP[provider]
cpu_request = cpu_value // pod_count
memory_request_in_ki = math.ceil(memory_value * MEMORY_SCALE_FACTOR // pod_count)
memory_request_in_k = int(memory_request_in_ki // 1.024)
logger.info(f"CPU request for each pod: {cpu_request}m, memory request for each pod: {memory_request_in_k}K, total pod per node: {pod_count}")
# Calculate the number of steps to scale up
steps = node_count // node_per_step
logger.info(f"Scaled enabled: {scale_enabled}, node per step: {node_per_step}, steps: {steps}, scrape kubelets: {scrape_kubelets}")
with open(override_file, 'w', encoding='utf-8') as file:
file.write(f"CL2_DEPLOYMENT_SIZE: {pod_count}\n")
file.write(f"CL2_RESOURCE_CONSUME_MEMORY: {memory_request_in_k}\n")
file.write(f"CL2_RESOURCE_CONSUME_MEMORY_KI: {memory_request_in_ki}Ki\n")
file.write(f"CL2_RESOURCE_CONSUME_CPU: {cpu_request}\n")
file.write(f"CL2_REPEATS: {repeats}\n")
file.write(f"CL2_NODE_COUNT: {node_count}\n")
file.write(f"CL2_NODE_PER_STEP: {node_per_step}\n")
file.write(f"CL2_STEPS: {steps}\n")
file.write(f"CL2_OPERATION_TIMEOUT: {operation_timeout}\n")
file.write(f"CL2_LOAD_TYPE: {load_type}\n")
file.write(f"CL2_SCALE_ENABLED: {str(scale_enabled).lower()}\n")
file.write("CL2_PROMETHEUS_TOLERATE_MASTER: true\n")
file.write("CL2_PROMETHEUS_CPU_SCALE_FACTOR: 30.0\n")
file.write("CL2_PROMETHEUS_MEMORY_LIMIT_FACTOR: 30.0\n")
file.write("CL2_PROMETHEUS_MEMORY_SCALE_FACTOR: 30.0\n")
file.write("CL2_PROMETHEUS_NODE_SELECTOR: \"prometheus: \\\"true\\\"\"\n")
file.write(f"CL2_POD_STARTUP_LATENCY_THRESHOLD: {pod_startup_latency_threshold}\n")
file.write(f"CL2_PROVIDER: {provider}\n")
file.write(f"CL2_SCRAPE_KUBELETS: {str(scrape_kubelets).lower()}\n")
file.close()