diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-26 12:11:15 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-26 12:11:15 +0300 |
commit | c8a7e4ada117b968f841c2bb300fadc421cb3e98 (patch) | |
tree | c7c84dd22cd56ea8ed228f91f4ab33c5a1e751fc /scripts/review_apps | |
parent | b692f9afa047ef24c54ab185b499628d9873122a (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'scripts/review_apps')
-rwxr-xr-x | scripts/review_apps/automated_cleanup.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/scripts/review_apps/automated_cleanup.rb b/scripts/review_apps/automated_cleanup.rb index 5707f02d3f0..aaa35cfc886 100755 --- a/scripts/review_apps/automated_cleanup.rb +++ b/scripts/review_apps/automated_cleanup.rb @@ -95,6 +95,40 @@ class AutomatedCleanup delete_helm_releases(releases_to_delete) end + def perform_gitlab_docs_environment_cleanup!(days_for_stop:, days_for_delete:) + puts "Checking for Docs Review Apps not updated in the last #{days_for_stop} days..." + + checked_environments = [] + stop_threshold = threshold_time(days: days_for_stop) + delete_threshold = threshold_time(days: days_for_delete) + + max_delete_count = 1000 + delete_count = 0 + + gitlab.deployments(project_path, per_page: DEPLOYMENTS_PER_PAGE, sort: 'desc').auto_paginate do |deployment| + environment = deployment.environment + + next unless environment + next unless environment.name.start_with?('review-docs/') + next if checked_environments.include?(environment.slug) + + last_deploy = deployment.created_at + deployed_at = Time.parse(last_deploy) + + if deployed_at < delete_threshold + delete_environment(environment, deployment) + delete_count += 1 + + break if delete_count > max_delete_count + elsif deployed_at < stop_threshold + environment_state = fetch_environment(environment)&.state + stop_environment(environment, deployment) if environment_state && environment_state != 'stopped' + end + + checked_environments << environment.slug + end + end + def perform_helm_releases_cleanup!(days:) puts "Checking for Helm releases that are failed or not updated in the last #{days} days..." @@ -203,6 +237,10 @@ timed('Review Apps cleanup') do automated_cleanup.perform_gitlab_environment_cleanup!(days_for_stop: 5, days_for_delete: 6) end +timed('Docs Review Apps cleanup') do + automated_cleanup.perform_gitlab_docs_environment_cleanup!(days_for_stop: 20, days_for_delete: 30) +end + puts timed('Helm releases cleanup') do |