Welcome to mirror list, hosted at ThFree Co, Russian Federation.

deployment_platform_spec.rb « concerns « models « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9164c3a75c5d72c620abdb7bccab45c4f83d8413 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# frozen_string_literal: true

require 'spec_helper'

describe DeploymentPlatform do
  let(:project) { create(:project) }

  describe '#deployment_platform' do
    subject { project.deployment_platform }

    context 'with no Kubernetes configuration on CI/CD, no Kubernetes Service' do
      it { is_expected.to be_nil }
    end

    context 'when project is the cluster\'s management project ' do
      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

      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

    context 'when project has configured kubernetes from CI/CD > Clusters' do
      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

      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

      context 'when project is the cluster\'s management project ' do
        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

        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

      context 'when child group has configured kubernetes cluster' do
        let(:child_group1) { create(:group, parent: group) }
        let!(:child_group1_cluster) { create(:cluster_for_group, groups: [child_group1]) }

        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
          let(:child_group2) { create(:group, parent: child_group1) }
          let!(:child_group2_cluster) { create(:cluster_for_group, groups: [child_group2]) }

          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
    end

    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
  end
end