summaryrefslogtreecommitdiff
path: root/spec/workers/cluster_configure_worker_spec.rb
diff options
context:
space:
mode:
authorTiger <twatson@gitlab.com>2019-04-15 12:11:50 +1000
committerTiger <twatson@gitlab.com>2019-04-16 13:59:37 +1000
commite33ecfdec30a8efee191f8c2dd85ca54011128ce (patch)
tree9b97e13ff405e56add3a45ab1ce6ff4433e6e1d5 /spec/workers/cluster_configure_worker_spec.rb
parent0a99e0220d9371423039f05f700af3675b26624f (diff)
downloadgitlab-ce-e33ecfdec30a8efee191f8c2dd85ca54011128ce.tar.gz
Disable JIT resource creation for project clusters60500-disable-jit-kubernetes-resource-creation-for-project-level-clusters
JIT resource creation blocks deployments if a user is self-managing their cluster, as it will fail the build if unable to create a namespace and service account. Using a custom namespace and service account was previously supported for project level clusters, so we should preserve this functionality. https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/27352
Diffstat (limited to 'spec/workers/cluster_configure_worker_spec.rb')
-rw-r--r--spec/workers/cluster_configure_worker_spec.rb67
1 files changed, 30 insertions, 37 deletions
diff --git a/spec/workers/cluster_configure_worker_spec.rb b/spec/workers/cluster_configure_worker_spec.rb
index 83f76809435..bdb8e0e9c84 100644
--- a/spec/workers/cluster_configure_worker_spec.rb
+++ b/spec/workers/cluster_configure_worker_spec.rb
@@ -10,25 +10,35 @@ describe ClusterConfigureWorker, '#perform' do
stub_feature_flags(ci_preparing_state: ci_preparing_state_enabled)
end
- context 'when group cluster' do
- let(:cluster) { create(:cluster, :group, :provided_by_gcp) }
- let(:group) { cluster.group }
+ shared_examples 'configured cluster' do
+ it 'creates a namespace' do
+ expect(Clusters::RefreshService).to receive(:create_or_update_namespaces_for_cluster).with(cluster).once
- context 'when group has no projects' do
- it 'does not create a namespace' do
- expect_any_instance_of(Clusters::Gcp::Kubernetes::CreateOrUpdateNamespaceService).not_to receive(:execute)
+ worker.perform(cluster.id)
+ end
+ end
- worker.perform(cluster.id)
- end
+ shared_examples 'unconfigured cluster' do
+ it 'does not create a namespace' do
+ expect(Clusters::RefreshService).not_to receive(:create_or_update_namespaces_for_cluster)
+
+ worker.perform(cluster.id)
end
+ end
+
+ context 'group cluster' do
+ let(:cluster) { create(:cluster, :group, :provided_by_gcp) }
+ let(:group) { cluster.group }
context 'when group has a project' do
let!(:project) { create(:project, group: group) }
- it 'creates a namespace for the project' do
- expect_any_instance_of(Clusters::Gcp::Kubernetes::CreateOrUpdateNamespaceService).to receive(:execute).once
+ it_behaves_like 'configured cluster'
+
+ context 'ci_preparing_state feature is enabled' do
+ let(:ci_preparing_state_enabled) { true }
- worker.perform(cluster.id)
+ it_behaves_like 'unconfigured cluster'
end
end
@@ -36,32 +46,26 @@ describe ClusterConfigureWorker, '#perform' do
let!(:subgroup) { create(:group, parent: group) }
let!(:project) { create(:project, group: subgroup) }
- it 'creates a namespace for the project' do
- expect_any_instance_of(Clusters::Gcp::Kubernetes::CreateOrUpdateNamespaceService).to receive(:execute).once
+ it_behaves_like 'configured cluster'
- worker.perform(cluster.id)
+ context 'ci_preparing_state feature is enabled' do
+ let(:ci_preparing_state_enabled) { true }
+
+ it_behaves_like 'unconfigured cluster'
end
end
end
context 'when provider type is gcp' do
- let(:cluster) { create(:cluster, :project, :provided_by_gcp) }
-
- it 'configures kubernetes platform' do
- expect_any_instance_of(Clusters::Gcp::Kubernetes::CreateOrUpdateNamespaceService).to receive(:execute)
+ let!(:cluster) { create(:cluster, :project, :provided_by_gcp) }
- described_class.new.perform(cluster.id)
- end
+ it_behaves_like 'configured cluster'
end
context 'when provider type is user' do
- let(:cluster) { create(:cluster, :project, :provided_by_user) }
+ let!(:cluster) { create(:cluster, :project, :provided_by_user) }
- it 'configures kubernetes platform' do
- expect_any_instance_of(Clusters::Gcp::Kubernetes::CreateOrUpdateNamespaceService).to receive(:execute)
-
- described_class.new.perform(cluster.id)
- end
+ it_behaves_like 'configured cluster'
end
context 'when cluster does not exist' do
@@ -71,15 +75,4 @@ describe ClusterConfigureWorker, '#perform' do
described_class.new.perform(123)
end
end
-
- context 'ci_preparing_state feature is enabled' do
- let(:cluster) { create(:cluster) }
- let(:ci_preparing_state_enabled) { true }
-
- it 'does not configure the cluster' do
- expect(Clusters::RefreshService).not_to receive(:create_or_update_namespaces_for_cluster)
-
- described_class.new.perform(cluster.id)
- end
- end
end