Merge pull request #10 from Heavybullets8/cmd-to-container

Fix multiple side cart container collision
This commit is contained in:
Heavybullets8 2022-08-22 05:24:22 +00:00 committed by GitHub
commit bd74270668
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -22,29 +22,24 @@ do
break break
fi fi
done done
rm cont_file 2> /dev/null
app_name=$(echo -e "$app_name" | grep ^"$selection)" | awk '{print $2}') app_name=$(echo -e "$app_name" | grep ^"$selection)" | awk '{print $2}')
mapfile -t pod_id < <(k3s crictl pods -s ready --namespace ix | grep -E "[[:space:]]$app_name([[:space:]]|-([-[:alnum:]])*[[:space:]])" | awk '{print $1}') mapfile -t pod_id < <(k3s crictl pods -s ready --namespace ix | grep -E "[[:space:]]$app_name([[:space:]]|-([-[:alnum:]])*[[:space:]])" | awk '{print $1}')
search=$(k3s crictl ps -a -s running | sed -E 's/[[:space:]]([0-9]*|About)[a-z0-9 ]{5,12}ago[[:space:]]//') search=$(k3s crictl ps -a -s running | sed -E 's/[[:space:]]([0-9]*|About)[a-z0-9 ]{5,12}ago[[:space:]]//')
for pod in "${pod_id[@]}" for pod in "${pod_id[@]}"
do do
if [[ $(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r " | wc -l) -gt 1 ]]; then echo "$search" | grep "$pod" >> cont_file
readarray -t containers <<<"$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")"
continue
fi
printf '%s\0' "${containers[@]}" | grep -Fxqz -- "$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")" && continue
containers+=("$(echo "$search" | grep "$pod" | awk '{print $4}' | tr -d " \t\r ")")
done done
mapfile -t containers < <(sort -u cont_file 2> /dev/null)
case "${#containers[@]}" in case "${#containers[@]}" in
0) 0)
echo -e "No containers available\nAre you sure the application in running?" echo -e "No containers available\nAre you sure the application in running?"
exit exit
;; ;;
1) 1)
container=$(echo "$search" | grep "${pod_id[0]}" | awk '{print $4}') container=$(grep "${pod_id[0]}" cont_file | awk '{print $4}')
container_id=$(echo "$search" | grep -E "[[:space:]]${container}[[:space:]]" | awk '{print $1}') container_id=$(grep -E "[[:space:]]${container}[[:space:]]" cont_file | awk '{print $1}')
;; ;;
*) *)
while true while true
do do
@ -53,7 +48,7 @@ case "${#containers[@]}" in
cont_search=$( cont_search=$(
for i in "${containers[@]}" for i in "${containers[@]}"
do do
echo "$i" echo "$i" | awk '{print $4}'
done | nl -s ") " | column -t done | nl -s ") " | column -t
) )
echo "$cont_search" echo "$cont_search"
@ -72,7 +67,7 @@ case "${#containers[@]}" in
fi fi
done done
container=$(echo "$cont_search" | grep ^"$selection)" | awk '{print $2}') container=$(echo "$cont_search" | grep ^"$selection)" | awk '{print $2}')
container_id=$(echo "$search" | grep -E "[[:space:]]${container}[[:space:]]" | awk '{print $1}') container_id=$(grep -E "[[:space:]]${container}[[:space:]]" cont_file | awk '{print $1}')
;; ;;
esac esac
while true while true
@ -113,6 +108,6 @@ do
;; ;;
esac esac
done done
rm cont_file 2> /dev/null
} }
export -f cmd_to_container export -f cmd_to_container