Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
flaper87 committed Jun 9, 2022
2 parents 4e98ea4 + 87da8d1 commit cb8dd0e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 48 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,5 @@ clean-ci:
list=$$(oc get secret -n $(EDGE_NAME) --no-headers |grep bmc|awk '{print $$1}'); \
for i in $${list}; do oc patch -n $(EDGE_NAME) secret $${i} --type json -p '[ { "op": "remove", "path": "/metadata/finalizers" } ]'; done; \
oc delete --ignore-not-found=true ns $(EDGE_NAME); \
oc rollout restart -n openshift-machine-api deployment/metal3; \
kcli delete vm -y $(EDGE_NAME)-m0 $(EDGE_NAME)-m1 $(EDGE_NAME)-m2 $(EDGE_NAME)-w0
100 changes: 52 additions & 48 deletions hack/clean/clean-libvirt-pool.sh
Original file line number Diff line number Diff line change
@@ -1,64 +1,68 @@
#!/usr/bin/env bash

set -o pipefail
set -o nounset
set -m

resourcesUsed=""
if [ -n "${1}" ]; then

# get all disk and isos in use
getUsedResources() {
for vm in $(kcli list vm -o json | jq -r .[].name); do
# preserve ISO/iso used by existing vm's
resourcesUsed=$(printf "%s|${resourcesUsed}" "${vm}.ISO")
resourcesUsed=""

# some vm's have a boot-ID iso - depending on how they were created
resourcesUsed=$(printf "%s|${resourcesUsed}" "$(kcli show vm ${vm} | grep iso: | awk '{print $2}' | sed 's#\/var\/lib\/libvirt\/images\/##g')")
# get all disk and isos in use
getUsedResources() {
for vm in $(kcli list vm -o json | jq -r .[].name); do
# preserve ISO/iso used by existing vm's
resourcesUsed=$(printf "%s|${resourcesUsed}" "${vm}.ISO")

# preserve images used by existing vm's
resourcesUsed=$(printf "%s|${resourcesUsed}" "$(kcli show vm ${vm} | grep image: | awk '{print $2}' | sed 's#\/var\/lib\/libvirt\/images\/##g')")
# some vm's have a boot-ID iso - depending on how they were created
resourcesUsed=$(printf "%s|${resourcesUsed}" "$(kcli show vm ${vm} | grep iso: | awk '{print $2}' | sed 's#\/var\/lib\/libvirt\/images\/##g')")

# preserve all disks used by existing vm's
for disk in $(kcli show vm $vm | grep -E 'diskname:' | awk '{print $10}' | sed 's#\/var\/lib\/libvirt\/images\/##'); do
resourcesUsed=$(printf "%s|${resourcesUsed}" "${disk}")
# preserve images used by existing vm's
resourcesUsed=$(printf "%s|${resourcesUsed}" "$(kcli show vm ${vm} | grep image: | awk '{print $2}' | sed 's#\/var\/lib\/libvirt\/images\/##g')")

# preserve all disks used by existing vm's
for disk in $(kcli show vm $vm | grep -E 'diskname:' | awk '{print $10}' | sed 's#\/var\/lib\/libvirt\/images\/##'); do
resourcesUsed=$(printf "%s|${resourcesUsed}" "${disk}")
done
done
done
}
}

# get the resources
getUsedResources
# get the resources
getUsedResources

# build a cmd that greps out the *used* resources
# cmd has to guarantee resources in toDelete are *unused*
# sanitize output by removing any trailing character
# and also double || introduced by getUsedResources\
# failing to do this will make cmd unusable and unreliable
resourcesGrep=$(echo $resourcesUsed | sed 's/.$//' | sed 's/||/|/'g)
cmd=$(printf "ls /var/lib/libvirt/images | grep -Ev '%s'" ${resourcesGrep})
toDelete=$(eval $cmd)
# build a cmd that greps out the *used* resources
# cmd has to guarantee resources in toDelete are *unused*
# sanitize output by removing any trailing character
# and also double || introduced by getUsedResources\
# failing to do this will make cmd unusable and unreliable
resourcesGrep=$(echo $resourcesUsed | sed 's/.$//' | sed 's/||/|/'g)
cmd=$(printf "ls /var/lib/libvirt/images | grep -Ev '%s'" ${resourcesGrep})
toDelete=$(eval $cmd)

# dry-run will prompt the images to be deleted
# now will wipe the pool
case "${1}" in
'dry-run')
echo "############### ${0} dry-run"
echo "############### resources in use - won't be deleted"
echo $cmd
echo ""
# dry-run will prompt the images to be deleted
# now will wipe the pool
case $1 in
'dry-run')
echo "############### ${0} dry-run"
echo "############### resources in use - won't be deleted"
echo $cmd
echo ""

echo "############### resources unused - will be delete"
for resource in $(echo $toDelete); do
echo $resource
done
;;
echo "############### resources unused - will be delete"
for resource in $(echo $toDelete); do
echo $resource
done
;;

'now')
for resource in $(echo $toDelete); do
kcli delete disk --novm --yes ${resource}
done
;;
'now')
for resource in $(echo $toDelete); do
kcli delete disk --novm --yes ${resource}
done
;;

*)
echo "Usage: $0 [dry-run|now]"
;;
esac
*)
echo "Usage: [dry-run|now]"
;;
esac
else
echo "Usage: [dry-run|now]"
fi
1 change: 1 addition & 0 deletions hack/deploy-hub-local/ansible/tasks/base/01-packages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,6 @@
- golang
- glibc-langpack-es
- mosh
- fpaste
ignore_errors: true
tags: [ 01-packages ]

0 comments on commit cb8dd0e

Please sign in to comment.