diff options
author | Stan Hu <stanhu@gmail.com> | 2019-06-25 01:23:18 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2019-06-25 01:23:18 +0300 |
commit | db9783f7826ed5ba58a8941dd80a1cd7dda517b0 (patch) | |
tree | 74834cc78180e1be10c3f48d12113771a305a380 | |
parent | 30eb7448dec4e97e82a1be6ac011e3abe0e4cc0d (diff) | |
parent | ee18ca2fa590453b42c7cba28c334d1327aa8b33 (diff) |
Merge branch 'refactor_deployment_cluster' into 'master'
Refactor Deployment#cluster to #deployment_platform_cluster
See merge request gitlab-org/gitlab-ce!29961
-rw-r--r-- | app/models/deployment.rb | 9 | ||||
-rw-r--r-- | lib/gitlab/ci/build/prerequisite/kubernetes_namespace.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/build/prerequisite/kubernetes_namespace_spec.rb | 8 | ||||
-rw-r--r-- | spec/models/deployment_spec.rb | 4 |
4 files changed, 10 insertions, 13 deletions
diff --git a/app/models/deployment.rb b/app/models/deployment.rb index ee6e830d3ec..f0fa5974787 100644 --- a/app/models/deployment.rb +++ b/app/models/deployment.rb @@ -84,12 +84,9 @@ class Deployment < ApplicationRecord Commit.truncate_sha(sha) end - def cluster - platform = project.deployment_platform(environment: environment.name) - - if platform.present? && platform.respond_to?(:cluster) - platform.cluster - end + # Deprecated - will be replaced by a persisted cluster_id + def deployment_platform_cluster + environment.deployment_platform&.cluster end def execute_hooks diff --git a/lib/gitlab/ci/build/prerequisite/kubernetes_namespace.rb b/lib/gitlab/ci/build/prerequisite/kubernetes_namespace.rb index e6e0aaab60b..49c680605ea 100644 --- a/lib/gitlab/ci/build/prerequisite/kubernetes_namespace.rb +++ b/lib/gitlab/ci/build/prerequisite/kubernetes_namespace.rb @@ -20,7 +20,7 @@ module Gitlab private def deployment_cluster - build.deployment&.cluster + build.deployment&.deployment_platform_cluster end def kubernetes_namespace 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 c5bc81a2b9e..51e16c99688 100644 --- a/spec/lib/gitlab/ci/build/prerequisite/kubernetes_namespace_spec.rb +++ b/spec/lib/gitlab/ci/build/prerequisite/kubernetes_namespace_spec.rb @@ -23,7 +23,7 @@ describe Gitlab::Ci::Build::Prerequisite::KubernetesNamespace do let(:cluster) { create(:cluster, :group) } before do - allow(build.deployment).to receive(:cluster).and_return(cluster) + allow(build.deployment).to receive(:deployment_platform_cluster).and_return(cluster) end it { is_expected.to be_truthy } @@ -49,7 +49,7 @@ describe Gitlab::Ci::Build::Prerequisite::KubernetesNamespace do context 'and no cluster to deploy to' do before do - expect(deployment.cluster).to be_nil + expect(deployment.deployment_platform_cluster).to be_nil end it { is_expected.to be_falsey } @@ -67,7 +67,7 @@ describe Gitlab::Ci::Build::Prerequisite::KubernetesNamespace do let(:cluster) { create(:cluster, :group) } before do - allow(build.deployment).to receive(:cluster).and_return(cluster) + allow(build.deployment).to receive(:deployment_platform_cluster).and_return(cluster) end it 'creates a kubernetes namespace' do @@ -84,7 +84,7 @@ describe Gitlab::Ci::Build::Prerequisite::KubernetesNamespace do context 'completion is not required' do before do - expect(deployment.cluster).to be_nil + expect(deployment.deployment_platform_cluster).to be_nil end it 'does not create a namespace' do diff --git a/spec/models/deployment_spec.rb b/spec/models/deployment_spec.rb index 1dceef3fc00..a433878f3bc 100644 --- a/spec/models/deployment_spec.rb +++ b/spec/models/deployment_spec.rb @@ -380,12 +380,12 @@ describe Deployment do end end - describe '#cluster' do + describe '#deployment_platform_cluster' do let(:deployment) { create(:deployment) } let(:project) { deployment.project } let(:environment) { deployment.environment } - subject { deployment.cluster } + subject { deployment.deployment_platform_cluster } before do expect(project).to receive(:deployment_platform) |