Rearrange DeploymentPlatform methods
- Change find_cluster_platform_kubernetes to ignore environment argument - Fix broken specs CE Port of: https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/5047/
This commit is contained in:
parent
fbb83069de
commit
ca59bfdc66
7 changed files with 17 additions and 9 deletions
|
@ -10,6 +10,7 @@ module Clusters
|
|||
Applications::Prometheus.application_name => Applications::Prometheus,
|
||||
Applications::Runner.application_name => Applications::Runner
|
||||
}.freeze
|
||||
DEFAULT_ENVIRONMENT = '*'.freeze
|
||||
|
||||
belongs_to :user
|
||||
|
||||
|
@ -50,6 +51,7 @@ module Clusters
|
|||
|
||||
scope :enabled, -> { where(enabled: true) }
|
||||
scope :disabled, -> { where(enabled: false) }
|
||||
scope :default_environment, -> { where(environment_scope: DEFAULT_ENVIRONMENT) }
|
||||
|
||||
def status_name
|
||||
if provider
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
module DeploymentPlatform
|
||||
# EE would override this and utilize the extra argument
|
||||
# EE would override this and utilize environment argument
|
||||
def deployment_platform(environment: nil)
|
||||
@deployment_platform ||=
|
||||
find_cluster_platform_kubernetes ||
|
||||
find_cluster_platform_kubernetes(environment: environment) ||
|
||||
find_kubernetes_service_integration ||
|
||||
build_cluster_and_deployment_platform
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_cluster_platform_kubernetes
|
||||
clusters.find_by(enabled: true)&.platform_kubernetes
|
||||
# EE would override this and utilize environment argument
|
||||
def find_cluster_platform_kubernetes(environment: nil)
|
||||
clusters.enabled.default_environment
|
||||
.last&.platform_kubernetes
|
||||
end
|
||||
|
||||
def find_kubernetes_service_integration
|
||||
|
|
|
@ -18,7 +18,7 @@ describe Projects::ClustersController do
|
|||
context 'when project has one or more clusters' do
|
||||
let(:project) { create(:project) }
|
||||
let!(:enabled_cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
|
||||
let!(:disabled_cluster) { create(:cluster, :disabled, :provided_by_gcp, projects: [project]) }
|
||||
let!(:disabled_cluster) { create(:cluster, :disabled, :provided_by_gcp, :production_environment, projects: [project]) }
|
||||
it 'lists available clusters' do
|
||||
go
|
||||
|
||||
|
@ -32,7 +32,7 @@ describe Projects::ClustersController do
|
|||
|
||||
before do
|
||||
allow(Clusters::Cluster).to receive(:paginates_per).and_return(1)
|
||||
create_list(:cluster, 2, :provided_by_gcp, projects: [project])
|
||||
create_list(:cluster, 2, :provided_by_gcp, :production_environment, projects: [project])
|
||||
get :index, namespace_id: project.namespace, project_id: project, page: last_page
|
||||
end
|
||||
|
||||
|
|
|
@ -32,5 +32,9 @@ FactoryBot.define do
|
|||
trait :disabled do
|
||||
enabled false
|
||||
end
|
||||
|
||||
trait :production_environment do
|
||||
sequence(:environment_scope) { |n| "production#{n}/*" }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ describe ClustersFinder do
|
|||
|
||||
describe '#execute' do
|
||||
let(:enabled_cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
|
||||
let(:disabled_cluster) { create(:cluster, :disabled, :provided_by_gcp, projects: [project]) }
|
||||
let(:disabled_cluster) { create(:cluster, :disabled, :provided_by_gcp, :production_environment, projects: [project]) }
|
||||
|
||||
subject { described_class.new(project, user, scope).execute }
|
||||
|
||||
|
|
|
@ -339,7 +339,7 @@ describe ProjectPresenter do
|
|||
|
||||
it 'returns link to clusters page if more than one exists' do
|
||||
project.add_master(user)
|
||||
create(:cluster, projects: [project])
|
||||
create(:cluster, :production_environment, projects: [project])
|
||||
create(:cluster, projects: [project])
|
||||
|
||||
expect(presenter.kubernetes_cluster_anchor_data).to eq(OpenStruct.new(enabled: true,
|
||||
|
|
|
@ -82,7 +82,7 @@ describe Clusters::CreateService do
|
|||
|
||||
context 'when project has a cluster' do
|
||||
include_context 'valid params'
|
||||
let!(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
|
||||
let!(:cluster) { create(:cluster, :provided_by_gcp, :production_environment, projects: [project]) }
|
||||
|
||||
it 'does not create a cluster' do
|
||||
expect(ClusterProvisionWorker).not_to receive(:perform_async)
|
||||
|
|
Loading…
Reference in a new issue