Browse Source

First working version for already patched pvcs

master
Fábio Kaiser Rauber 3 years ago
parent
commit
cbac8d49ab
  1. 66
      check_full_pvs.sh

66
check_full_pvs.sh

@ -24,32 +24,59 @@ checkReqs () {
} }
appstop () { scaleworkload () {
$NAMESPACE = $1 NAMESPACE=$1
#Stop deployments TYPE=$2
DEPLOYS=$(kubectl get deployments --namespace ${NAMESPACE} | grep -v NAME | awk '{print $1}' ) WORKLOADNAME=$3
SCALE=$4
echo -n " |-- Scaling $TYPE $WORKLOADNAME in $NAMESPACE to $SCALE... " && \
kubectl scale --replicas=$SCALE $TYPE $WORKLOADNAME --namespace ${NAMESPACE}
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo " |-- Error trying to get deployments for namespace $NAMESPACE." echo " |-- Error scaling $TYPE $WORKLOADNAME to $SCALE."
fi
}
waitforresize (){
ns=$1
pvcname=$2
echo " |-- Waiting for volume resize for $pvcname..."
pendingresize=0
for count in $(seq 1 60); do
pvcstatus=$(kubectl get pvc $pvcname -n $ns -o=jsonpath='{.status.conditions[0].type}')
if [[ "$pvcstatus" == "FileSystemResizePending" ]]; then
echo " |-- $pvcname resized. Need now to resize inner filesystem. This happens automatically when a pod mounts the volume."
pendingresize=1
break
else else
for DEPLOY in $DEPLOYS; do sleep 10
echo -n " |-- Stopping in ${NAMESPACE}... " && \
kubectl scale --replicas=0 deployment ${DEPLOY} --namespace ${NAMESPACE}
if [ $? -ne 0 ]; then
echo "Error stopping $DEPLOY in namespace $NAMESPACE."
fi fi
done done
if [ $pendingresize -eq 0 ]; then
echo " |-- Timeout trying to resize $pvcname."
fi fi
#Stop statefulsets }
SSETS=$(kubectl get statefulsets --namespace ${NAMESPACE} | grep -v NAME | awk '{print $1}' )
restartforresize () {
NAMESPACE=$1
PVC=$2
DEPLOYS=$(kubectl get deployments -n $NAMESPACE -o=jsonpath='{range .items[*]}{.metadata.name}{" "}{.spec.template.spec.volumes[].persistentVolumeClaim.claimName}{" "}{.status.replicas}{"\n"}{end}')
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo " |-- Error trying to get statefulsets for namespace $NAMESPACE." echo " |-- Error trying to get deployments for namespace $NAMESPACE."
else else
for SSET in $SSETS; do for DEPLOY in $DEPLOYS; do
echo -n "Stopping in ${NAMESPACE}... " && \ name=$(echo $DEPLOY | awk '{print $1}')
kubectl scale --replicas=0 statefulset ${SSET} --namespace ${NAMESPACE} pvcname=$(echo $DEPLOY | awk '{print $2}')
if [ $? -ne 0 ]; then scale=$(echo $DEPLOY | awk '{print $3}')
echo "Error stopping $SSET in namespace $NAMESPACE."
if [[ "$pvcname" == $PVC ]]; then
scaleworkload $NAMESPACE deployment $name 0
waitforresize $NAMESPACE $pvcname
scaleworkload $NAMESPACE deployment $name $scale
fi fi
done done
fi fi
@ -103,8 +130,9 @@ for ns in $ALLNS; do
pvcstatus=$(kubectl get pvc $pvcname -n $ns -o=jsonpath='{.status.conditions[0].type}') pvcstatus=$(kubectl get pvc $pvcname -n $ns -o=jsonpath='{.status.conditions[0].type}')
if [[ "$pvcstatus" == 'Resizing' ]]; then if [[ "$pvcstatus" == 'Resizing' ]]; then
echo " |-- Volume $pvcname already has a Resizing operation going on." echo " |-- Volume $pvcname already has a Resizing operation going on."
restartforresize $ns $pvcname
else else
newsize=$(echo ${size}*1.5| bc | grep -v "$\.0") newsize=$(echo ${size}*1.${INCREASEPERC}| bc | grep -v "$\.0")
echo " |-- Resizing $pvcname: ${size}Gi --> ${newsize}Gi..." echo " |-- Resizing $pvcname: ${size}Gi --> ${newsize}Gi..."
fi fi
fi fi

Loading…
Cancel
Save