Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
49de2bda
Commit
49de2bda
authored
Mar 18, 2020
by
Adrien Kohlbecker
Committed by
Dylan Griffith
Mar 18, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix access to logs when multiple pods exist
parent
479fa52d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
20 additions
and
9 deletions
+20
-9
app/services/pod_logs/kubernetes_service.rb
app/services/pod_logs/kubernetes_service.rb
+1
-1
changelogs/unreleased/ak-fix-multi-pod.yml
changelogs/unreleased/ak-fix-multi-pod.yml
+5
-0
spec/services/pod_logs/base_service_spec.rb
spec/services/pod_logs/base_service_spec.rb
+4
-2
spec/services/pod_logs/kubernetes_service_spec.rb
spec/services/pod_logs/kubernetes_service_spec.rb
+7
-3
spec/support/helpers/kubernetes_helpers.rb
spec/support/helpers/kubernetes_helpers.rb
+3
-3
No files found.
app/services/pod_logs/kubernetes_service.rb
View file @
49de2bda
...
@@ -43,7 +43,7 @@ module PodLogs
...
@@ -43,7 +43,7 @@ module PodLogs
end
end
def
check_container_name
(
result
)
def
check_container_name
(
result
)
pod_details
=
result
[
:raw_pods
].
fi
rst
{
|
p
|
p
.
metadata
.
name
==
result
[
:pod_name
]
}
pod_details
=
result
[
:raw_pods
].
fi
nd
{
|
p
|
p
.
metadata
.
name
==
result
[
:pod_name
]
}
containers
=
pod_details
.
spec
.
containers
.
map
(
&
:name
)
containers
=
pod_details
.
spec
.
containers
.
map
(
&
:name
)
# select first container if not specified
# select first container if not specified
...
...
changelogs/unreleased/ak-fix-multi-pod.yml
0 → 100644
View file @
49de2bda
---
title
:
Fix access to logs when multiple pods exist
merge_request
:
27008
author
:
type
:
fixed
spec/services/pod_logs/base_service_spec.rb
View file @
49de2bda
...
@@ -9,11 +9,13 @@ describe ::PodLogs::BaseService do
...
@@ -9,11 +9,13 @@ describe ::PodLogs::BaseService do
let
(
:namespace
)
{
'autodevops-deploy-9-production'
}
let
(
:namespace
)
{
'autodevops-deploy-9-production'
}
let
(
:pod_name
)
{
'pod-1'
}
let
(
:pod_name
)
{
'pod-1'
}
let
(
:pod_name_2
)
{
'pod-2'
}
let
(
:container_name
)
{
'container-0'
}
let
(
:container_name
)
{
'container-0'
}
let
(
:params
)
{
{}
}
let
(
:params
)
{
{}
}
let
(
:raw_pods
)
do
let
(
:raw_pods
)
do
JSON
.
parse
([
JSON
.
parse
([
kube_pod
(
name:
pod_name
)
kube_pod
(
name:
pod_name
),
kube_pod
(
name:
pod_name_2
)
].
to_json
,
object_class:
OpenStruct
)
].
to_json
,
object_class:
OpenStruct
)
end
end
...
@@ -115,7 +117,7 @@ describe ::PodLogs::BaseService do
...
@@ -115,7 +117,7 @@ describe ::PodLogs::BaseService do
result
=
subject
.
send
(
:get_pod_names
,
raw_pods:
raw_pods
)
result
=
subject
.
send
(
:get_pod_names
,
raw_pods:
raw_pods
)
expect
(
result
[
:status
]).
to
eq
(
:success
)
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
end
end
end
spec/services/pod_logs/kubernetes_service_spec.rb
View file @
49de2bda
...
@@ -9,16 +9,20 @@ describe ::PodLogs::KubernetesService do
...
@@ -9,16 +9,20 @@ describe ::PodLogs::KubernetesService do
let
(
:namespace
)
{
'autodevops-deploy-9-production'
}
let
(
:namespace
)
{
'autodevops-deploy-9-production'
}
let
(
:pod_name
)
{
'pod-1'
}
let
(
:pod_name
)
{
'pod-1'
}
let
(
:pod_name_2
)
{
'pod-2'
}
let
(
:container_name
)
{
'container-0'
}
let
(
:container_name
)
{
'container-0'
}
let
(
:container_name_2
)
{
'foo-0'
}
let
(
:params
)
{
{}
}
let
(
:params
)
{
{}
}
let
(
:raw_logs
)
do
let
(
:raw_logs
)
do
"2019-12-13T14:04:22.123456Z Log 1
\n
2019-12-13T14:04:23.123456Z Log 2
\n
"
\
"2019-12-13T14:04:22.123456Z Log 1
\n
2019-12-13T14:04:23.123456Z Log 2
\n
"
\
"2019-12-13T14:04:24.123456Z Log 3"
"2019-12-13T14:04:24.123456Z Log 3"
end
end
let
(
:raw_pods
)
do
let
(
:raw_pods
)
do
JSON
.
parse
([
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
)
].
to_json
,
object_class:
OpenStruct
)
end
end
...
@@ -220,12 +224,12 @@ describe ::PodLogs::KubernetesService do
...
@@ -220,12 +224,12 @@ describe ::PodLogs::KubernetesService do
it
'returns success if container_name was not specified and there are containers'
do
it
'returns success if container_name was not specified and there are containers'
do
result
=
subject
.
send
(
:check_container_name
,
result
=
subject
.
send
(
:check_container_name
,
pod_name:
pod_name
,
pod_name:
pod_name
_2
,
raw_pods:
raw_pods
raw_pods:
raw_pods
)
)
expect
(
result
[
:status
]).
to
eq
(
:success
)
expect
(
result
[
:status
]).
to
eq
(
:success
)
expect
(
result
[
:container_name
]).
to
eq
(
container_name
)
expect
(
result
[
:container_name
]).
to
eq
(
container_name
_2
)
end
end
it
'returns error if container_name was not specified and there are no containers on the pod'
do
it
'returns error if container_name was not specified and there are no containers on the pod'
do
...
...
spec/support/helpers/kubernetes_helpers.rb
View file @
49de2bda
...
@@ -489,7 +489,7 @@ module KubernetesHelpers
...
@@ -489,7 +489,7 @@ module KubernetesHelpers
# This is a partial response, it will have many more elements in reality but
# This is a partial response, it will have many more elements in reality but
# these are the ones we care about at the moment
# 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"
=>
{
"metadata"
=>
{
"name"
=>
name
,
"name"
=>
name
,
...
@@ -506,8 +506,8 @@ module KubernetesHelpers
...
@@ -506,8 +506,8 @@ module KubernetesHelpers
},
},
"spec"
=>
{
"spec"
=>
{
"containers"
=>
[
"containers"
=>
[
{
"name"
=>
"
container-0
"
},
{
"name"
=>
"
#{
container_name
}
"
},
{
"name"
=>
"
container
-1"
}
{
"name"
=>
"
#{
container_name
}
-1"
}
]
]
},
},
"status"
=>
{
"phase"
=>
status
}
"status"
=>
{
"phase"
=>
status
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment