|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +SCRIPT_DIR=$(readlink -f `dirname "${BASH_SOURCE[0]}"`) |
| 4 | + |
| 5 | +function help() { |
| 6 | + echo "usage: kwokmcadperf.sh [-h]" |
| 7 | + echo |
| 8 | + echo "Description: Runs Appwrapper performance test script(s) in subdirectories under $SCRIPT_DIR." |
| 9 | + echo "NOTE: This runs on KWOK Fake nodes only." |
| 10 | + echo |
| 11 | + echo "Preconditions: " |
| 12 | + echo " - The script assumes you've logged into your cluster already. If not, it will tell you to login." |
| 13 | + echo " - The script checks that you have the mcad-controller installed, otherwise it'll tell you to install it first." |
| 14 | + echo " - The script checks that you have the kwok-controller installed, otherwise it'll tell you to install it first." |
| 15 | + echo |
| 16 | + echo "Options:" |
| 17 | + echo " -h Print this help message" |
| 18 | + echo |
| 19 | +} |
| 20 | + |
| 21 | +function check_kubectl_login_status() { |
| 22 | + set +e |
| 23 | + kubectl get ns default &> /dev/null |
| 24 | + res="$?" |
| 25 | + set -e |
| 26 | + OCP="$res" |
| 27 | + if [ $OCP == 1 ] |
| 28 | + then |
| 29 | + echo "You need to login to your Kubernetes Cluster" |
| 30 | + exit 1 |
| 31 | + else |
| 32 | + echo |
| 33 | + echo "Nice, looks like you're logged in" |
| 34 | + fi |
| 35 | +} |
| 36 | + |
| 37 | +function check_mcad_installed_status() { |
| 38 | + set +e |
| 39 | + kubectl get pod -A |grep mcad-controller &> /dev/null |
| 40 | + res2="$?" |
| 41 | + kubectl get crd |grep appwrapper &> /dev/null |
| 42 | + res3="$?" |
| 43 | + set -e |
| 44 | + MCAD="$res2" |
| 45 | + CRD="$res3" |
| 46 | + if [[ $MCAD == 1 ]] || [[ $CRD == 1 ]] |
| 47 | + then |
| 48 | + echo "You need Install MCAD Controller first before running this script" |
| 49 | + exit 1 |
| 50 | + else |
| 51 | + echo "Nice, MCAD Controller is installed" |
| 52 | + fi |
| 53 | +} |
| 54 | + |
| 55 | +function check_kwok_installed_status() { |
| 56 | + set +e |
| 57 | + kubectl get pod -A |grep kwok-controller &> /dev/null |
| 58 | + res2="$?" |
| 59 | + set -e |
| 60 | + KWOK="$res2" |
| 61 | + if [[ $KWOK == 1 ]] |
| 62 | + then |
| 63 | + echo "You need Install the KWOK Controller first before running this script" |
| 64 | + exit 1 |
| 65 | + else |
| 66 | + echo "Nice, the KWOK Controller is installed" |
| 67 | + fi |
| 68 | +} |
| 69 | + |
| 70 | + |
| 71 | +while getopts hf: option; do |
| 72 | + case $option in |
| 73 | + h) |
| 74 | + help |
| 75 | + exit 0 |
| 76 | + ;; |
| 77 | + *) |
| 78 | + ;; |
| 79 | + esac |
| 80 | +done |
| 81 | +shift $((OPTIND-1)) |
| 82 | + |
| 83 | +# Track whether we have a valid kubectl login |
| 84 | +echo "Checking whether we have a valid cluster login or not..." |
| 85 | +check_kubectl_login_status |
| 86 | + |
| 87 | +# Track whether you have the MCAD controller installed |
| 88 | +echo "Checking MCAD Controller installation status" |
| 89 | +echo |
| 90 | +check_mcad_installed_status |
| 91 | + |
| 92 | +# Track whether you have the KWOK controller installed |
| 93 | +echo "Checking MCAD Controller installation status" |
| 94 | +echo |
| 95 | +check_kwok_installed_status |
| 96 | + |
| 97 | +echo |
| 98 | +read -p "How many fake KWOK appwrapper jobs do you want?" jobs |
| 99 | + |
| 100 | +# Start the timer now |
| 101 | +SECONDS=0 |
| 102 | + |
| 103 | +echo "jobs number is $jobs" |
| 104 | +export STARTTIME=`date +"%T"` |
| 105 | +echo " " |
| 106 | +echo "Jobs started at: $STARTTIME" |tee fake-job-$STARTTIME.log |
| 107 | +echo " " |
| 108 | + |
| 109 | +# This fixes the number of jobs to be one less so the for loop gets the right amount |
| 110 | +((realjobs=$jobs-1)) |
| 111 | + |
| 112 | +for num in $(eval echo "{0.."$realjobs"}") |
| 113 | +do |
| 114 | + next_num=$(($num + 1)) |
| 115 | + echo "Submitting job $next_num" |
| 116 | +# Had to do this OSTYPE because sed acts differently on Linux versus Mac |
| 117 | + case "$OSTYPE" in |
| 118 | + linux-gnu*) |
| 119 | + sed -i "s/fake-defaultaw-schd-spec-with-timeout-$num/fake-defaultaw-schd-spec-with-timeout-$next_num/g" ${SCRIPT_DIR}/preempt-exp-kwok.yaml ;; |
| 120 | + darwin*) |
| 121 | + sed -i '' "s/fake-defaultaw-schd-spec-with-timeout-$num/fake-defaultaw-schd-spec-with-timeout-$next_num/g" ${SCRIPT_DIR}/preempt-exp-kwok.yaml ;; |
| 122 | + *) |
| 123 | + sed -i "s/fake-defaultaw-schd-spec-with-timeout-$num/fake-defaultaw-schd-spec-with-timeout-$next_num/g" ${SCRIPT_DIR}/preempt-exp-kwok.yaml ;; |
| 124 | + esac |
| 125 | + kubectl apply -f ${SCRIPT_DIR}/preempt-exp-kwok.yaml |
| 126 | +done |
| 127 | + |
| 128 | + # Let's reset the original preempt-exp-kwok.yaml file back to original value |
| 129 | + case "$OSTYPE" in |
| 130 | + linux-gnu*) |
| 131 | + sed -i "s/fake-defaultaw-schd-spec-with-timeout-$next_num/fake-defaultaw-schd-spec-with-timeout-1/g" ${SCRIPT_DIR}/preempt-exp-kwok.yaml ;; |
| 132 | + darwin*) |
| 133 | + sed -i '' "s/fake-defaultaw-schd-spec-with-timeout-$next_num/fake-defaultaw-schd-spec-with-timeout-1/g" ${SCRIPT_DIR}/preempt-exp-kwok.yaml ;; |
| 134 | + *) |
| 135 | + sed -i "s/fake-defaultaw-schd-spec-with-timeout-$next_num/fake-defaultaw-schd-spec-with-timeout-1/g" ${SCRIPT_DIR}/preempt-exp-kwok.yaml ;; |
| 136 | + esac |
| 137 | + |
| 138 | +# Check for all jobs to report complete |
| 139 | +jobstatus=`kubectl get jobs -n default --no-headers --field-selector status.successful=1 |wc -l` |
| 140 | + |
| 141 | +while [ $jobstatus -lt $jobs ] |
| 142 | +do |
| 143 | + echo "Number of completed jobs is: " $jobstatus " and the goal is: " $jobs |
| 144 | + sleep 10 |
| 145 | + jobstatus=`kubectl get jobs -n default --no-headers --field-selector status.successful=1 |wc -l` |
| 146 | +done |
| 147 | + |
| 148 | +echo " " |
| 149 | +export FINISHTIME=`date +"%T"` |
| 150 | +echo "All $jobstatus jobs finished: $FINISHTIME" |tee -a fake-job-$STARTTIME.log |
| 151 | +echo "Total amount of time for $jobs appwrappers is: $SECONDS seconds" |tee -a ${SCRIPT_DIR}/fake-job-$STARTTIME.log |
| 152 | +echo " " |
| 153 | +echo "Test results are stored in this file: ${SCRIPT_DIR}/fake-job-$next_num-$STARTTIME.log" |
| 154 | + |
| 155 | +# Rename the log to show the number of jobs used |
| 156 | +mv ${SCRIPT_DIR}/fake-job-$STARTTIME.log ${SCRIPT_DIR}/fake-job-$next_num-$STARTTIME.log |
| 157 | + |
| 158 | +#Ask if you want to auto-cleanup the appwrapper jobs |
| 159 | +echo "Do you want to cleanup the most recently created appwrappers? [Y/n]" |
| 160 | +read DELETE |
| 161 | +if [[ $DELETE == "Y" || $DELETE == "y" ]]; then |
| 162 | + echo "OK, deleting" |
| 163 | + ${SCRIPT_DIR}/cleanup-mcad-kwok.sh |
| 164 | +else |
| 165 | + echo "OK, you'll need to cleanup yourself later using ./cleanup-mcad-kwok.sh" |
| 166 | +fi |
0 commit comments