Skip to content

Commit

Permalink
Increase obsolete image flagging and pruning
Browse files Browse the repository at this point in the history
It was observed in the Cirrus-CI cron logs, that only the total
number of images scanned is reported.  Fix this by giving more
useful info., like the number of candidates for obsolete/pruning.

Related, the original restriction of `10` obsolete/prune images
was originally put in place when only a few repos utilized Cirrus-CI
VMs and image building was substantially more infrequent.  The
reason it exists is to prevent potential catastrophe should the `meta`
time stamp updating tasks have a bug or some other related failure occur.
Increase the limit to `50` so deletions may proceed much more rapidly.

*Note:* "Obsolete" images still live w/in a 30-day window where they can
be recovered if need be.  It's simply that any attempted use by CI will
fail, putting someone on notice that image recovery may be necessary.

Signed-off-by: Chris Evich <cevich@redhat.com>
  • Loading branch information
cevich committed Jul 8, 2024
1 parent a86360d commit f67769a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion IMG_SFX
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20240702t180702z-f40f39d13
20240708t135624z-f40f39d13
9 changes: 5 additions & 4 deletions imgobsolete/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ gcloud_init

# Set this to 1 for testing
DRY_RUN="${DRY_RUN:-0}"
OBSOLETE_LIMIT=10
OBSOLETE_LIMIT=50
THEFUTURE=$(date --date='+1 hour' +%s)
TOO_OLD_DAYS='30'
TOO_OLD_DESC="$TOO_OLD_DAYS days ago"
Expand Down Expand Up @@ -201,14 +201,15 @@ for (( i=nr_amis ; i ; i-- )); do
done

COUNT=$(<"$IMGCOUNT")
CANDIDATES=$(wc -l <$TOOBSOLETE)
msg "########################################################################"
msg "Obsoleting $OBSOLETE_LIMIT random images of $COUNT examined:"
msg "Obsoleting $OBSOLETE_LIMIT random image candidates ($CANDIDATES/$COUNT total):"

# Require a minimum number of images to exist. Also if there is some
# horrible scripting accident, this limits the blast-radius.
if [[ "$COUNT" -lt $OBSOLETE_LIMIT ]]
if [[ "$CANDIDATES" -lt $OBSOLETE_LIMIT ]]
then
die 0 "Safety-net Insufficient images ($COUNT) to process ($OBSOLETE_LIMIT required)"
die 0 "Safety-net Insufficient images ($CANDIDATES) to process ($OBSOLETE_LIMIT required)"
fi

# Don't let one bad apple ruin the whole bunch
Expand Down
9 changes: 5 additions & 4 deletions imgprune/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ gcloud_init
# Set this to 1 for testing
DRY_RUN="${DRY_RUN:-0}"
# For safety's sake limit nr deletions
DELETE_LIMIT=10
DELETE_LIMIT=50
ABOUTNOW=$(date --iso-8601=date) # precision is not needed for this use
# Format Ref: https://cloud.google.com/sdk/gcloud/reference/topic/formats
# Field list from `gcloud compute images list --limit=1 --format=text`
Expand Down Expand Up @@ -106,13 +106,14 @@ for (( i=nr_amis ; i ; i-- )); do
done

COUNT=$(<"$IMGCOUNT")
CANDIDATES=$(wc -l <$TODELETE)
msg "########################################################################"
msg "Deleting up to $DELETE_LIMIT random images of $COUNT examined:"
msg "Deleting up to $DELETE_LIMIT random image candidates ($CANDIDATES/$COUNT total)::"

# Require a minimum number of images to exist
if [[ "$COUNT" -lt $DELETE_LIMIT ]]
if [[ "$CANDIDATES" -lt $DELETE_LIMIT ]]
then
die 0 "Safety-net Insufficient images ($COUNT) to process deletions ($DELETE_LIMIT required)"
die 0 "Safety-net Insufficient images ($CANDIDATES) to process deletions ($DELETE_LIMIT required)"
fi

sort --random-sort $TODELETE | tail -$DELETE_LIMIT | \
Expand Down

0 comments on commit f67769a

Please sign in to comment.