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 NAMESPACE=$1
TYPE=$2 DEPPVC=$2
PVC=$3
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 if [ $? -ne 0 ]; then
echo " |-- Error trying to get deployments for namespace $NAMESPACE." echo " |-- Error trying to get deployments for namespace $NAMESPACE."
else else
for WORKLOAD in $WORKLOADS; do for DEP in $DEPS; do
name=$(echo $WORKLOAD | awk '{print $1}') name=$(echo $DEP | awk '{print $1}')
pvcname=$(echo $WORKLOAD | awk '{print $2}') scale=$(echo $DEP | awk '{print $2}')
scale=$(echo $WORKLOAD | awk '{print $3}') thepvc=$(echo $DEP | awk '{print $3}')
if [[ "$pvcname" == $PVC ]]; then if [[ "$thepvc" == $DEPPVC ]]; then
scaleworkload $NAMESPACE $TYPE $name 0 scaleworkload $NAMESPACE deployment $name 0
waitforresize $NAMESPACE $pvcname waitforresize $NAMESPACE $DEPPVC
scaleworkload $NAMESPACE $TYPE $name $scale scaleworkload $NAMESPACE deployment $name $scale
fi fi
done done
fi 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 FULLTHRESHOLD=85
FIX=0 FIX=0
INCREASEPERC=50 INCREASEPERC=50
@ -139,8 +160,8 @@ for ns in $ALLNS; do
echo -n " |-- Resizing $pvcname: ${size}Gi --> ${newsize}Gi..." && \ echo -n " |-- Resizing $pvcname: ${size}Gi --> ${newsize}Gi..." && \
kubectl patch pvc -n $ns $pvcname -p '{ "spec": { "resources": { "requests": { "storage": "'${newsize}'Gi" }}}}' kubectl patch pvc -n $ns $pvcname -p '{ "spec": { "resources": { "requests": { "storage": "'${newsize}'Gi" }}}}'
fi fi
restartforresize $ns deployment $pvcname restartdeploymentforresize $ns $pvcname
restartforresize $ns statefulset $pvcname restartstatefulsetforresize $ns $pvcname
fi fi
fi fi
done done

Loading…
Cancel
Save