forked from project-codeflare/multi-cluster-app-dispatcher
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathperf.sh
executable file
·144 lines (125 loc) · 4.54 KB
/
perf.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash
SCRIPT_DIR=$(readlink -f `dirname "${BASH_SOURCE[0]}"`)
function help() {
echo "usage: perf.sh [-h]"
echo
echo "Description: Runs Appwrapper performance test script(s) in subdirectories under $SCRIPT_DIR."
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 mcad-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"
fi
}
function check_mcad_installed_status() {
set +e
kubectl get pod -A |grep mcad-controller &> /dev/null
res2="$?"
kubectl get crd |grep appwrapper &> /dev/null
res3="$?"
set -e
MCAD="$res2"
CRD="$res3"
if [[ $MCAD == 1 ]] || [[ $CRD == 1 ]]
then
echo "You need Install MCAD Controller first before running this script"
exit 1
else
echo "Nice, MCAD 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 MCAD controller installed
echo "Checking MCAD Controller installation status"
echo
#check_mcad_installed_status
echo
read -p "How many appwrapper jobs do you want?" jobs
# Start the timer now
SECONDS=0
echo "Appwrapper number is $jobs"
export STARTTIME=`date +"%T"`
echo " "
echo "Appwrappers started at: $STARTTIME" |tee job-$STARTTIME.log
echo " "
# This fixes the number of jobs to be one less so the for loop gets the right amount
((realjobs=$jobs-1))
for num in $(eval echo "{0.."$realjobs"}")
do
next_num=$(($num + 1))
echo "Submitting job $next_num"
# Had to do this OSTYPE because sed acts differently on Linux versus Mac
case "$OSTYPE" in
linux-gnu*)
sed -i "s/defaultaw-schd-spec-with-timeout-$num/defaultaw-schd-spec-with-timeout-$next_num/g" ${SCRIPT_DIR}/preempt-exp.yaml ;;
darwin*)
sed -i '' "s/defaultaw-schd-spec-with-timeout-$num/defaultaw-schd-spec-with-timeout-$next_num/g" ${SCRIPT_DIR}/preempt-exp.yaml ;;
*)
sed -i "s/defaultaw-schd-spec-with-timeout-$num/defaultaw-schd-spec-with-timeout-$next_num/g" ${SCRIPT_DIR}/preempt-exp.yaml ;;
esac
kubectl apply -f ${SCRIPT_DIR}/preempt-exp.yaml
done
# Let's reset the original preempt-exp.yaml file back to original value
case "$OSTYPE" in
linux-gnu*)
sed -i "s/defaultaw-schd-spec-with-timeout-$next_num/defaultaw-schd-spec-with-timeout-1/g" ${SCRIPT_DIR}/preempt-exp.yaml ;;
darwin*)
sed -i '' "s/defaultaw-schd-spec-with-timeout-$next_num/defaultaw-schd-spec-with-timeout-1/g" ${SCRIPT_DIR}/preempt-exp.yaml ;;
*)
sed -i "s/defaultaw-schd-spec-with-timeout-$next_num/defaultaw-schd-spec-with-timeout-1/g" ${SCRIPT_DIR}/preempt-exp.yaml ;;
esac
# Check for all appwrappers to report complete
jobstatus=`kubectl get appwrappers -o=custom-columns=SUCCESS:.status.Succeeded -n default |grep 1 |wc -l`
while [ $jobstatus -lt $jobs ]
do
echo "Number of completed appwrappers is: " $jobstatus " and the goal is: " $jobs
sleep 10
jobstatus=`kubectl get appwrappers -o=custom-columns=SUCCESS:.status.Succeeded -n default |grep 1 |wc -l`
done
echo " "
export FINISHTIME=`date +"%T"`
echo "All $jobstatus appwrappers finished: $FINISHTIME" |tee -a job-$STARTTIME.log
echo "Total amount of time for $jobs appwrappers is: $SECONDS seconds" |tee -a ${SCRIPT_DIR}/job-$STARTTIME.log
echo " "
echo "Test results are stored in this file: ${SCRIPT_DIR}/job-$next_num-$STARTTIME.log"
# Rename the log to show the number of jobs used
mv ${SCRIPT_DIR}/job-$STARTTIME.log ${SCRIPT_DIR}/job-$next_num-$STARTTIME.log
#Ask if you want to auto-cleanup the appwrapper jobs
echo "Do you want to cleanup the most recently created appwrappers? [Y/n]"
read DELETE
if [[ $DELETE == "Y" || $DELETE == "y" ]]; then
echo "OK, deleting"
${SCRIPT_DIR}/cleanup.sh
else
echo "OK, you'll need to cleanup yourself later using ./cleanup.sh"
fi