-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.sh
More file actions
50 lines (39 loc) · 2.07 KB
/
Copy pathscript.sh
File metadata and controls
50 lines (39 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
NAMESPACE="$1"
if [ -z "$NAMESPACE" ]; then
echo "Usage: $0 <namespace>"
exit 1
fi
echo "Collecting Deployments + StatefulSets in namespace: $NAMESPACE"
echo "----------------------------------------------------------------------------------------------"
echo -e "KIND\tNAME\tCONTAINER\tIMAGE\tREQUEST_CPU\tREQUEST_MEM\tLIMIT_CPU\tLIMIT_MEM"
###############################################
# Function to extract resources for a workload
###############################################
extract_resources() {
kind=$1
name=$2
containers=$(oc get "$kind" "$name" -n "$NAMESPACE" -o jsonpath='{range .spec.template.spec.containers[*]}{.name}{" "}{end}')
for container in $containers; do
image=$(oc get "$kind" "$name" -n "$NAMESPACE" -o jsonpath="{.spec.template.spec.containers[?(@.name=='$container')].image}")
req_cpu=$(oc get "$kind" "$name" -n "$NAMESPACE" -o jsonpath="{.spec.template.spec.containers[?(@.name=='$container')].resources.requests.cpu}")
req_mem=$(oc get "$kind" "$name" -n "$NAMESPACE" -o jsonpath="{.spec.template.spec.containers[?(@.name=='$container')].resources.requests.memory}")
lim_cpu=$(oc get "$kind" "$name" -n "$NAMESPACE" -o jsonpath="{.spec.template.spec.containers[?(@.name=='$container')].resources.limits.cpu}")
lim_mem=$(oc get "$kind" "$name" -n "$NAMESPACE" -o jsonpath="{.spec.template.spec.containers[?(@.name=='$container')].resources.limits.memory}")
echo -e "$kind\t$name\t$container\t$image\t$req_cpu\t$req_mem\t$lim_cpu\t$lim_mem"
done
}
###############################################
# Deployments
###############################################
deployments=$(oc get deploy -n "$NAMESPACE" -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}')
for dep in $deployments; do
extract_resources "deploy" "$dep"
done
###############################################
# StatefulSets
###############################################
statefulsets=$(oc get statefulset -n "$NAMESPACE" -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}')
for sts in $statefulsets; do
extract_resources "statefulset" "$sts"
done