Commit ca59bfdc authored by Mayra Cabrera's avatar Mayra Cabrera

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/
parent fbb83069
...@@ -10,6 +10,7 @@ module Clusters ...@@ -10,6 +10,7 @@ module Clusters
Applications::Prometheus.application_name => Applications::Prometheus, Applications::Prometheus.application_name => Applications::Prometheus,
Applications::Runner.application_name => Applications::Runner Applications::Runner.application_name => Applications::Runner
}.freeze }.freeze
DEFAULT_ENVIRONMENT = '*'.freeze
belongs_to :user belongs_to :user
...@@ -50,6 +51,7 @@ module Clusters ...@@ -50,6 +51,7 @@ module Clusters
scope :enabled, -> { where(enabled: true) } scope :enabled, -> { where(enabled: true) }
scope :disabled, -> { where(enabled: false) } scope :disabled, -> { where(enabled: false) }
scope :default_environment, -> { where(environment_scope: DEFAULT_ENVIRONMENT) }
def status_name def status_name
if provider if provider
......
module DeploymentPlatform module DeploymentPlatform
# EE would override this and utilize the extra argument # EE would override this and utilize environment argument
def deployment_platform(environment: nil) def deployment_platform(environment: nil)
@deployment_platform ||= @deployment_platform ||=
find_cluster_platform_kubernetes || find_cluster_platform_kubernetes(environment: environment) ||
find_kubernetes_service_integration || find_kubernetes_service_integration ||
build_cluster_and_deployment_platform build_cluster_and_deployment_platform
end end
private private
def find_cluster_platform_kubernetes # EE would override this and utilize environment argument
clusters.find_by(enabled: true)&.platform_kubernetes def find_cluster_platform_kubernetes(environment: nil)
clusters.enabled.default_environment
.last&.platform_kubernetes
end end
def find_kubernetes_service_integration def find_kubernetes_service_integration
......
...@@ -18,7 +18,7 @@ describe Projects::ClustersController do ...@@ -18,7 +18,7 @@ describe Projects::ClustersController do
context 'when project has one or more clusters' do context 'when project has one or more clusters' do
let(:project) { create(:project) } let(:project) { create(:project) }
let!(:enabled_cluster) { create(:cluster, :provided_by_gcp, projects: [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 it 'lists available clusters' do
go go
...@@ -32,7 +32,7 @@ describe Projects::ClustersController do ...@@ -32,7 +32,7 @@ describe Projects::ClustersController do
before do before do
allow(Clusters::Cluster).to receive(:paginates_per).and_return(1) 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 get :index, namespace_id: project.namespace, project_id: project, page: last_page
end end
......
...@@ -32,5 +32,9 @@ FactoryBot.define do ...@@ -32,5 +32,9 @@ FactoryBot.define do
trait :disabled do trait :disabled do
enabled false enabled false
end end
trait :production_environment do
sequence(:environment_scope) { |n| "production#{n}/*" }
end
end end
end end
...@@ -6,7 +6,7 @@ describe ClustersFinder do ...@@ -6,7 +6,7 @@ describe ClustersFinder do
describe '#execute' do describe '#execute' do
let(:enabled_cluster) { create(:cluster, :provided_by_gcp, projects: [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]) }
subject { described_class.new(project, user, scope).execute } subject { described_class.new(project, user, scope).execute }
......
...@@ -339,7 +339,7 @@ describe ProjectPresenter do ...@@ -339,7 +339,7 @@ describe ProjectPresenter do
it 'returns link to clusters page if more than one exists' do it 'returns link to clusters page if more than one exists' do
project.add_master(user) project.add_master(user)
create(:cluster, projects: [project]) create(:cluster, :production_environment, projects: [project])
create(:cluster, projects: [project]) create(:cluster, projects: [project])
expect(presenter.kubernetes_cluster_anchor_data).to eq(OpenStruct.new(enabled: true, expect(presenter.kubernetes_cluster_anchor_data).to eq(OpenStruct.new(enabled: true,
......
...@@ -82,7 +82,7 @@ describe Clusters::CreateService do ...@@ -82,7 +82,7 @@ describe Clusters::CreateService do
context 'when project has a cluster' do context 'when project has a cluster' do
include_context 'valid params' 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 it 'does not create a cluster' do
expect(ClusterProvisionWorker).not_to receive(:perform_async) expect(ClusterProvisionWorker).not_to receive(:perform_async)
......
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