Commit 4b57dfad authored by Stan Hu's avatar Stan Hu

Fix 500 error loading environments index

Previously loading the environments index page would show a 500 error
when two conditions were met:

1. The associated cluster deployment had no pods
2. Reactive caching has cached the state of the deployment data.

Previously the filtering of pods by project environment were only run if
there were pods present, but this special case isn't needed as the
filter already handles empty arrays.

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/216118
parent d597839a
---
title: Fix 500 error loading environments index
merge_request: 31184
author:
type: fixed
......@@ -25,8 +25,7 @@ module EE
project = environment.project
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?
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: pods, legacy_deployments: legacy_deployments)
......
......@@ -67,6 +67,17 @@ describe Clusters::Platforms::Kubernetes do
end
end
context 'deployment with no pods' do
let(:deployment) { kube_deployment(name: 'some-deployment', environment_slug: environment.slug, project_slug: project.full_path_slug) }
let(:deployments) { [deployment] }
let(:pods) { [] }
it 'returns a valid status with matching deployments' do
expect(rollout_status).to be_kind_of(::Gitlab::Kubernetes::RolloutStatus)
expect(rollout_status.deployments.map(&:name)).to contain_exactly('some-deployment')
end
end
context 'new deployment based on annotations' do
let(:matched_deployment) { kube_deployment(name: 'matched-deployment', environment_slug: environment.slug, project_slug: project.full_path_slug) }
let(:matched_pod) { kube_pod(environment_slug: environment.slug, project_slug: project.full_path_slug) }
......
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