Commit 7c211cc7 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Merge branch '34753-improve-the-scripts-review_apps-automated_cleanup-rb-script' into 'master'

Improve the scripts/review_apps/automated_cleanup.rb script

Closes #34753

See merge request gitlab-org/gitlab!18992
parents 845a43c3 f1d048a5
...@@ -35,14 +35,12 @@ build-qa-image: ...@@ -35,14 +35,12 @@ build-qa-image:
- echo "${CI_JOB_TOKEN}" | docker login --username gitlab-ci-token --password-stdin ${CI_REGISTRY} - echo "${CI_JOB_TOKEN}" | docker login --username gitlab-ci-token --password-stdin ${CI_REGISTRY}
- time docker push ${QA_IMAGE} - time docker push ${QA_IMAGE}
schedule:review-cleanup: .base-review-cleanup:
extends: extends:
- .default-tags - .default-tags
- .default-retry - .default-retry
- .default-only - .default-only
- .only-code-qa-changes - .only-code-qa-changes
- .only-review-schedules
- .except-deploys
stage: prepare stage: prepare
image: registry.gitlab.com/gitlab-org/gitlab-build-images:gitlab-charts-build-base image: registry.gitlab.com/gitlab-org/gitlab-build-images:gitlab-charts-build-base
allow_failure: true allow_failure: true
...@@ -55,6 +53,16 @@ schedule:review-cleanup: ...@@ -55,6 +53,16 @@ schedule:review-cleanup:
script: script:
- ruby -rrubygems scripts/review_apps/automated_cleanup.rb - ruby -rrubygems scripts/review_apps/automated_cleanup.rb
schedule:review-cleanup:
extends:
- .base-review-cleanup
- .only-review-schedules
manual:review-cleanup:
extends:
- .base-review-cleanup
when: manual
.review-build-cng-base: .review-build-cng-base:
extends: extends:
- .default-only - .default-only
......
...@@ -58,8 +58,11 @@ class AutomatedCleanup ...@@ -58,8 +58,11 @@ class AutomatedCleanup
checked_environments = [] checked_environments = []
delete_threshold = threshold_time(days: days_for_delete) delete_threshold = threshold_time(days: days_for_delete)
stop_threshold = threshold_time(days: days_for_stop) stop_threshold = threshold_time(days: days_for_stop)
deployments_look_back_threshold = threshold_time(days: days_for_delete * 5)
gitlab.deployments(project_path, per_page: DEPLOYMENTS_PER_PAGE, sort: 'desc').auto_paginate do |deployment|
break if Time.parse(deployment.created_at) < deployments_look_back_threshold
gitlab.deployments(project_path, per_page: DEPLOYMENTS_PER_PAGE).auto_paginate do |deployment|
environment = deployment.environment environment = deployment.environment
next unless environment next unless environment
...@@ -89,6 +92,9 @@ class AutomatedCleanup ...@@ -89,6 +92,9 @@ class AutomatedCleanup
threshold_day = threshold_time(days: days) threshold_day = threshold_time(days: days)
helm_releases.each do |release| helm_releases.each do |release|
# Prevents deleting `dns-gitlab-review-app` releases or other unrelated releases
next unless release.name.start_with?('review-')
if release.status == 'FAILED' || release.last_update < threshold_day if release.status == 'FAILED' || release.last_update < threshold_day
delete_helm_release(release) delete_helm_release(release)
else else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment