diff options
author | Tiger <twatson@gitlab.com> | 2019-03-13 06:06:54 +0300 |
---|---|---|
committer | Tiger <twatson@gitlab.com> | 2019-03-20 04:04:46 +0300 |
commit | 89b0bc04b9927abc85ce5fc3735438f956a8d5a2 (patch) | |
tree | 29355d49ce1a784b4695b4897880c6fe2879d353 /spec/lib/gitlab/ci/build | |
parent | 759dab5b69f53a861045ebbc84836f83c7502af2 (diff) |
Create one Kubernetes namespace for a deployment
Instead of creating a Kubernetes namespace on every
cluster related to a project, only create one on the
cluster the project is about to be deployed to.
Diffstat (limited to 'spec/lib/gitlab/ci/build')
-rw-r--r-- | spec/lib/gitlab/ci/build/prerequisite/kubernetes_namespace_spec.rb | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/spec/lib/gitlab/ci/build/prerequisite/kubernetes_namespace_spec.rb b/spec/lib/gitlab/ci/build/prerequisite/kubernetes_namespace_spec.rb index 6f6e4abc0c8..ba87863c978 100644 --- a/spec/lib/gitlab/ci/build/prerequisite/kubernetes_namespace_spec.rb +++ b/spec/lib/gitlab/ci/build/prerequisite/kubernetes_namespace_spec.rb @@ -16,34 +16,41 @@ describe Gitlab::Ci::Build::Prerequisite::KubernetesNamespace do it { is_expected.to be_falsey } end - context 'build has a deployment, and no existing kubernetes namespace' do + context 'build has a deployment' do let!(:deployment) { create(:deployment, deployable: build) } - let!(:cluster) { create(:cluster, projects: [build.project]) } - before do - expect(build.project.kubernetes_namespaces).to be_empty - end + context 'and a cluster to deploy to' do + let(:cluster) { create(:cluster, projects: [build.project]) } - it { is_expected.to be_truthy } - end + before do + allow(build.deployment).to receive(:cluster).and_return(cluster) + end - context 'build has a deployment and kubernetes namespaces' do - let!(:deployment) { create(:deployment, deployable: build) } - let!(:cluster) { create(:cluster, projects: [build.project]) } - let!(:kubernetes_namespace) { create(:cluster_kubernetes_namespace, cluster: cluster) } + it { is_expected.to be_truthy } + end - it { is_expected.to be_falsey } + context 'and no cluster to deploy to' do + before do + expect(deployment.cluster).to be_nil + end + + it { is_expected.to be_falsey } + end end end describe '#complete!' do - let(:cluster) { create(:cluster, projects: [build.project]) } + let!(:deployment) { create(:deployment, deployable: build) } let(:service) { double(execute: true) } subject { described_class.new(build).complete! } context 'completion is required' do - let!(:deployment) { create(:deployment, deployable: build) } + let(:cluster) { create(:cluster, projects: [build.project]) } + + before do + allow(build.deployment).to receive(:cluster).and_return(cluster) + end it 'creates a kubernetes namespace' do expect(Clusters::Gcp::Kubernetes::CreateOrUpdateNamespaceService) @@ -59,7 +66,7 @@ describe Gitlab::Ci::Build::Prerequisite::KubernetesNamespace do context 'completion is not required' do before do - expect(build.deployment).to be_nil + expect(deployment.cluster).to be_nil end it 'does not create a namespace' do |