This repository has been archived by the owner on Sep 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathgluster-resize-pv.sh
executable file
·67 lines (51 loc) · 1.79 KB
/
gluster-resize-pv.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
#!/bin/bash
# Environment definition
## Define logical/gluster volumes to be resized
gluster_volume[0]="gluster_vol_88"
gluster_volume[1]="gluster_vol_86"
## Define OpenShift persistent volumes to be resized
persistent_volume[0]="gluster-pv88"
persistent_volume[1]="gluster-pv86"
## Define volume group containing the logical/gluster volumes
volume_group="vg_gluster"
## Define new volume size in gigabytes
new_volume_size=2
## Define deploymentConfigs to scale down
deploymentconfig[0]=""
#deploymentconfig[1]=""
## Define project
project=""
## Define gluster nodes (hostnames or IPs)
gluster_node[0]=""
gluster_node[1]=""
## Initialize variables
dc_replicas=()
# Rock'n'roll
## Reset timer
SECONDS=0
## Scale down applications
for ((i=0; i<${#deploymentconfig[@]}; i++)); do
echo "Scaling down ${deploymentconfig[$i]}"
dc_replicas[$i]=$(oc get dc ${deploymentconfig[$i]} --output jsonpath='{.status.replicas}' -n $project)
oc scale --replicas=0 dc ${deploymentconfig[$i]} -n $project
done
## Resize logical volumes
for node in "${gluster_node[@]}"; do
for vol in "${gluster_volume[@]}"; do
echo "Resizing gluster volume $vol on node $node"
ssh $node "lvresize --size ${new_volume_size}g --resizefs /dev/${volume_group}/${vol}"
done
done
## Resize persistent volume in OpenShift
for pv in "${persistent_volume[@]}"; do
echo "Patching persistent volume"
oc patch pv $pv --patch="{\"spec\":{\"capacity\":{\"storage\":\"${new_volume_size}Gi\"}}}"
done
## Scale up applications
for ((i=0; i<${#deploymentconfig[@]}; i++)); do
echo "Scaling up ${deploymentconfig[$i]} to ${dc_replicas[$i]}"
oc scale --replicas=${dc_replicas[$i]} dc ${deploymentconfig[$i]} -n $project
done
## Calculate run duration
duration=$SECONDS
echo "Duration was $(($duration / 60)) minutes $(($duration % 60)) seconds"