-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools_assist.sh
More file actions
69 lines (60 loc) · 1.62 KB
/
Copy pathtools_assist.sh
File metadata and controls
69 lines (60 loc) · 1.62 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
source tools_utils.sh
PRINT_CONTAINERS=false
NAMESPACE=""
print_help() {
printf '\nKWAAP techdata assit script help.\n Flags:\n'
printf '\t -n, --namespace \t\t The Namespace in which KWAAP is installed. Default: all namespases\n'
printf '\t -c, --containers \t\t Prints the list of pod-names and container-names per namespace. Default: Prints pod&conataine names from all namespaces\n'
}
display_usage_get_containers() {
echo "Usage: $0 [-n|--namespace <namespace_value>] -c|--containers"
}
while [[ "$1" =~ ^- ]]; do
case $1 in
-n | --namespace)
if [ -z "$2" ] || [[ "$2" == "-"* ]]; then
print_error "Error: The -n|--namespace parameter requires a namespace value."
display_usage_get_containers
exit 1
fi
NAMESPACE="$2"
shift
shift
;;
-c | --containers)
PRINT_CONTAINERS=true
shift
;;
-h | --help)
##help scenario.
print_help
exit 1
;;
*)
print_error "Error: Invalid option -$1"
display_usage
exit 1
;;
esac
done
get_pods_and_container_per_namespace() {
local ns=$1 # arg1 - Namespace
if [[ -z "$ns" ]]; then
cmd="kubectl get pods --all-namespaces --output=custom-columns=NAMESPACE:.metadata.namespace,POD:.metadata.name,CONTAINERS:.spec.containers[*].name"
namespace_msg="in namespace $ns"
else
cmd="kubectl get pods -n $ns --output=custom-columns=POD:.metadata.name,CONTAINERS:.spec.containers[*].name"
fi
handle_cmd $cmd
if [[ $EXIT_CODE -eq 0 ]]; then
if [[ -z "$STDOUT_OUTPUT" ]]; then
echo "No pods found $namespace_msg"
else
echo "${STDOUT_OUTPUT[@]}"
fi
fi
}
if [ "$PRINT_CONTAINERS" = true ]; then
get_pods_and_container_per_namespace $NAMESPACE
fi