To clean old agents, the following commands can be executed on the database (Postgres example)
delete from agents where capacity=-1;
delete from agents where coalesce(name, '') = '';
This will clean a lot stale agents but not all.
Another way is to clean all agents for which the last contact is older than 1 day (thanks @zc-devs), one can do
delete from agents where last_contact < now() - interval '1 day';
Alternatively, one can remove all agents, then recreate the pod and the attached PV. This will reinitialize a fresh agent with a new ID.
I've tested this PR and recreated the agents (two replicas) many times. No new agents were created and /etc/woodpecker/agent.conf always showed the persistet agent ID.
To persist
/etc/woodpecker/agent.conf
and solve https://github.com/woodpecker-ci/woodpecker/issues/3023To clean old agents, the following commands can be executed on the database (Postgres example)
This will clean a lot stale agents but not all.
Another way is to clean all agents for which the last contact is older than 1 day (thanks @zc-devs), one can do
Alternatively, one can remove all agents, then recreate the pod and the attached PV. This will reinitialize a fresh agent with a new ID.
I've tested this PR and recreated the agents (two replicas) many times. No new agents were created and
/etc/woodpecker/agent.conf
always showed the persistet agent ID.