Skip to content

Commit 816178f

Browse files
committed
fix: handle date format for e2e cleanup
1 parent ae0bdba commit 816178f

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

hack/clean-e2e-images.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ if [[ -n "${QUAY_E2E_USERNAME:-}" && -n "${QUAY_E2E_PASSWORD:-}" ]]; then
2121
fi
2222

2323
# Calculate cutoff timestamp
24-
cutoff=$(date -u -v-${MAX_AGE_DAYS}d +%s 2>/dev/null || date -u -d "${MAX_AGE_DAYS} days ago" +%s)
24+
cutoff=$(date -u -v-"${MAX_AGE_DAYS}"d +%s 2>/dev/null || date -u -d "${MAX_AGE_DAYS} days ago" +%s)
2525

2626
if [[ "${DRY_RUN}" == "true" ]]; then
2727
echo "DRY RUN: will list tags without deleting them"
@@ -38,17 +38,18 @@ fi
3838

3939
deleted=0
4040
while IFS= read -r name; do
41-
# Get the image creation timestamp (RFC3339 format)
42-
created=$(regctl image config "${REPO}:${name}" --format '{{.Created}}' 2>/dev/null || true)
41+
# Get the image creation timestamp in RFC3339 format using jsonPretty to ensure quotes and T/Z separators
42+
created=$(regctl image config "${REPO}:${name}" --format '{{jsonPretty .Created}}' 2>/dev/null | sed 's/^"//;s/"$//' || true)
4343

4444
if [[ -z "${created}" ]]; then
4545
echo "Warning: could not get creation time for tag ${name}, skipping"
4646
continue
4747
fi
4848

49-
# Convert RFC3339 to epoch (strip fractional seconds and Z suffix for macOS compatibility)
50-
stripped=$(echo "${created}" | sed 's/\.[0-9]*Z$//' | sed 's/Z$//')
51-
created_ts=$(date -u -jf "%Y-%m-%dT%H:%M:%S" "${stripped}" +%s 2>/dev/null \
49+
# Convert to a format that date can parse (handle both RFC3339 and 'YYYY-MM-DD HH:MM:SS...' formats)
50+
normalized=$(echo "${created}" | sed 's/ /T/' | sed 's/ UTC$//')
51+
created_ts=$(date -u -jf "%Y-%m-%dT%H:%M:%S" "${normalized%.*}" +%s 2>/dev/null \
52+
|| date -u -d "${normalized}" +%s 2>/dev/null \
5253
|| date -u -d "${created}" +%s 2>/dev/null \
5354
|| true)
5455

0 commit comments

Comments
 (0)