Commit 4afabae0 authored by Santhosh Kumar's avatar Santhosh Kumar

cleanup code

parent adf37892
......@@ -275,21 +275,25 @@ def get_deployment_info():
pod_name = pod.metadata.name
# Get resource metrics for the pod
metrics = metrics_api.get_namespaced_custom_object(
group="metrics.k8s.io",
version="v1beta1",
namespace=namespace,
plural="pods",
name=pod_name
)
# Extract CPU and memory usage from metrics
cpu_usage = metrics["containers"][0]["usage"]["cpu"]
memory_usage = metrics["containers"][0]["usage"]["memory"]
# Accumulate total usage
cpu_usage_total += int(cpu_usage[:-1]) # Convert string like "1234n" to int (removing "n" suffix)
memory_usage_total += int(memory_usage[:-2]) # Convert string like "1234Ki" to int (removing "Ki" suffix)
print(pod_name)
try:
metrics = metrics_api.get_namespaced_custom_object(
group="metrics.k8s.io",
version="v1beta1",
namespace=namespace,
plural="pods",
name=pod_name
)
# Extract CPU and memory usage from metrics
cpu_usage = metrics["containers"][0]["usage"]["cpu"]
memory_usage = metrics["containers"][0]["usage"]["memory"]
# Accumulate total usage
cpu_usage_total += int(cpu_usage[:-1]) # Convert string like "1234n" to int (removing "n" suffix)
memory_usage_total += int(memory_usage[:-2]) # Convert string like "1234Ki" to int (removing "Ki" suffix)
except ApiException as e:
pass
# Calculate average usage across all pods
num_pods = len(pods)
......@@ -312,11 +316,10 @@ def get_deployment_info():
if e.status == 404:
exposed_url = "Not exposed"
else:
raise
exposed_url = "service error "
# Get HPDA (HorizontalPodAutoscaler) if exists
hpa_name = f"{deployment_name}-hpa"
print("Iam here")
try:
hpa = scale_api.read_namespaced_horizontal_pod_autoscaler(name=hpa_name, namespace=namespace)
min_replicas = hpa.spec.min_replicas
......@@ -337,11 +340,9 @@ def get_deployment_info():
hpa_info = "HPA Error"
# Get replica sets
print("Iam here")
replica_sets = apps_api.list_namespaced_replica_set(namespace=deployment.metadata.namespace).items
# Print deployment info
print("Iam here")
print("{:<30} {:<15} {:<15} {:<20} {:<20} {:<20}".format(
deployment_name, replicas, json.dumps(limits), json.dumps(usage), exposed_url, json.dumps(hpa_info)))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment