Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
e5009bfd
Commit
e5009bfd
authored
Feb 08, 2016
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #19474 from endocode/container_names_in_kubectl_logs
Auto commit by PR queue bot
parents
c75e344b
6cd10d4f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
5 deletions
+23
-5
strategy.go
pkg/registry/pod/strategy.go
+22
-4
strategy_test.go
pkg/registry/pod/strategy_test.go
+1
-1
No files found.
pkg/registry/pod/strategy.go
View file @
e5009bfd
...
@@ -22,6 +22,7 @@ import (
...
@@ -22,6 +22,7 @@ import (
"net/http"
"net/http"
"net/url"
"net/url"
"strconv"
"strconv"
"strings"
"time"
"time"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
...
@@ -231,6 +232,15 @@ func ResourceLocation(getter ResourceGetter, rt http.RoundTripper, ctx api.Conte
...
@@ -231,6 +232,15 @@ func ResourceLocation(getter ResourceGetter, rt http.RoundTripper, ctx api.Conte
return
loc
,
rt
,
nil
return
loc
,
rt
,
nil
}
}
// getContainerNames returns a formatted string containing the container names
func
getContainerNames
(
pod
*
api
.
Pod
)
string
{
names
:=
[]
string
{}
for
_
,
c
:=
range
pod
.
Spec
.
Containers
{
names
=
append
(
names
,
c
.
Name
)
}
return
strings
.
Join
(
names
,
" "
)
}
// LogLocation returns the log URL for a pod container. If opts.Container is blank
// LogLocation returns the log URL for a pod container. If opts.Container is blank
// and only one container is present in the pod, that container is used.
// and only one container is present in the pod, that container is used.
func
LogLocation
(
func
LogLocation
(
...
@@ -249,10 +259,14 @@ func LogLocation(
...
@@ -249,10 +259,14 @@ func LogLocation(
// If a container was provided, it must be valid
// If a container was provided, it must be valid
container
:=
opts
.
Container
container
:=
opts
.
Container
if
len
(
container
)
==
0
{
if
len
(
container
)
==
0
{
if
len
(
pod
.
Spec
.
Containers
)
==
1
{
switch
len
(
pod
.
Spec
.
Containers
)
{
case
1
:
container
=
pod
.
Spec
.
Containers
[
0
]
.
Name
container
=
pod
.
Spec
.
Containers
[
0
]
.
Name
}
else
{
case
0
:
return
nil
,
nil
,
errors
.
NewBadRequest
(
fmt
.
Sprintf
(
"a container name must be specified for pod %s"
,
name
))
return
nil
,
nil
,
errors
.
NewBadRequest
(
fmt
.
Sprintf
(
"a container name must be specified for pod %s"
,
name
))
default
:
containerNames
:=
getContainerNames
(
pod
)
return
nil
,
nil
,
errors
.
NewBadRequest
(
fmt
.
Sprintf
(
"a container name must be specified for pod %s, choose one of: [%s]"
,
name
,
containerNames
))
}
}
}
else
{
}
else
{
if
!
podHasContainerWithName
(
pod
,
container
)
{
if
!
podHasContainerWithName
(
pod
,
container
)
{
...
@@ -386,10 +400,14 @@ func streamLocation(
...
@@ -386,10 +400,14 @@ func streamLocation(
// Try to figure out a container
// Try to figure out a container
// If a container was provided, it must be valid
// If a container was provided, it must be valid
if
container
==
""
{
if
container
==
""
{
if
len
(
pod
.
Spec
.
Containers
)
==
1
{
switch
len
(
pod
.
Spec
.
Containers
)
{
case
1
:
container
=
pod
.
Spec
.
Containers
[
0
]
.
Name
container
=
pod
.
Spec
.
Containers
[
0
]
.
Name
}
else
{
case
0
:
return
nil
,
nil
,
errors
.
NewBadRequest
(
fmt
.
Sprintf
(
"a container name must be specified for pod %s"
,
name
))
return
nil
,
nil
,
errors
.
NewBadRequest
(
fmt
.
Sprintf
(
"a container name must be specified for pod %s"
,
name
))
default
:
containerNames
:=
getContainerNames
(
pod
)
return
nil
,
nil
,
errors
.
NewBadRequest
(
fmt
.
Sprintf
(
"a container name must be specified for pod %s, choose one of: [%s]"
,
name
,
containerNames
))
}
}
}
else
{
}
else
{
if
!
podHasContainerWithName
(
pod
,
container
)
{
if
!
podHasContainerWithName
(
pod
,
container
)
{
...
...
pkg/registry/pod/strategy_test.go
View file @
e5009bfd
...
@@ -129,7 +129,7 @@ func TestCheckLogLocation(t *testing.T) {
...
@@ -129,7 +129,7 @@ func TestCheckLogLocation(t *testing.T) {
Status
:
api
.
PodStatus
{},
Status
:
api
.
PodStatus
{},
},
},
opts
:
&
api
.
PodLogOptions
{},
opts
:
&
api
.
PodLogOptions
{},
expectedErr
:
errors
.
NewBadRequest
(
"a container name must be specified for pod test"
),
expectedErr
:
errors
.
NewBadRequest
(
"a container name must be specified for pod test
, choose one of: [container1 container2]
"
),
},
},
{
{
in
:
&
api
.
Pod
{
in
:
&
api
.
Pod
{
...
...
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