fix(gitea_runner): address review of the prune count and threshold

Give each new input its own assert message so every refused-input case
matches only its own input, and cover a negative count and a bad disk
check schedule. Fire the pressure prune only above the threshold, as
the inputs describe it. Name the disk check script apart from the
pressure service, prefix the new registers as internal, and keep the
new comments short.

Refs #319

Assisted-by: Claude Code
This commit is contained in:
Defame1297 committed 2026-11-23 18:20:32 +00:00
1 parent f50ecc2945
commit e91c074373
10 files changed
+86 -63

No files matched your search

+24 -18
View File
@@ -116,7 +116,7 @@
- gitea_runner_test_pressure_timer.status.ActiveState == 'active'
- gitea_runner_test_pressure_timer.status.UnitFileState == 'enabled'
- "'ExecCondition=/usr/local/sbin/gitea-runner-docker-prune-gate 3600' in gitea_runner_test_pressure_text"
- "'ExecCondition=/usr/local/sbin/gitea-runner-docker-prune-pressure 90' in gitea_runner_test_pressure_text"
- "'ExecCondition=/usr/local/sbin/gitea-runner-docker-prune-disk-check 90' in gitea_runner_test_pressure_text"
- "'ExecStart=-/usr/local/sbin/gitea-runner-docker-prune-keep 2' in gitea_runner_test_pressure_text"
- "'ExecStart=-/usr/bin/docker builder prune --force --keep-storage 10GB' in gitea_runner_test_pressure_text"
quiet: true
@@ -195,14 +195,10 @@
loop_control:
loop_var: gitea_runner_test_path
# The count prune and the disk check against a stub docker CLI. The stub answers `image ls`,
# `ps` and `container inspect` from the files below, `info` with the root named in a file, and
# records every `rmi` call; a fail-<command> file makes that command fail. With N = 2:
# - app: a1 (two tags, newest) and a2 stay, a3 and a5 go, a4 stays because container c1 uses it;
# a1 counted twice would push a2 out;
# - lib keeps m1, so it stays although it is the third newest of old, which keeps o1 and o2;
# - stale: s3 goes with --force (two tags);
# - dangling: d1 goes, d2 stays because container c2 uses it.
# The count prune and the disk check against a stub docker CLI: it answers from the files below,
# records `rmi` calls, and a fail-<command> file makes that command fail. With N = 2, app keeps
# a1 (two tags: counted twice it would push a2 out), a2 and a4 (used by c1); lib keeps m1 though
# it is third in old; s3 (two tags) goes with --force; d1 goes, d2 (used by c2) stays.
- name: Verify the count prune and the disk check
hosts: all
gather_facts: false
@@ -315,19 +311,23 @@
loop_control:
label: "{{ item.gitea_runner_test_case.name }}"
# Any used root filesystem is at least 1% full (df rounds up), and a tmpfs holding a few lock
# files is far from 50%, so both cases hold on any host.
# The above case sets the threshold one below the root's use, read just before (df rounds up,
# so a used root is at least 1%); a tmpfs holding a few lock files is never above 50%.
- name: Run each disk check case
ansible.builtin.shell:
cmd: |
cd {{ gitea_runner_test_dir }} && rm -f fail-*
{{ ('touch fail-' ~ gitea_runner_test_case.fail) if gitea_runner_test_case.fail else ':' }}
echo '{{ gitea_runner_test_case.root }}' > root
/usr/local/sbin/gitea-runner-docker-prune-pressure {{ gitea_runner_test_case.threshold }}
threshold={{ gitea_runner_test_case.threshold }}
if [ "$threshold" = below-use ]; then
df -P / > df-root && threshold=$(($(awk 'NR == 2 { sub(/%$/, "", $5); print $5 }' df-root) - 1))
fi
/usr/local/sbin/gitea-runner-docker-prune-disk-check "$threshold"
loop:
- {name: above, root: /, threshold: 1, fail: "", rc: 0}
- {name: above, root: /, threshold: below-use, fail: "", rc: 0}
- {name: below, root: /run/lock, threshold: 50, fail: "", rc: 1}
- {name: info-fails, root: /, threshold: 1, fail: info, rc: 1}
- {name: info-fails, root: /, threshold: below-use, fail: info, rc: 1}
- {name: root-missing, root: /nonexistent, threshold: 1, fail: "", rc: 1}
loop_control:
loop_var: gitea_runner_test_case
@@ -424,12 +424,18 @@
- name: prune age without a unit
vars: {gitea_runner_docker_prune_image_age: "168"}
expect: plain OnCalendar value
- name: negative prune count
vars: {gitea_runner_docker_prune_keep_per_repository: -1}
expect: gitea_runner_docker_prune_keep_per_repository must be 0 (off) or more
- name: disk threshold of 100
vars: {gitea_runner_docker_prune_disk_threshold_percent: 100}
expect: 0 (off) or 1 to 99
expect: gitea_runner_docker_prune_disk_threshold_percent must be 0 (off) or 1 to 99
- name: disk check schedule with a newline
vars: {gitea_runner_docker_prune_disk_check_schedule: "hourly\nExecStartPre=/bin/false"}
expect: gitea_runner_docker_prune_disk_check_schedule must be a plain OnCalendar value
- name: builder keep-storage with an extra argument
vars: {gitea_runner_docker_prune_builder_keep_storage: "10GB --all"}
expect: 0 (off) or 1 to 99
expect: gitea_runner_docker_prune_builder_keep_storage must be a number
- name: disk threshold without a count
vars: {gitea_runner_docker_prune_keep_per_repository: 0}
expect: needs gitea_runner_docker_prune_keep_per_repository above 0
@@ -561,7 +567,7 @@
loop:
- /etc/systemd/system/gitea-runner-docker-prune-pressure.service
- /etc/systemd/system/gitea-runner-docker-prune-pressure.timer
- /usr/local/sbin/gitea-runner-docker-prune-pressure
- /usr/local/sbin/gitea-runner-docker-prune-disk-check
loop_control:
loop_var: gitea_runner_test_path
register: gitea_runner_test_pressure_off
@@ -622,7 +628,7 @@
- /etc/systemd/system/gitea-runner-docker-prune-pressure.service
- /etc/systemd/system/gitea-runner-docker-prune-pressure.timer
- /usr/local/sbin/gitea-runner-docker-prune-keep
- /usr/local/sbin/gitea-runner-docker-prune-pressure
- /usr/local/sbin/gitea-runner-docker-prune-disk-check
- /etc/systemd/system/multi-user.target.wants/gitea-runner.service
loop_control:
loop_var: gitea_runner_test_path