-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-apiversion.sh
29 lines (24 loc) · 979 Bytes
/
get-apiversion.sh
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
#!/bin/bash
get_api_group() {
if [ -z "$resource" ]; then
echo "Invalid input, empty string, exiting!"
return 1
fi
resource_info=$(kubectl api-resources --no-headers | grep -iE '(^|[ ,])'$1'([ ,]|$)' | grep -iv metric)
echo -e "The result is: \n$resource_info"
if [ -z "$resource_info" ]; then
echo "The resource '$1' not found in this cluster."
else
api_group=$(echo "$resource_info" | awk '{for(i=1;i<=NF;i++) if ($i ~ /\// || $i =="v1") print $i }' | cut -d'/' -f1)
num_api_groups=$(echo "$api_group" | wc -w)
if [ $num_api_groups -gt 1 ]; then
echo "The resource '$1' is part of multiple apiGroups as following: $api_group" | tr '\n' ' '
elif [ $api_group == "v1" ]; then
echo "The resource '$1' is part of k8s core apiGroup."
else
echo "The apiGroup for resource '$1' is: $api_group"
fi
fi
}
read -p "Enter the Kubernetes resource name: " resource
get_api_group $resource