summaryrefslogtreecommitdiff
path: root/lib/quality
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 12:26:25 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 12:26:25 +0000
commita09983ae35713f5a2bbb100981116d31ce99826e (patch)
tree2ee2af7bd104d57086db360a7e6d8c9d5d43667a /lib/quality
parent18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff)
downloadgitlab-ce-a09983ae35713f5a2bbb100981116d31ce99826e.tar.gz
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'lib/quality')
-rw-r--r--lib/quality/helm3_client.rb109
-rw-r--r--lib/quality/kubernetes_client.rb85
-rw-r--r--lib/quality/seeders/issues.rb1
-rw-r--r--lib/quality/test_level.rb8
4 files changed, 9 insertions, 194 deletions
diff --git a/lib/quality/helm3_client.rb b/lib/quality/helm3_client.rb
deleted file mode 100644
index afea73cbc50..00000000000
--- a/lib/quality/helm3_client.rb
+++ /dev/null
@@ -1,109 +0,0 @@
-# frozen_string_literal: true
-
-require 'time'
-require_relative '../gitlab/popen' unless defined?(Gitlab::Popen)
-
-module Quality
- class Helm3Client
- CommandFailedError = Class.new(StandardError)
-
- attr_reader :namespace
-
- RELEASE_JSON_ATTRIBUTES = %w[name revision updated status chart app_version namespace].freeze
- PAGINATION_SIZE = 256 # Default helm list pagination size
-
- Release = Struct.new(:name, :revision, :last_update, :status, :chart, :app_version, :namespace) do
- def revision
- @revision ||= self[:revision].to_i
- end
-
- def last_update
- @last_update ||= Time.parse(self[:last_update])
- end
- end
-
- # A single page of data and the corresponding page number.
- Page = Struct.new(:releases, :number)
-
- def initialize(namespace:)
- @namespace = namespace
- end
-
- def releases(args: [])
- each_release(args)
- end
-
- def delete(release_name:)
- run_command([
- 'uninstall',
- %(--namespace "#{namespace}"),
- release_name
- ])
- end
-
- private
-
- def run_command(command)
- final_command = ['helm', *command].join(' ')
- puts "Running command: `#{final_command}`" # rubocop:disable Rails/Output
-
- result = Gitlab::Popen.popen_with_detail([final_command])
-
- if result.status.success?
- result.stdout.chomp.freeze
- else
- raise CommandFailedError, "The `#{final_command}` command failed (status: #{result.status}) with the following error:\n#{result.stderr}"
- end
- end
-
- def raw_releases(page, args = [])
- command = [
- 'list',
- %(--namespace "#{namespace}"),
- %(--max #{PAGINATION_SIZE}),
- %(--offset #{PAGINATION_SIZE * page}),
- %(--output json),
- *args
- ]
- releases = JSON.parse(run_command(command))
-
- releases.map do |release|
- Release.new(*release.values_at(*RELEASE_JSON_ATTRIBUTES))
- end
- rescue JSON::ParserError => ex
- puts "Ignoring this JSON parsing error: #{ex}" # rubocop:disable Rails/Output
- []
- end
-
- # Fetches data from Helm and yields a Page object for every page
- # of data, without loading all of them into memory.
- #
- # method - The Octokit method to use for getting the data.
- # args - Arguments to pass to the `helm list` command.
- def each_releases_page(args, &block)
- return to_enum(__method__, args) unless block_given?
-
- page = 0
- final_args = args.dup
-
- begin
- collection = raw_releases(page, final_args)
-
- yield Page.new(collection, page += 1)
- end while collection.any?
- end
-
- # Iterates over all of the releases.
- #
- # args - Any arguments to pass to the `helm list` command.
- def each_release(args, &block)
- return to_enum(__method__, args) unless block_given?
-
- each_releases_page(args) do |page|
- page.releases.each do |release|
- yield release
- end
- end
- end
- end
-end
diff --git a/lib/quality/kubernetes_client.rb b/lib/quality/kubernetes_client.rb
deleted file mode 100644
index f83652e117f..00000000000
--- a/lib/quality/kubernetes_client.rb
+++ /dev/null
@@ -1,85 +0,0 @@
-# frozen_string_literal: true
-
-require_relative '../gitlab/popen' unless defined?(Gitlab::Popen)
-
-module Quality
- class KubernetesClient
- RESOURCE_LIST = 'ingress,svc,pdb,hpa,deploy,statefulset,job,pod,secret,configmap,pvc,secret,clusterrole,clusterrolebinding,role,rolebinding,sa,crd'
- CommandFailedError = Class.new(StandardError)
-
- attr_reader :namespace
-
- def initialize(namespace:)
- @namespace = namespace
- end
-
- def cleanup(release_name:, wait: true)
- delete_by_selector(release_name: release_name, wait: wait)
- delete_by_matching_name(release_name: release_name)
- end
-
- private
-
- def delete_by_selector(release_name:, wait:)
- selector = case release_name
- when String
- %(-l release="#{release_name}")
- when Array
- %(-l 'release in (#{release_name.join(', ')})')
- else
- raise ArgumentError, 'release_name must be a string or an array'
- end
-
- command = [
- 'delete',
- RESOURCE_LIST,
- %(--namespace "#{namespace}"),
- '--now',
- '--ignore-not-found',
- '--include-uninitialized',
- %(--wait=#{wait}),
- selector
- ]
-
- run_command(command)
- end
-
- def delete_by_matching_name(release_name:)
- resource_names = raw_resource_names
- command = [
- 'delete',
- %(--namespace "#{namespace}"),
- '--ignore-not-found'
- ]
-
- Array(release_name).each do |release|
- resource_names
- .select { |resource_name| resource_name.include?(release) }
- .each { |matching_resource| run_command(command + [matching_resource]) }
- end
- end
-
- def raw_resource_names
- command = [
- 'get',
- RESOURCE_LIST,
- %(--namespace "#{namespace}"),
- '-o name'
- ]
- run_command(command).lines.map(&:strip)
- end
-
- def run_command(command)
- final_command = ['kubectl', *command].join(' ')
- puts "Running command: `#{final_command}`" # rubocop:disable Rails/Output
-
- result = Gitlab::Popen.popen_with_detail([final_command])
-
- if result.status.success?
- result.stdout.chomp.freeze
- else
- raise CommandFailedError, "The `#{final_command}` command failed (status: #{result.status}) with the following error:\n#{result.stderr}"
- end
- end
- end
-end
diff --git a/lib/quality/seeders/issues.rb b/lib/quality/seeders/issues.rb
index 4c8cb6e97cc..ae19e86546a 100644
--- a/lib/quality/seeders/issues.rb
+++ b/lib/quality/seeders/issues.rb
@@ -29,6 +29,7 @@ module Quality
assignee_ids: Array(team.pluck(:id).sample(3)),
labels: labels.join(',')
}
+ params[:closed_at] = params[:created_at] + rand(35).days if params[:state] == 'closed'
issue = ::Issues::CreateService.new(project, team.sample, params).execute
if issue.persisted?
diff --git a/lib/quality/test_level.rb b/lib/quality/test_level.rb
index 334643fd0d3..cd94efddc1e 100644
--- a/lib/quality/test_level.rb
+++ b/lib/quality/test_level.rb
@@ -93,8 +93,14 @@ module Quality
private
+ def migration_and_background_migration_folders
+ TEST_LEVEL_FOLDERS.fetch(:migration) + TEST_LEVEL_FOLDERS.fetch(:background_migration)
+ end
+
def folders_pattern(level)
case level
+ when :migration
+ "{#{migration_and_background_migration_folders.join(',')}}"
# Geo specs aren't in a specific folder, but they all have the :geo tag, so we must search for them globally
when :all, :geo
'**'
@@ -105,6 +111,8 @@ module Quality
def folders_regex(level)
case level
+ when :migration
+ "(#{migration_and_background_migration_folders.join('|')})"
# Geo specs aren't in a specific folder, but they all have the :geo tag, so we must search for them globally
when :all, :geo
''