diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 17:34:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 17:34:42 +0300 |
commit | 9f46488805e86b1bc341ea1620b866016c2ce5ed (patch) | |
tree | f9748c7e287041e37d6da49e0a29c9511dc34768 /scripts/review_apps | |
parent | dfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff) |
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
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 | 9 | ||||
-rwxr-xr-x | scripts/review_apps/review-apps.sh | 46 |
3 files changed, 20 insertions, 56 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..f289a50f629 100755 --- a/scripts/review_apps/gcp_cleanup.sh +++ b/scripts/review_apps/gcp_cleanup.sh @@ -1,7 +1,14 @@ -#!/bin/bash +#!/usr/bin/env bash 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..097fe9c8cca 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}" @@ -267,7 +236,6 @@ function base_config_changed() { function deploy() { local namespace="${KUBE_NAMESPACE}" local release="${CI_ENVIRONMENT_SLUG}" - local edition="${GITLAB_EDITION-ce}" local base_config_file_ref="master" if [[ "$(base_config_changed)" == "true" ]]; then base_config_file_ref="${CI_COMMIT_SHA}"; fi local base_config_file="https://gitlab.com/gitlab-org/gitlab/raw/${base_config_file_ref}/scripts/review_apps/base-config.yaml" @@ -275,13 +243,13 @@ function deploy() { echoinfo "Deploying ${release}..." true IMAGE_REPOSITORY="registry.gitlab.com/gitlab-org/build/cng-mirror" - gitlab_migrations_image_repository="${IMAGE_REPOSITORY}/gitlab-rails-${edition}" - gitlab_sidekiq_image_repository="${IMAGE_REPOSITORY}/gitlab-sidekiq-${edition}" - gitlab_unicorn_image_repository="${IMAGE_REPOSITORY}/gitlab-webservice-${edition}" - gitlab_task_runner_image_repository="${IMAGE_REPOSITORY}/gitlab-task-runner-${edition}" + gitlab_migrations_image_repository="${IMAGE_REPOSITORY}/gitlab-rails-ee" + gitlab_sidekiq_image_repository="${IMAGE_REPOSITORY}/gitlab-sidekiq-ee" + gitlab_unicorn_image_repository="${IMAGE_REPOSITORY}/gitlab-webservice-ee" + gitlab_task_runner_image_repository="${IMAGE_REPOSITORY}/gitlab-task-runner-ee" gitlab_gitaly_image_repository="${IMAGE_REPOSITORY}/gitaly" gitlab_shell_image_repository="${IMAGE_REPOSITORY}/gitlab-shell" - gitlab_workhorse_image_repository="${IMAGE_REPOSITORY}/gitlab-workhorse-${edition}" + gitlab_workhorse_image_repository="${IMAGE_REPOSITORY}/gitlab-workhorse-ee" create_application_secret @@ -290,7 +258,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}" \ @@ -304,8 +272,10 @@ HELM_CMD=$(cat << EOF --set gitlab.gitaly.image.tag="v${GITALY_VERSION}" \ --set gitlab.gitlab-shell.image.repository="${gitlab_shell_image_repository}" \ --set gitlab.gitlab-shell.image.tag="v${GITLAB_SHELL_VERSION}" \ + --set gitlab.sidekiq.annotations.commit="${CI_COMMIT_SHORT_SHA}" \ --set gitlab.sidekiq.image.repository="${gitlab_sidekiq_image_repository}" \ --set gitlab.sidekiq.image.tag="${CI_COMMIT_REF_SLUG}" \ + --set gitlab.unicorn.annotations.commit="${CI_COMMIT_SHORT_SHA}" \ --set gitlab.unicorn.image.repository="${gitlab_unicorn_image_repository}" \ --set gitlab.unicorn.image.tag="${CI_COMMIT_REF_SLUG}" \ --set gitlab.unicorn.workhorse.image="${gitlab_workhorse_image_repository}" \ |