Commit 84f8862b authored by Thong Kuah's avatar Thong Kuah Committed by Enrique Alcantara

Select deployments that only has the app label

As Auto DevOps deployments both label and annotations, that will be
included in the deploy board so need to warn at all.
parent 49dd3dd3
......@@ -13,7 +13,7 @@ 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) if data[:pods]&.any?
legacy_deployments = filter_by_label(data[:deployments], { app: environment.slug })
legacy_deployments = filter_by_legacy_label(data[:deployments], project.full_path_slug, environment.slug)
::Gitlab::Kubernetes::RolloutStatus.from_deployments(*deployments, pods: pods, legacy_deployments: legacy_deployments)
end
......
......@@ -43,6 +43,14 @@ module Gitlab
})
end
def filter_by_legacy_label(items, app, env)
legacy_items = filter_by_label(items, { app: env })
non_legacy_items = filter_by_project_environment(legacy_items, app, env)
legacy_items - non_legacy_items
end
# Converts a pod (as returned by the kubernetes API) into a terminal
def terminals_for_pod(api_url, namespace, pod)
metadata = pod.fetch("metadata", {})
......
......@@ -67,6 +67,30 @@ describe Gitlab::Kubernetes do
end
end
describe '#filter_by_legacy_label' do
let(:non_matching_pod) { kube_pod(environment_slug: 'production', project_slug: 'my-cool-app') }
let(:non_matching_pod_2) do
kube_pod(environment_slug: 'production', project_slug: 'my-cool-app').tap do |pod|
pod['metadata']['labels']['app'] = 'production'
end
end
let(:matching_pod) do
kube_pod.tap do |pod|
pod['metadata']['annotations'].delete('app.gitlab.com/env')
pod['metadata']['annotations'].delete('app.gitlab.com/app')
pod['metadata']['labels']['app'] = 'production'
end
end
it 'returns matching labels' do
items = [non_matching_pod, non_matching_pod_2, matching_pod]
expect(filter_by_legacy_label(items, 'my-cool-app', 'production')).to contain_exactly(matching_pod)
end
end
describe '#to_kubeconfig' do
let(:token) { 'TOKEN' }
let(:ca_pem) { 'PEM' }
......
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