2019-03-30 07:23:56 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-29 07:56:52 +00:00
|
|
|
require 'spec_helper'
|
2018-01-04 22:35:41 +00:00
|
|
|
|
|
|
|
describe DeploymentPlatform do
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
|
2019-07-16 23:37:34 +00:00
|
|
|
describe '#deployment_platform' do
|
2018-01-04 22:35:41 +00:00
|
|
|
subject { project.deployment_platform }
|
|
|
|
|
2019-06-18 05:29:25 +00:00
|
|
|
context 'with no Kubernetes configuration on CI/CD, no Kubernetes Service' do
|
2018-01-04 22:35:41 +00:00
|
|
|
it { is_expected.to be_nil }
|
|
|
|
end
|
|
|
|
|
2019-10-14 12:06:14 +00:00
|
|
|
context 'when project is the cluster\'s management project ' do
|
2019-10-24 12:06:03 +00:00
|
|
|
let(:another_project) { create(:project, namespace: project.namespace) }
|
|
|
|
|
|
|
|
let!(:cluster_with_management_project) do
|
|
|
|
create(:cluster, :provided_by_user, projects: [another_project], management_project: project)
|
|
|
|
end
|
2019-10-14 12:06:14 +00:00
|
|
|
|
|
|
|
context 'cluster_management_project feature is enabled' do
|
|
|
|
it 'returns the cluster with management project' do
|
|
|
|
is_expected.to eq(cluster_with_management_project.platform_kubernetes)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'cluster_management_project feature is disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(cluster_management_project: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nothing' do
|
|
|
|
is_expected.to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-10-29 02:28:36 +00:00
|
|
|
context 'when project has configured kubernetes from CI/CD > Clusters' do
|
2018-01-04 22:35:41 +00:00
|
|
|
let!(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
|
|
|
|
let(:platform_kubernetes) { cluster.platform_kubernetes }
|
|
|
|
|
|
|
|
it 'returns the Kubernetes platform' do
|
|
|
|
expect(subject).to eq(platform_kubernetes)
|
|
|
|
end
|
2018-10-29 02:28:36 +00:00
|
|
|
|
|
|
|
context 'with a group level kubernetes cluster' do
|
|
|
|
let(:group_cluster) { create(:cluster, :provided_by_gcp, :group) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.update!(group: group_cluster.group)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the Kubernetes platform from the project cluster' do
|
|
|
|
expect(subject).to eq(platform_kubernetes)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when group has configured kubernetes cluster' do
|
|
|
|
let!(:group_cluster) { create(:cluster, :provided_by_gcp, :group) }
|
|
|
|
let(:group) { group_cluster.group }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.update!(group: group)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the Kubernetes platform' do
|
|
|
|
is_expected.to eq(group_cluster.platform_kubernetes)
|
|
|
|
end
|
|
|
|
|
2019-10-14 12:06:14 +00:00
|
|
|
context 'when project is the cluster\'s management project ' do
|
2019-10-24 12:06:03 +00:00
|
|
|
let(:another_project) { create(:project, namespace: project.namespace) }
|
|
|
|
|
|
|
|
let!(:cluster_with_management_project) do
|
|
|
|
create(:cluster, :provided_by_user, projects: [another_project], management_project: project)
|
|
|
|
end
|
2019-10-14 12:06:14 +00:00
|
|
|
|
|
|
|
context 'cluster_management_project feature is enabled' do
|
|
|
|
it 'returns the cluster with management project' do
|
|
|
|
is_expected.to eq(cluster_with_management_project.platform_kubernetes)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'cluster_management_project feature is disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(cluster_management_project: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the group cluster' do
|
|
|
|
is_expected.to eq(group_cluster.platform_kubernetes)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when project is not the cluster\'s management project' do
|
|
|
|
let(:another_project) { create(:project, group: group) }
|
|
|
|
let!(:cluster_with_management_project) { create(:cluster, :provided_by_user, management_project: another_project) }
|
|
|
|
|
|
|
|
it 'returns the group cluster' do
|
|
|
|
is_expected.to eq(group_cluster.platform_kubernetes)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-24 09:20:54 +00:00
|
|
|
context 'when child group has configured kubernetes cluster' do
|
2019-07-16 23:32:04 +00:00
|
|
|
let(:child_group1) { create(:group, parent: group) }
|
|
|
|
let!(:child_group1_cluster) { create(:cluster_for_group, groups: [child_group1]) }
|
2018-10-29 02:28:36 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
project.update!(group: child_group1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the Kubernetes platform for the child group' do
|
|
|
|
is_expected.to eq(child_group1_cluster.platform_kubernetes)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'deeply nested group' do
|
2019-07-16 23:32:04 +00:00
|
|
|
let(:child_group2) { create(:group, parent: child_group1) }
|
|
|
|
let!(:child_group2_cluster) { create(:cluster_for_group, groups: [child_group2]) }
|
2018-10-29 02:28:36 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
project.update!(group: child_group2)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns most nested group cluster Kubernetes platform' do
|
|
|
|
is_expected.to eq(child_group2_cluster.platform_kubernetes)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'cluster in the middle of hierarchy is disabled' do
|
|
|
|
before do
|
|
|
|
child_group2_cluster.update!(enabled: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns closest enabled Kubenetes platform' do
|
|
|
|
is_expected.to eq(child_group1_cluster.platform_kubernetes)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-01-04 22:35:41 +00:00
|
|
|
end
|
2019-10-22 18:06:35 +00:00
|
|
|
|
|
|
|
context 'when instance has configured kubernetes cluster' do
|
|
|
|
let!(:instance_cluster) { create(:cluster, :provided_by_user, :instance) }
|
|
|
|
|
|
|
|
it 'returns the Kubernetes platform' do
|
|
|
|
is_expected.to eq(instance_cluster.platform_kubernetes)
|
|
|
|
end
|
|
|
|
end
|
2018-01-04 22:35:41 +00:00
|
|
|
end
|
|
|
|
end
|