-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathnodes.sh
executable file
·116 lines (103 loc) · 3.27 KB
/
nodes.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
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
SCRIPT_DIR=$(readlink -f `dirname "${BASH_SOURCE[0]}"`)
function help() {
echo "usage: nodes.sh [-h]"
echo
echo "Description: Creates fake KWOK nodes for performance testing"
echo
echo "Preconditions: "
echo " - The script assumes you've logged into your cluster already. If not, it will tell you to login."
echo " - The script checks that you have the kwok-controller installed, otherwise it'll tell you to install it first."
echo
echo "Options:"
echo " -h Print this help message"
echo
}
function check_kubectl_login_status() {
set +e
kubectl get ns default &> /dev/null
res="$?"
set -e
OCP="$res"
if [ $OCP == 1 ]
then
echo "You need to login to your Kubernetes Cluster"
exit 1
else
echo
echo "Nice, looks like you're logged in"
echo ""
fi
}
function check_kwok_installed_status() {
set +e
kubectl get pod -A |grep kwok-controller &> /dev/null
res2="$?"
set -e
KWOK="$res2"
if [[ $KWOK == 1 ]]
then
echo "You need Install the KWOK Controller first before running this script"
exit 1
else
echo "Nice, the KWOK Controller is installed"
fi
}
while getopts hf: option; do
case $option in
h)
help
exit 0
;;
*)
;;
esac
done
shift $((OPTIND-1))
# Track whether we have a valid kubectl login
echo "Checking whether we have a valid cluster login or not..."
check_kubectl_login_status
# Track whether you have the KWOK controller installed
echo "Checking KWOK Controller installation status"
echo
check_kwok_installed_status
echo
read -p "How many simulated KWOK nodes do you want?" NODES
echo "Nodes number is $NODES"
echo " "
COUNTER=1
while [ $COUNTER -le $NODES ]
do
ORIG_COUNTER=$(($COUNTER - 1))
echo "Submitting node $COUNTER"
# Had to do this OSTYPE because sed acts differently on Linux versus Mac
case "$OSTYPE" in
linux-gnu*)
sed -i "s/kwok-node-$ORIG_COUNTER/kwok-node-$COUNTER/g" ${SCRIPT_DIR}/node.yaml ;;
darwin*)
sed -i '' "s/kwok-node-$ORIG_COUNTER/kwok-node-$COUNTER/g" ${SCRIPT_DIR}/node.yaml ${SCRIPT_DIR}/node.yaml ;;
*)
sed -i "/kwok-node-$ORIG_COUNTER/kwok-node-$COUNTER/g" ${SCRIPT_DIR}/node.yaml ;;
esac
kubectl apply -f ${SCRIPT_DIR}/node.yaml
COUNTER=$[$COUNTER +1]
done
# Let's reset the original node.yaml file back to original value
case "$OSTYPE" in
linux-gnu*)
sed -i "s/kwok-node-$NODES/kwok-node-0/g" ${SCRIPT_DIR}/node.yaml ;;
darwin*)
sed -i '' "s/kwok-node-$NODES/kwok-node-0/g" ${SCRIPT_DIR}/node.yaml ;;
*)
sed -i "s/kwok-node-$NODES/kwok-node-0/g" ${SCRIPT_DIR}/node.yaml ;;
esac
# Check for all nodes to report complete
echo "Waiting until all the simualted pods become ready:"
kubectl wait --for=condition=Ready nodes --selector type=kwok --timeout=600s
echo " "
echo "Total amount of simulated nodes requested is: $NODES"
echo "Total number of created nodes is: "`kubectl get nodes --selector type=kwok -o name |wc -l`
kubectl get nodes --selector type=kwok
echo " "
echo "FYI, to clean up the kwow nodes, issue this:"
echo "kubectl get nodes --selector type=kwok -o name | xargs kubectl delete"