summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-09 12:09:24 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-09 12:09:24 +0000
commita9ced7da447785c57477b3d8dbccc73a78cface1 (patch)
tree5179d27ab9d801748ee4ed1c64c985974e799812 /scripts
parentad0265eead72a624ce7a020847db4f0f0c877e57 (diff)
downloadgitlab-ce-a9ced7da447785c57477b3d8dbccc73a78cface1.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/review_apps/automated_cleanup.rb25
1 files changed, 18 insertions, 7 deletions
diff --git a/scripts/review_apps/automated_cleanup.rb b/scripts/review_apps/automated_cleanup.rb
index 0a073a28bf3..e3ed7143ea2 100755
--- a/scripts/review_apps/automated_cleanup.rb
+++ b/scripts/review_apps/automated_cleanup.rb
@@ -2,6 +2,7 @@
require 'gitlab'
require_relative File.expand_path('../../lib/quality/helm_client.rb', __dir__)
+require_relative File.expand_path('../../lib/quality/helm3_client.rb', __dir__)
require_relative File.expand_path('../../lib/quality/kubernetes_client.rb', __dir__)
class AutomatedCleanup
@@ -11,7 +12,8 @@ class AutomatedCleanup
HELM_RELEASES_BATCH_SIZE = 5
IGNORED_HELM_ERRORS = [
'transport is closing',
- 'error upgrading connection'
+ 'error upgrading connection',
+ 'not found'
].freeze
IGNORED_KUBERNETES_ERRORS = [
'NotFound'
@@ -43,8 +45,16 @@ class AutomatedCleanup
self.class.ee? ? 'review-apps-ee' : 'review-apps-ce'
end
+ def helm3?
+ !ENV['HELM_3'].nil?
+ end
+
+ def helm_client_class
+ helm3? ? Quality::Helm3Client : Quality::HelmClient
+ end
+
def helm
- @helm ||= Quality::HelmClient.new(
+ @helm ||= helm_client_class.new(
tiller_namespace: review_apps_namespace,
namespace: review_apps_namespace)
end
@@ -78,7 +88,7 @@ class AutomatedCleanup
if deployed_at < delete_threshold
deleted_environment = delete_environment(environment, deployment)
if deleted_environment
- release = Quality::HelmClient::Release.new(environment.slug, 1, deployed_at.to_s, nil, nil, review_apps_namespace)
+ release = helm_client_class::Release.new(environment.slug, 1, deployed_at.to_s, nil, nil, review_apps_namespace)
releases_to_delete << release
end
else
@@ -97,7 +107,7 @@ class AutomatedCleanup
end
def perform_helm_releases_cleanup!(days:)
- puts "Checking for Helm releases that are FAILED or not updated in the last #{days} days..."
+ puts "Checking for Helm releases that are failed or not updated in the last #{days} days..."
threshold = threshold_time(days: days)
@@ -107,7 +117,7 @@ class AutomatedCleanup
# 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
+ if release.status.casecmp('failed') == 0 || release.last_update < threshold
releases_to_delete << release
else
print_release_state(subject: 'Release', release_name: release.name, release_date: release.last_update, action: 'leaving')
@@ -143,7 +153,8 @@ class AutomatedCleanup
end
def helm_releases
- args = ['--all', '--date', "--max #{HELM_RELEASES_BATCH_SIZE}"]
+ args = ['--all', '--date']
+ args << "--max #{HELM_RELEASES_BATCH_SIZE}" unless helm3?
helm.releases(args: args)
end
@@ -159,7 +170,7 @@ class AutomatedCleanup
helm.delete(release_name: releases_names)
kubernetes.cleanup(release_name: releases_names, wait: false)
- rescue Quality::HelmClient::CommandFailedError => ex
+ rescue helm_client_class::CommandFailedError => ex
raise ex unless ignore_exception?(ex.message, IGNORED_HELM_ERRORS)
puts "Ignoring the following Helm error:\n#{ex}\n"