Browse Source

Fix issue when dealing with statefulsets

master
Fábio Kaiser Rauber 3 years ago
parent
commit
ee213218ec
  1. 51
      check_full_pvs.sh

51
check_full_pvs.sh

@ -63,30 +63,51 @@ waitforresize (){
}
restartforresize () {
restartdeploymentforresize () {
NAMESPACE=$1
TYPE=$2
PVC=$3
DEPPVC=$2
WORKLOADS=$(kubectl get $TYPE -n $NAMESPACE -o=jsonpath='{range .items[*]}{.metadata.name}{" "}{.spec.template.spec.volumes[].persistentVolumeClaim.claimName}{" "}{.status.replicas}{"\n"}{end}')
DEPS=$(kubectl get deployment -n $NAMESPACE -o=jsonpath='{range .items[*]}{.metadata.name}{" "}{.status.replicas}{" "}{.spec.template.spec.volumes[*].persistentVolumeClaim.claimName}{"\n"}{end}')
if [ $? -ne 0 ]; then
echo " |-- Error trying to get deployments for namespace $NAMESPACE."
else
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 $TYPE $name 0
waitforresize $NAMESPACE $pvcname
scaleworkload $NAMESPACE $TYPE $name $scale
for DEP in $DEPS; do
name=$(echo $DEP | awk '{print $1}')
scale=$(echo $DEP | awk '{print $2}')
thepvc=$(echo $DEP | awk '{print $3}')
if [[ "$thepvc" == $DEPPVC ]]; then
scaleworkload $NAMESPACE deployment $name 0
waitforresize $NAMESPACE $DEPPVC
scaleworkload $NAMESPACE deployment $name $scale
fi
done
fi
}
restartstatefulsetforresize() {
NAMESPACE=$1
SSPVC=$2
SSETS=$(kubectl get statefulset -n $NAMESPACE -o=jsonpath='{range .items[*]}{.metadata.name}{" "}{.status.replicas}{" "}{.spec.volumeClaimTemplates[].metadata.name}{"-"}{.metadata.name}{"\n"}{end}')
if [ $? -ne 0 ]; then
echo " |-- Error trying to get statefulsets for namespace $NAMESPACE."
else
for SSET in $SSETS; do
name=$(echo $SSET | awk '{print $1}')
scale=$(echo $SSET | awk '{print $2}')
thepvc=$(echo $SSET | awk '{print $3}')
if [[ "$SSPVC" =~ $thepvc-[0-9] ]]; then
scaleworkload $NAMESPACE statefulset $name 0
waitforresize $NAMESPACE $SSPVC
scaleworkload $NAMESPACE statefulset $name $scale
fi
done
fi
}
FULLTHRESHOLD=85
FIX=0
INCREASEPERC=50
@ -139,8 +160,8 @@ for ns in $ALLNS; do
echo -n " |-- Resizing $pvcname: ${size}Gi --> ${newsize}Gi..." && \
kubectl patch pvc -n $ns $pvcname -p '{ "spec": { "resources": { "requests": { "storage": "'${newsize}'Gi" }}}}'
fi
restartforresize $ns deployment $pvcname
restartforresize $ns statefulset $pvcname
restartdeploymentforresize $ns $pvcname
restartstatefulsetforresize $ns $pvcname
fi
fi
done

Loading…
Cancel
Save