Commit f4d32264 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '36933-failed-scheduled-review-clean-up-job-with-403-on-gitlab-api' into 'master'

Skip restricted environments when deleting or stopping

Closes #36933

See merge request gitlab-org/gitlab!20518
parents 94969ce1 96195d4f
...@@ -75,9 +75,11 @@ class AutomatedCleanup ...@@ -75,9 +75,11 @@ class AutomatedCleanup
deployed_at = Time.parse(last_deploy) deployed_at = Time.parse(last_deploy)
if deployed_at < delete_threshold if deployed_at < delete_threshold
delete_environment(environment, deployment) environment = delete_environment(environment, deployment)
release = Quality::HelmClient::Release.new(environment.slug, 1, deployed_at.to_s, nil, nil, review_apps_namespace) if environment
releases_to_delete << release release = Quality::HelmClient::Release.new(environment.slug, 1, deployed_at.to_s, nil, nil, review_apps_namespace)
releases_to_delete << release
end
elsif deployed_at < stop_threshold elsif deployed_at < stop_threshold
stop_environment(environment, deployment) stop_environment(environment, deployment)
else else
...@@ -116,11 +118,17 @@ class AutomatedCleanup ...@@ -116,11 +118,17 @@ class AutomatedCleanup
def delete_environment(environment, deployment) def delete_environment(environment, deployment)
print_release_state(subject: 'Review app', release_name: environment.slug, release_date: deployment.created_at, action: 'deleting') print_release_state(subject: 'Review app', release_name: environment.slug, release_date: deployment.created_at, action: 'deleting')
gitlab.delete_environment(project_path, environment.id) gitlab.delete_environment(project_path, environment.id)
rescue Gitlab::Error::Forbidden
puts "Review app '#{environment.slug}' is forbidden: skipping it"
end end
def stop_environment(environment, deployment) def stop_environment(environment, deployment)
print_release_state(subject: 'Review app', release_name: environment.slug, release_date: deployment.created_at, action: 'stopping') print_release_state(subject: 'Review app', release_name: environment.slug, release_date: deployment.created_at, action: 'stopping')
gitlab.stop_environment(project_path, environment.id) gitlab.stop_environment(project_path, environment.id)
rescue Gitlab::Error::Forbidden
puts "Review app '#{environment.slug}' is forbidden: skipping it"
end end
def helm_releases def helm_releases
......
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