This is somewhat similar to How to check if the latest Cloud Run revision is ready to serve
I would like to list non-active revisions of my Cloud Run service so that I can delete them. I can list them using:
gcloud run revisions list --region europe-west1 --service service-name
The listing looks like:
REVISION ACTIVE SERVICE DEPLOYED DEPLOYED BY
✔ xxxxx-server-00083-ban yes xxxxx-server 2022-12-22 18:13:50 UTC xxxxx-server@***.iam.gserviceaccount.com
✔ xxxxx-server-00082-few xxxxx-server 2022-12-22 18:09:27 UTC xxxxx-server@***.iam.gserviceaccount.com
✔ xxxxx-server-00081-zex xxxxx-server 2022-12-22 18:03:00 UTC xxxxx-server@***.iam.gserviceaccount.com
✔ xxxxx-server-00080-bad xxxxx-server 2022-12-22 18:02:02 UTC xxxxx-server@***.iam.gserviceaccount.com
Now I would like to filter only those which do not have ACTIVE:yes
. I have tried adding --filter='-active:*'
, but it does not seem to have any effect and I am given an warning:
WARNING: The following filter keys were not present in any resource : active
When I try listing the information with --format=JSON
or --format=YAML
, I am overwhelmed with information, which includes listing all past status transitions like:
status:
conditions:
- lastTransitionTime: '2022-12-22T18:14:04.208603Z'
status: 'True'
type: Ready
- lastTransitionTime: '2022-12-22T18:24:23.335439Z'
reason: Reserve
severity: Info
status: Unknown
type: Active
I have no idea if / how I can filter based on this.
How can I list only non-active Cloud Run revisions of my service?
You can use this command to do that :)
# Get non running revisions
gcloud run revisions list \
--filter="status.conditions.type:Active AND status.conditions.status:'False'" \
--format='value(metadata.name)'
And here u can delete them all at once :)
REVS=`gcloud run revisions list --filter="status.conditions.type:Active AND status.conditions.status:'False'" --format='value(metadata.name)'`
for rev in `echo $REVS`; do
echo $rev
gcloud run revisions delete $rev --quiet &
done