Skip to content

Commit 02f6d82

Browse files
authored
Update pv-resize.sh (#153)
1 parent 98c70d4 commit 02f6d82

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

scripts/pv-resize.sh

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ resize() {
4343
local CLUSTER_TYPE=$1
4444
local CLUSTER_NAME=$2
4545
local NAMESPACE=$3
46-
local INT_NEW_SIZE=$4
47-
local NEW_SIZE_SUFFIX=$5
46+
local WAIT=$4
47+
local INT_NEW_SIZE=$5
48+
local NEW_SIZE_SUFFIX=$6
4849

4950
if [ -f "${CLUSTER_NAME}"-sts.yaml ]; then
5051
die "${CLUSTER_NAME}-sts.yaml exist, please delete by running rm -f ${CLUSTER_NAME}-sts.yaml"
@@ -63,14 +64,13 @@ resize() {
6364
INT_current_capacity=( $(grep -Eo '^[0-9]+\.?[0-9]*' <<< "${current_capacity}") )
6465
INT_current_capacity_suffix="${current_capacity#"${INT_current_capacity}"}"
6566
current_multiplier=$(get_suffix_multiplier ${INT_current_capacity_suffix})
66-
RAW_current_size=`bc -l <<< "${INT_current_capacity} * 1024^${current_multiplier}"`
67+
let RAW_current_size=( ${INT_current_capacity}*1024**${current_multiplier} )
6768

68-
new_mulitplier=$(get_suffix_multiplier ${NEW_SIZE_SUFFIX})
69-
RAW_new_size=`bc -l <<< "${INT_NEW_SIZE} * 1024^${new_mulitplier}"`
70-
expand=`bc -l <<< "${RAW_new_size} > ${RAW_current_size}"`
69+
new_multiplier=$(get_suffix_multiplier ${NEW_SIZE_SUFFIX})
70+
let RAW_new_size=( ${INT_NEW_SIZE}*1024**${new_multiplier} )
7171

72-
if [ ${expand} -eq "1" ]; then
73-
NEW_SIZE="${INT_NEW_SIZE}${NEW_SIZE_SUFFIX}"
72+
NEW_SIZE="${INT_NEW_SIZE}${NEW_SIZE_SUFFIX}"
73+
if [ "${RAW_new_size}" -gt "${RAW_current_size}" ]; then
7474
echo "${green}#########################"
7575
echo "#### PVC: ${PVC}"
7676
echo "#### Current Size: ${current_capacity}"
@@ -90,15 +90,16 @@ resize() {
9090

9191
# Resize can take 2-3 tries 2 mins apart while resizing
9292
echo "${green}#### Waiting for PVC resize: ${PVC}${reset}"
93-
kubectl wait --for=condition=FileSystemResizePending pvc/"${PVC}" -n "${NAMESPACE}" --timeout=30m
93+
echo " kubectl wait --for=condition=FileSystemResizePending pvc/"${PVC}" -n "${NAMESPACE}" --timeout="${WAIT}"m"
94+
kubectl wait --for=condition=FileSystemResizePending pvc/"${PVC}" -n "${NAMESPACE}" --timeout="${WAIT}"m
9495
# Creating the sts puts the pod back and reattached the pvc
9596
kubectl create -f "${CLUSTER_NAME}"-sts.yaml -n "${NAMESPACE}"
9697
# This wait isn't strictly necessary as the rolling operator on the next \
9798
# pod in the queue would prevent issues.
9899
echo "${green} #### Waiting for Pod to start: ${POD}${reset}"
99-
kubectl wait --for=condition=ready pod/${POD} -n "${NAMESPACE}" --timeout=30m
100+
kubectl wait --for=condition=ready pod/${POD} -n "${NAMESPACE}" --timeout="${WAIT}"m
100101
else
101-
echo "${green}#### PVC: ${PVC} is already size: ${current_capacity}${reset}. This script is only for disk expansion."
102+
echo "${green}#### PVC: ${PVC} is size: ${current_capacity} which is not less than requested new size: ${NEW_SIZE}${reset}. This script is only for disk expansion."
102103
fi
103104
done
104105

@@ -113,12 +114,13 @@ resize() {
113114
components_types=(kafka ksqldb controlcenter zookeeper)
114115
valid_suffixes=("Ki" "Mi" "Gi" "Ti")
115116
usage() {
116-
echo "usage: ./pv-resize.sh -c <cluster-name> -t <cluster-type> -n <namespace> -s <size_with_unit>"
117+
echo "usage: ./pv-resize.sh -c <cluster-name> -t <cluster-type> -n <namespace> -s <size_with_unit> -w <wait_duration_minutes>"
117118
echo " ";
118119
echo " -c | --cluster-name : name of the cluster to resize the PV";
119120
echo " -t | --cluster-type : confluent platform component, supported value: ${components_types[*]}";
120121
echo " -n | --namespace : kubernetes namespace where cluster is running";
121122
echo " -s | --size : new PV size in Ki|Mi|Gi|Ti";
123+
echo " -w | --wait : wait duration for pod to be ready in minutes (default 60 min)";
122124
echo " -h | --help : Usage command";
123125
}
124126

@@ -130,6 +132,7 @@ parse_args() {
130132
-c | --name ) name="${2}"; shift;;
131133
-n | --namespace ) namespace="${2}"; shift;;
132134
-s | --size) size="${2}"; shift;;
135+
-w | --wait) wait="${2}"; shift;;
133136
-h | --help ) help="true"; ;;
134137
*) args+=("$1")
135138
esac
@@ -145,14 +148,15 @@ parse_args() {
145148
if [[ ! "${components_types[*]}" =~ ${type} ]]; then die "Please provide cluster type, supported value: ${components_types[*]}"; fi
146149
if [[ -z ${namespace} ]]; then usage; die "==> Please provide namespace where cluster is running"; fi
147150
if [[ -z ${size} ]]; then usage; die "==> Please provide PV size in ${SUFFIXES_STRING}"; fi
151+
if [[ -z ${wait} ]]; then wait=60; fi
148152

149153
local NEW_SIZE_VALUE=( $(grep -Eo '^[0-9]+' <<< "${size}") )
150154
#decimal todo
151155
local NEW_SIZE_SUFFIX="${size#"${NEW_SIZE_VALUE}"}"
152156
if [ -z "${NEW_SIZE_VALUE}" ] || [ "${NEW_SIZE_VALUE}" == "0" ]
153157
then
154158
# do not allow decimals https://github.com/kubernetes/kubernetes/pull/100100
155-
die "new size with unit parameter is not properly formatted. No decimals allowed"
159+
die "--size parameter is not properly formatted. No decimals allowed"
156160
fi
157161

158162
local in=1
@@ -164,11 +168,10 @@ parse_args() {
164168
done
165169
if [[ ${in} -eq 1 ]];
166170
then
167-
die "new size with unit parameter should not have decimals or is not properly formatted with units ${SUFFIXES_STRING}"
171+
die "--size with unit parameter should not have decimals and should be properly formatted with units ${SUFFIXES_STRING}"
168172
fi
169173

170-
resize "${type}" "${name}" "${namespace}" "${NEW_SIZE_VALUE}" "${NEW_SIZE_SUFFIX}"
174+
resize "${type}" "${name}" "${namespace}" "${wait}" "${NEW_SIZE_VALUE}" "${NEW_SIZE_SUFFIX}"
171175
}
172176

173177
parse_args "$@";
174-

0 commit comments

Comments
 (0)