diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-21 21:09:31 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-21 21:09:31 +0300 |
commit | f1d9023a9049ed7defec5566063b7f704c26dfd6 (patch) | |
tree | 0e7ea3a1e0d07c4b69baf361e99bad4fc1e16bc9 /scripts/review_apps | |
parent | e33f87ac0fabaab468ce4b457996cc0f1b1bb648 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'scripts/review_apps')
-rwxr-xr-x | scripts/review_apps/automated_cleanup.rb | 21 | ||||
-rwxr-xr-x | scripts/review_apps/gcp_cleanup.sh | 7 | ||||
-rwxr-xr-x | scripts/review_apps/review-apps.sh | 33 |
3 files changed, 12 insertions, 49 deletions
diff --git a/scripts/review_apps/automated_cleanup.rb b/scripts/review_apps/automated_cleanup.rb index e3ed7143ea2..a9659071a2f 100755 --- a/scripts/review_apps/automated_cleanup.rb +++ b/scripts/review_apps/automated_cleanup.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true 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__) @@ -9,7 +8,6 @@ class AutomatedCleanup attr_reader :project_path, :gitlab_token DEPLOYMENTS_PER_PAGE = 100 - HELM_RELEASES_BATCH_SIZE = 5 IGNORED_HELM_ERRORS = [ 'transport is closing', 'error upgrading connection', @@ -45,18 +43,8 @@ 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 ||= helm_client_class.new( - tiller_namespace: review_apps_namespace, - namespace: review_apps_namespace) + @helm ||= Quality::Helm3Client.new(namespace: review_apps_namespace) end def kubernetes @@ -88,7 +76,7 @@ class AutomatedCleanup if deployed_at < delete_threshold deleted_environment = delete_environment(environment, deployment) if deleted_environment - release = helm_client_class::Release.new(environment.slug, 1, deployed_at.to_s, nil, nil, review_apps_namespace) + release = Quality::Helm3Client::Release.new(environment.slug, 1, deployed_at.to_s, nil, nil, review_apps_namespace) releases_to_delete << release end else @@ -117,7 +105,7 @@ class AutomatedCleanup # Prevents deleting `dns-gitlab-review-app` releases or other unrelated releases next unless release.name.start_with?('review-') - if release.status.casecmp('failed') == 0 || release.last_update < threshold + if release.status == 'failed' || 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') @@ -154,7 +142,6 @@ class AutomatedCleanup def helm_releases args = ['--all', '--date'] - args << "--max #{HELM_RELEASES_BATCH_SIZE}" unless helm3? helm.releases(args: args) end @@ -170,7 +157,7 @@ class AutomatedCleanup helm.delete(release_name: releases_names) kubernetes.cleanup(release_name: releases_names, wait: false) - rescue helm_client_class::CommandFailedError => ex + rescue Quality::Helm3Client::CommandFailedError => ex raise ex unless ignore_exception?(ex.message, IGNORED_HELM_ERRORS) puts "Ignoring the following Helm error:\n#{ex}\n" diff --git a/scripts/review_apps/gcp_cleanup.sh b/scripts/review_apps/gcp_cleanup.sh index ea6b60ed5ff..efdde05a194 100755 --- a/scripts/review_apps/gcp_cleanup.sh +++ b/scripts/review_apps/gcp_cleanup.sh @@ -2,6 +2,13 @@ source scripts/utils.sh +function setup_gcp_dependencies() { + apk add jq + + gcloud auth activate-service-account --key-file="${REVIEW_APPS_GCP_CREDENTIALS}" + gcloud config set project "${REVIEW_APPS_GCP_PROJECT}" +} + # These scripts require the following environment variables: # - REVIEW_APPS_GCP_REGION - e.g `us-central1` # - KUBE_NAMESPACE - e.g `review-apps-ee` diff --git a/scripts/review_apps/review-apps.sh b/scripts/review_apps/review-apps.sh index 915b4f5050b..c514b89e899 100755 --- a/scripts/review_apps/review-apps.sh +++ b/scripts/review_apps/review-apps.sh @@ -95,37 +95,6 @@ function delete_failed_release() { fi } -function helm2_deploy_exists() { - local namespace="${1}" - local release="${2}" - local deploy_exists - - echoinfo "Checking if Helm 2 ${release} exists in the ${namespace} namespace..." true - - kubectl get cm -l OWNER=TILLER -n ${namespace} | grep ${release} 2>&1 - deploy_exists=$? - - echoinfo "Helm 2 release for ${release} is ${deploy_exists}" - return $deploy_exists -} - -function delete_helm2_release() { - local namespace="${KUBE_NAMESPACE}" - local release="${CI_ENVIRONMENT_SLUG}" - - if [ -z "${release}" ]; then - echoerr "No release given, aborting the delete!" - return - fi - - if ! helm2_deploy_exists "${namespace}" "${release}"; then - echoinfo "No Review App with ${release} is currently deployed by Helm 2." - else - echoinfo "Cleaning up ${release} installed by Helm 2" - kubectl_cleanup_release "${namespace}" "${release}" - fi -} - function get_pod() { local namespace="${KUBE_NAMESPACE}" local release="${CI_ENVIRONMENT_SLUG}" @@ -290,7 +259,7 @@ HELM_CMD=$(cat << EOF --namespace="${namespace}" \ --install \ --wait \ - --timeout 900s \ + --timeout 15m \ --set ci.branch="${CI_COMMIT_REF_NAME}" \ --set ci.commit.sha="${CI_COMMIT_SHORT_SHA}" \ --set ci.job.url="${CI_JOB_URL}" \ |