Commit d1535ead authored by Thong Kuah's avatar Thong Kuah

Remove un-reachable BE methods

But we still maintain a has_legacy_app_label facade for the API.

Also remove un-used legacy_deployments keyword
parent 50e6ca32
......@@ -26,9 +26,8 @@ module EE
deployments = filter_by_project_environment(data[:deployments], project.full_path_slug, environment.slug)
pods = filter_by_project_environment(data[:pods], project.full_path_slug, environment.slug)
legacy_deployments = filter_by_legacy_label(data[:deployments], project.full_path_slug, environment.slug)
::Gitlab::Kubernetes::RolloutStatus.from_deployments(*deployments, pods_attrs: pods, legacy_deployments: legacy_deployments)
::Gitlab::Kubernetes::RolloutStatus.from_deployments(*deployments, pods_attrs: pods)
end
private
......
......@@ -4,7 +4,11 @@ class RolloutStatusEntity < Grape::Entity
include RequestAwareEntity
expose :status, as: :status
expose :has_legacy_app_label?, as: :has_legacy_app_label
# To be removed in API v5
expose :has_legacy_app_label do |_rollout_status|
false
end
expose :instances, if: -> (rollout_status, _) { rollout_status.found? }
expose :completion, if: -> (rollout_status, _) { rollout_status.found? }
......
......@@ -22,31 +22,26 @@ module Gitlab
@status == :not_found
end
def has_legacy_app_label?
legacy_deployments.present?
end
def found?
@status == :found
end
def self.from_deployments(*deployments, pods_attrs: [], legacy_deployments: [])
return new([], status: :not_found, legacy_deployments: legacy_deployments) if deployments.empty?
def self.from_deployments(*deployments, pods_attrs: {})
return new([], status: :not_found) if deployments.empty?
deployments = deployments.map { |deploy| ::Gitlab::Kubernetes::Deployment.new(deploy, pods: pods_attrs) }
deployments.sort_by!(&:order)
new(deployments, legacy_deployments: legacy_deployments)
new(deployments)
end
def self.loading
new([], status: :loading)
end
def initialize(deployments, status: :found, legacy_deployments: [])
def initialize(deployments, status: :found)
@status = status
@deployments = deployments
@instances = deployments.flat_map(&:instances)
@legacy_deployments = legacy_deployments
@completion =
if @instances.empty?
......@@ -58,10 +53,6 @@ module Gitlab
(finished / @instances.count.to_f * 100).to_i
end
end
private
attr_reader :legacy_deployments
end
end
end
......@@ -7,7 +7,6 @@ RSpec.describe Gitlab::Kubernetes::RolloutStatus do
let(:track) { nil }
let(:specs) { specs_all_finished }
let(:legacy_deployments) { [] }
let(:pods) do
create_pods(name: "one", count: 3, track: 'stable') + create_pods(name: "two", count: 3, track: "canary")
......@@ -27,26 +26,7 @@ RSpec.describe Gitlab::Kubernetes::RolloutStatus do
]
end
subject(:rollout_status) { described_class.from_deployments(*specs, pods_attrs: pods, legacy_deployments: legacy_deployments) }
describe '#has_legacy_app_label?' do
let(:specs) { [] }
let(:pods) { [] }
context 'no legacy deployments' do
it { is_expected.not_to be_has_legacy_app_label }
end
context 'with legacy deployment' do
let(:legacy_deployments) do
[
kube_deployment(name: 'legacy')
]
end
it { is_expected.to be_has_legacy_app_label }
end
end
subject(:rollout_status) { described_class.from_deployments(*specs, pods_attrs: pods) }
describe '#deployments' do
it 'stores the deployments' do
......
......@@ -61,10 +61,6 @@ RSpec.describe Clusters::Platforms::Kubernetes do
expect(rollout_status.deployments).to eq([])
end
it 'has the has_legacy_app_label flag' do
expect(rollout_status).to be_has_legacy_app_label
end
end
context 'deployment with no pods' do
......@@ -89,35 +85,6 @@ RSpec.describe Clusters::Platforms::Kubernetes do
expect(rollout_status.deployments.map(&:name)).to contain_exactly('matched-deployment')
end
it 'does have the has_legacy_app_label flag' do
expect(rollout_status).to be_has_legacy_app_label
end
end
context 'deployment with app label not matching the environment' do
let(:other_deployment) do
kube_deployment(name: 'other-deployment').tap do |deployment|
deployment['metadata']['annotations'].delete('app.gitlab.com/env')
deployment['metadata']['annotations'].delete('app.gitlab.com/app')
deployment['metadata']['labels']['app'] = 'helm-app-label'
end
end
let(:other_pod) do
kube_pod(name: 'other-pod').tap do |pod|
pod['metadata']['annotations'].delete('app.gitlab.com/env')
pod['metadata']['annotations'].delete('app.gitlab.com/app')
pod['metadata']['labels']['app'] = environment.slug
end
end
let(:deployments) { [other_deployment] }
let(:pods) { [other_pod] }
it 'does not have the has_legacy_app_label flag' do
expect(rollout_status).not_to be_has_legacy_app_label
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment