11#! /bin/bash
22set -ex
3- kubectl apply -f hack/manifests/pod.yaml
4- kubectl apply -f hack/manifests/hostprocess.yaml
5- sleep 1m
6- total_num_of_run=4
3+ total_num_of_run=5
74scale_up_of_pods=2400
85scale_down_pods=1
9- echo " Total num of run $total_num_of_run "
6+
7+ function help()
8+ {
9+ echo " Scale deployment based on the parameters."
10+ echo " By default script will repeat the process of scale up/down"
11+ echo
12+ echo " Syntax: scale [-h|n|u|s|c|r]"
13+ echo " options:"
14+ echo " h Print this help."
15+ echo " n Number of times the scale down/scale up task should run."
16+ echo " u Number of pods to be scaled up."
17+ echo " s Scale the pods single time. Accepted Values: true, default : false"
18+ echo " c Check deployment status. Accepted Values: true, default : false"
19+ echo
20+ }
1021
1122function check_deployment() {
1223 available=-1
@@ -22,16 +33,42 @@ function check_deployment() {
2233 echo " deployment complete."
2334}
2435
25- for (( i= 1 ; i <= total_num_of_run; i++ ))
26- do
27- echo " Current Run: $i "
28- echo " Scaling pods to : $scale_up_of_pods "
29- kubectl scale deployment container --replicas $scale_up_of_pods
30- check_deployment $scale_up_of_pods
31- echo " Scaling down pods to : $scale_down_pods "
32- kubectl scale deployment container --replicas $scale_down_pods
33- check_deployment $scale_down_pods
36+ function scale_deployment()
37+ {
38+ desired_replicas=$1
39+ kubectl scale deployment container --replicas " $desired_replicas "
40+ echo " Scaled the deployment to $desired_replicas "
41+ }
42+
43+ function repeat_deployment() {
44+ echo " Total num of run $total_num_of_run "
45+ for (( i= 1 ; i <= total_num_of_run; i++ ))
46+ do
47+ echo " Current Run: $i "
48+ echo " Scaling down pods to : $scale_down_pods "
49+ scale_deployment $scale_down_pods
50+ check_deployment $scale_down_pods
51+ echo " Scaling pods to : $scale_up_of_pods "
52+ scale_deployment " $scale_up_of_pods "
53+ check_deployment " $scale_up_of_pods "
54+ done
55+ }
56+
57+ while getopts " :h:n:u:sc" option; do
58+ case $option in
59+ h) help
60+ exit ;;
61+ n) total_num_of_run=$OPTARG ;;
62+ u) scale_up_of_pods=$OPTARG ;;
63+ s) echo " Scale deployment"
64+ scale_deployment " $scale_up_of_pods " ;;
65+ c) echo " Check deployment"
66+ check_deployment " $scale_up_of_pods " ;;
67+ \? ) echo " Error: Invalid option"
68+ exit ;;
69+ esac
3470done
3571
36- kubectl scale deployment container --replicas $scale_up_of_pods
37- check_deployment $scale_up_of_pods
72+ if [ " $total_num_of_run " -gt 0 ]; then
73+ repeat_deployment
74+ fi
0 commit comments