Resolve "Provide a mechanism to clean up stale environments"
What does this MR do and why?
Add an API endpoint for a project to stop all environments that have been modified before a specified date.
Screenshots or screen recordings
http://gdk.test:3000/api/v4/projects/8/environments/stop_all/10%2F10%2F2020
[
{
"id": 9,
"name": "staging",
"slug": "staging",
"external_url": null,
"created_at": "2022-06-08T15:17:13.981Z",
"updated_at": "2022-12-07T15:28:33.046Z"
},
{
"id": 10,
"name": "production",
"slug": "production",
"external_url": null,
"created_at": "2022-06-08T15:17:13.997Z",
"updated_at": "2022-12-07T15:28:33.139Z"
},
...
SQL Query
SELECT "environments".id FROM "environments" LEFT JOIN "deployments" on "deployments"."environment_id" = "environments".id AND "deployments"."project_id" = 278964 AND deployments.updated_at >= '01-01-2023' WHERE "environments"."project_id" = 278964 AND "environments"."updated_at" < '01-01-2023' AND "environments"."name" != 'protected_prod' AND "environments"."tier" != 0 GROUP BY environments.id, deployments.id HAVING deployments.id IS NULL
https://postgres.ai/console/gitlab/gitlab-production-tunnel-pg12/sessions/13979/commands/48918
How to set up and validate locally
- POST to the
/api/v4/projects/<PROJECT_ID/environments/stop_all/<DATE>
endpoint with an appropriate date - All applicable environments should be returned
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #19724 (closed)
Edited by Allen Cook