summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-10 15:08:08 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-10 15:08:08 +0000
commit7c38405be9e79099f399aa429503ea7b463bbf5a (patch)
tree30944a8baf135021395574e081f53ed5f756ace0 /scripts
parent1fa79760ad2d4bd67f5c5a27f372a7533b9b7c69 (diff)
downloadgitlab-ce-7c38405be9e79099f399aa429503ea7b463bbf5a.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/review_apps/automated_cleanup.rb20
1 files changed, 15 insertions, 5 deletions
diff --git a/scripts/review_apps/automated_cleanup.rb b/scripts/review_apps/automated_cleanup.rb
index 93412b658f6..0a073a28bf3 100755
--- a/scripts/review_apps/automated_cleanup.rb
+++ b/scripts/review_apps/automated_cleanup.rb
@@ -81,10 +81,13 @@ class AutomatedCleanup
release = Quality::HelmClient::Release.new(environment.slug, 1, deployed_at.to_s, nil, nil, review_apps_namespace)
releases_to_delete << release
end
- elsif environment.state != 'stopped' && deployed_at < stop_threshold
- stop_environment(environment, deployment)
else
- print_release_state(subject: 'Review App', release_name: environment.slug, release_date: last_deploy, action: 'leaving')
+ if deployed_at >= stop_threshold
+ print_release_state(subject: 'Review App', release_name: environment.slug, release_date: last_deploy, action: 'leaving')
+ else
+ environment_state = fetch_environment(environment)&.state
+ stop_environment(environment, deployment) if environment_state && environment_state != 'stopped'
+ end
end
checked_environments << environment.slug
@@ -116,12 +119,19 @@ class AutomatedCleanup
private
+ def fetch_environment(environment)
+ gitlab.environment(project_path, environment.id)
+ rescue Errno::ETIMEDOUT => ex
+ puts "Failed to fetch '#{environment.name}' / '#{environment.slug}' (##{environment.id}):\n#{ex.message}"
+ nil
+ end
+
def delete_environment(environment, deployment)
print_release_state(subject: 'Review app', release_name: environment.slug, release_date: deployment.created_at, action: 'deleting')
gitlab.delete_environment(project_path, environment.id)
rescue Gitlab::Error::Forbidden
- puts "Review app '#{environment.slug}' is forbidden: skipping it"
+ puts "Review app '#{environment.name}' / '#{environment.slug}' (##{environment.id}) is forbidden: skipping it"
end
def stop_environment(environment, deployment)
@@ -129,7 +139,7 @@ class AutomatedCleanup
gitlab.stop_environment(project_path, environment.id)
rescue Gitlab::Error::Forbidden
- puts "Review app '#{environment.slug}' is forbidden: skipping it"
+ puts "Review app '#{environment.name}' / '#{environment.slug}' (##{environment.id}) is forbidden: skipping it"
end
def helm_releases