Commit 7509f6bf authored by Dylan Griffith's avatar Dylan Griffith

Merge branch 'ak/fix-multi-pod' into 'master'

Fix access to logs when multiple pods exist

See merge request gitlab-org/gitlab!27008
parents 91e7ea3e 49de2bda
......@@ -43,7 +43,7 @@ module PodLogs
end
def check_container_name(result)
pod_details = result[:raw_pods].first { |p| p.metadata.name == result[:pod_name] }
pod_details = result[:raw_pods].find { |p| p.metadata.name == result[:pod_name] }
containers = pod_details.spec.containers.map(&:name)
# select first container if not specified
......
---
title: Fix access to logs when multiple pods exist
merge_request: 27008
author:
type: fixed
......@@ -9,11 +9,13 @@ describe ::PodLogs::BaseService do
let(:namespace) { 'autodevops-deploy-9-production' }
let(:pod_name) { 'pod-1' }
let(:pod_name_2) { 'pod-2' }
let(:container_name) { 'container-0' }
let(:params) { {} }
let(:raw_pods) do
JSON.parse([
kube_pod(name: pod_name)
kube_pod(name: pod_name),
kube_pod(name: pod_name_2)
].to_json, object_class: OpenStruct)
end
......@@ -115,7 +117,7 @@ describe ::PodLogs::BaseService do
result = subject.send(:get_pod_names, raw_pods: raw_pods)
expect(result[:status]).to eq(:success)
expect(result[:pods]).to eq([pod_name])
expect(result[:pods]).to eq([pod_name, pod_name_2])
end
end
end
......@@ -9,16 +9,20 @@ describe ::PodLogs::KubernetesService do
let(:namespace) { 'autodevops-deploy-9-production' }
let(:pod_name) { 'pod-1' }
let(:pod_name_2) { 'pod-2' }
let(:container_name) { 'container-0' }
let(:container_name_2) { 'foo-0' }
let(:params) { {} }
let(:raw_logs) do
"2019-12-13T14:04:22.123456Z Log 1\n2019-12-13T14:04:23.123456Z Log 2\n" \
"2019-12-13T14:04:24.123456Z Log 3"
end
let(:raw_pods) do
JSON.parse([
kube_pod(name: pod_name)
kube_pod(name: pod_name),
kube_pod(name: pod_name_2, container_name: container_name_2)
].to_json, object_class: OpenStruct)
end
......@@ -220,12 +224,12 @@ describe ::PodLogs::KubernetesService do
it 'returns success if container_name was not specified and there are containers' do
result = subject.send(:check_container_name,
pod_name: pod_name,
pod_name: pod_name_2,
raw_pods: raw_pods
)
expect(result[:status]).to eq(:success)
expect(result[:container_name]).to eq(container_name)
expect(result[:container_name]).to eq(container_name_2)
end
it 'returns error if container_name was not specified and there are no containers on the pod' do
......
......@@ -489,7 +489,7 @@ module KubernetesHelpers
# This is a partial response, it will have many more elements in reality but
# these are the ones we care about at the moment
def kube_pod(name: "kube-pod", environment_slug: "production", namespace: "project-namespace", project_slug: "project-path-slug", status: "Running", track: nil)
def kube_pod(name: "kube-pod", container_name: "container-0", environment_slug: "production", namespace: "project-namespace", project_slug: "project-path-slug", status: "Running", track: nil)
{
"metadata" => {
"name" => name,
......@@ -506,8 +506,8 @@ module KubernetesHelpers
},
"spec" => {
"containers" => [
{ "name" => "container-0" },
{ "name" => "container-1" }
{ "name" => "#{container_name}" },
{ "name" => "#{container_name}-1" }
]
},
"status" => { "phase" => status }
......
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