Commit fa8d93fd authored by Lin Jen-Shin's avatar Lin Jen-Shin

Merge branch '216459-use-gitlab-json-class-for-flaky-report-and-helm3-client-libs' into 'master'

Move tooling classes to tooling/lib/tooling and use Gitlab::Json

Closes #216459

See merge request gitlab-org/gitlab!35961
parents 8fa3522e d15768b3
...@@ -139,13 +139,13 @@ module Gitlab ...@@ -139,13 +139,13 @@ module Gitlab
%r{\Arubocop/cop/migration(/|\.rb)} => :database, %r{\Arubocop/cop/migration(/|\.rb)} => :database,
%r{\A(\.gitlab-ci\.yml\z|\.gitlab\/ci)} => :engineering_productivity, %r{\A(\.gitlab-ci\.yml\z|\.gitlab\/ci)} => :engineering_productivity,
%r{\A\.codeclimate\.yml\z} => :engineering_productivity,
%r{\A\.overcommit\.yml\.example\z} => :engineering_productivity, %r{\A\.overcommit\.yml\.example\z} => :engineering_productivity,
%r{\Atooling/overcommit/} => :engineering_productivity, %r{\A\.editorconfig\z} => :engineering_productivity,
%r{\A.editorconfig\z} => :engineering_productivity,
%r{Dangerfile\z} => :engineering_productivity, %r{Dangerfile\z} => :engineering_productivity,
%r{\A(ee/)?(danger/|lib/gitlab/danger/)} => :engineering_productivity, %r{\A(ee/)?(danger/|lib/gitlab/danger/)} => :engineering_productivity,
%r{\A(ee/)?scripts/} => :engineering_productivity, %r{\A(ee/)?scripts/} => :engineering_productivity,
%r{\A\.codeclimate\.yml\z} => :engineering_productivity, %r{\Atooling/} => :engineering_productivity,
%r{\A(ee/)?app/(?!assets|views)[^/]+} => :backend, %r{\A(ee/)?app/(?!assets|views)[^/]+} => :backend,
%r{\A(ee/)?(bin|config|generator_templates|lib|rubocop)/} => :backend, %r{\A(ee/)?(bin|config|generator_templates|lib|rubocop)/} => :backend,
......
# frozen_string_literal: true # frozen_string_literal: true
require 'gitlab' require 'gitlab'
require_relative File.expand_path('../../lib/quality/helm3_client.rb', __dir__) require_relative File.expand_path('../../tooling/lib/tooling/helm3_client.rb', __dir__)
require_relative File.expand_path('../../lib/quality/kubernetes_client.rb', __dir__) require_relative File.expand_path('../../tooling/lib/tooling/kubernetes_client.rb', __dir__)
class AutomatedCleanup class AutomatedCleanup
attr_reader :project_path, :gitlab_token attr_reader :project_path, :gitlab_token
...@@ -44,11 +44,11 @@ class AutomatedCleanup ...@@ -44,11 +44,11 @@ class AutomatedCleanup
end end
def helm def helm
@helm ||= Quality::Helm3Client.new(namespace: review_apps_namespace) @helm ||= Tooling::Helm3Client.new(namespace: review_apps_namespace)
end end
def kubernetes def kubernetes
@kubernetes ||= Quality::KubernetesClient.new(namespace: review_apps_namespace) @kubernetes ||= Tooling::KubernetesClient.new(namespace: review_apps_namespace)
end end
def perform_gitlab_environment_cleanup!(days_for_stop:, days_for_delete:) def perform_gitlab_environment_cleanup!(days_for_stop:, days_for_delete:)
...@@ -76,7 +76,7 @@ class AutomatedCleanup ...@@ -76,7 +76,7 @@ class AutomatedCleanup
if deployed_at < delete_threshold if deployed_at < delete_threshold
deleted_environment = delete_environment(environment, deployment) deleted_environment = delete_environment(environment, deployment)
if deleted_environment if deleted_environment
release = Quality::Helm3Client::Release.new(environment.slug, 1, deployed_at.to_s, nil, nil, review_apps_namespace) release = Tooling::Helm3Client::Release.new(environment.slug, 1, deployed_at.to_s, nil, nil, review_apps_namespace)
releases_to_delete << release releases_to_delete << release
end end
else else
...@@ -157,11 +157,11 @@ class AutomatedCleanup ...@@ -157,11 +157,11 @@ class AutomatedCleanup
helm.delete(release_name: releases_names) helm.delete(release_name: releases_names)
kubernetes.cleanup(release_name: releases_names, wait: false) kubernetes.cleanup(release_name: releases_names, wait: false)
rescue Quality::Helm3Client::CommandFailedError => ex rescue Tooling::Helm3Client::CommandFailedError => ex
raise ex unless ignore_exception?(ex.message, IGNORED_HELM_ERRORS) raise ex unless ignore_exception?(ex.message, IGNORED_HELM_ERRORS)
puts "Ignoring the following Helm error:\n#{ex}\n" puts "Ignoring the following Helm error:\n#{ex}\n"
rescue Quality::KubernetesClient::CommandFailedError => ex rescue Tooling::KubernetesClient::CommandFailedError => ex
raise ex unless ignore_exception?(ex.message, IGNORED_KUBERNETES_ERRORS) raise ex unless ignore_exception?(ex.message, IGNORED_KUBERNETES_ERRORS)
puts "Ignoring the following Kubernetes error:\n#{ex}\n" puts "Ignoring the following Kubernetes error:\n#{ex}\n"
......
# frozen_string_literal: true # frozen_string_literal: true
require 'fast_spec_helper' require_relative '../../../../tooling/lib/tooling/helm3_client'
RSpec.describe Quality::Helm3Client do RSpec.describe Tooling::Helm3Client do
let(:namespace) { 'review-apps' } let(:namespace) { 'review-apps' }
let(:release_name) { 'my-release' } let(:release_name) { 'my-release' }
let(:raw_helm_list_page1) do let(:raw_helm_list_page1) do
......
# frozen_string_literal: true # frozen_string_literal: true
require 'fast_spec_helper' require_relative '../../../../tooling/lib/tooling/kubernetes_client'
RSpec.describe Quality::KubernetesClient do RSpec.describe Tooling::KubernetesClient do
let(:namespace) { 'review-apps' } let(:namespace) { 'review-apps' }
let(:release_name) { 'my-release' } let(:release_name) { 'my-release' }
let(:pod_for_release) { "pod-my-release-abcd" } let(:pod_for_release) { "pod-my-release-abcd" }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
require_relative '../../../../tooling/lib/tooling/test_file_finder' require_relative '../../../../tooling/lib/tooling/test_file_finder'
RSpec.describe Tooling::TestFileFinder do RSpec.describe Tooling::TestFileFinder do
subject { Tooling::TestFileFinder.new(file) } subject { described_class.new(file) }
describe '#test_files' do describe '#test_files' do
context 'when given non .rb files' do context 'when given non .rb files' do
......
# frozen_string_literal: true # frozen_string_literal: true
require 'time' require 'time'
require_relative '../gitlab/popen' unless defined?(Gitlab::Popen) require 'json'
require_relative '../../../lib/gitlab/popen' unless defined?(Gitlab::Popen)
require_relative '../../../lib/gitlab/json' unless defined?(Gitlab::Json)
module Quality module Tooling
class Helm3Client class Helm3Client
CommandFailedError = Class.new(StandardError) CommandFailedError = Class.new(StandardError)
...@@ -65,12 +67,12 @@ module Quality ...@@ -65,12 +67,12 @@ module Quality
%(--output json), %(--output json),
*args *args
] ]
releases = JSON.parse(run_command(command)) releases = Gitlab::Json.parse(run_command(command))
releases.map do |release| releases.map do |release|
Release.new(*release.values_at(*RELEASE_JSON_ATTRIBUTES)) Release.new(*release.values_at(*RELEASE_JSON_ATTRIBUTES))
end end
rescue JSON::ParserError => ex rescue ::JSON::ParserError => ex
puts "Ignoring this JSON parsing error: #{ex}" # rubocop:disable Rails/Output puts "Ignoring this JSON parsing error: #{ex}" # rubocop:disable Rails/Output
[] []
end end
......
# frozen_string_literal: true # frozen_string_literal: true
require_relative '../gitlab/popen' unless defined?(Gitlab::Popen) require_relative '../../../lib/gitlab/popen' unless defined?(Gitlab::Popen)
require_relative '../../../lib/gitlab/json' unless defined?(Gitlab::JSON)
module Quality module Tooling
class KubernetesClient class KubernetesClient
RESOURCE_LIST = 'ingress,svc,pdb,hpa,deploy,statefulset,job,pod,secret,configmap,pvc,secret,clusterrole,clusterrolebinding,role,rolebinding,sa,crd' RESOURCE_LIST = 'ingress,svc,pdb,hpa,deploy,statefulset,job,pod,secret,configmap,pvc,secret,clusterrole,clusterrolebinding,role,rolebinding,sa,crd'
CommandFailedError = Class.new(StandardError) CommandFailedError = Class.new(StandardError)
......
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