Browse Source

Restartforresize now restarts any type of worload

master
Fábio Kaiser Rauber 3 years ago
parent
commit
b89e24cbdc
  1. 24
      check_full_pvs.sh

24
check_full_pvs.sh

@ -8,7 +8,7 @@ showHelp () {
echo "Parameters:"
echo " -t (optional) : Threshold to use for near full PV evaluation (in %). Defaults to 85%."
echo " -f (optional) : Fix near full PVs (resize them). Defaults to false."
echo " -i (optional) : Percentage of PV increase when resizing. Defaults to 30%."
echo " -i (optional) : Percentage of PV increase when resizing. Defaults to 50%."
}
checkReqs () {
@ -62,21 +62,22 @@ waitforresize (){
restartforresize () {
NAMESPACE=$1
PVC=$2
TYPE=$2
PVC=$3
DEPLOYS=$(kubectl get deployments -n $NAMESPACE -o=jsonpath='{range .items[*]}{.metadata.name}{" "}{.spec.template.spec.volumes[].persistentVolumeClaim.claimName}{" "}{.status.replicas}{"\n"}{end}')
WORKLOADS=$(kubectl get $TYPE -n $NAMESPACE -o=jsonpath='{range .items[*]}{.metadata.name}{" "}{.spec.template.spec.volumes[].persistentVolumeClaim.claimName}{" "}{.status.replicas}{"\n"}{end}')
if [ $? -ne 0 ]; then
echo " |-- Error trying to get deployments for namespace $NAMESPACE."
else
for DEPLOY in $DEPLOYS; do
name=$(echo $DEPLOY | awk '{print $1}')
pvcname=$(echo $DEPLOY | awk '{print $2}')
scale=$(echo $DEPLOY | awk '{print $3}')
for WORKLOAD in $WORKLOADS; do
name=$(echo $WORKLOAD | awk '{print $1}')
pvcname=$(echo $WORKLOAD | awk '{print $2}')
scale=$(echo $WORKLOAD | awk '{print $3}')
if [[ "$pvcname" == $PVC ]]; then
scaleworkload $NAMESPACE deployment $name 0
scaleworkload $NAMESPACE $TYPE $name 0
waitforresize $NAMESPACE $pvcname
scaleworkload $NAMESPACE deployment $name $scale
scaleworkload $NAMESPACE $TYPE $name $scale
fi
done
fi
@ -85,7 +86,7 @@ restartforresize () {
FULLTHRESHOLD=85
FIX=0
INCREASEPERC=30
INCREASEPERC=50
while getopts ":t:i:f" opt; do
case ${opt} in
@ -130,7 +131,8 @@ for ns in $ALLNS; do
pvcstatus=$(kubectl get pvc $pvcname -n $ns -o=jsonpath='{.status.conditions[0].type}')
if [[ "$pvcstatus" == 'Resizing' ]]; then
echo " |-- Volume $pvcname already has a Resizing operation going on."
restartforresize $ns $pvcname
restartforresize $ns deployment $pvcname
restartforresize $ns statefulset $pvcname
else
newsize=$(echo ${size}*1.${INCREASEPERC}| bc | grep -v "$\.0")
echo " |-- Resizing $pvcname: ${size}Gi --> ${newsize}Gi..."

Loading…
Cancel
Save