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
b42cac69
Commit
b42cac69
authored
Jul 01, 2015
by
Zach Loafman
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #10519 from JanetKuo/kubectl-c
Enable -c for kubectl logs container arg
parents
03be2f3f
62b48835
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
11 deletions
+30
-11
kubectl
contrib/completions/bash/kubectl
+2
-0
kubectl_logs.md
docs/kubectl_logs.md
+3
-2
kubectl-logs.1
docs/man/man1/kubectl-logs.1
+4
-0
log.go
pkg/kubectl/cmd/log.go
+21
-9
No files found.
contrib/completions/bash/kubectl
View file @
b42cac69
...
@@ -428,6 +428,8 @@ _kubectl_logs()
...
@@ -428,6 +428,8 @@ _kubectl_logs()
flags_with_completion
=()
flags_with_completion
=()
flags_completion
=()
flags_completion
=()
flags+
=(
"--container="
)
two_word_flags+
=(
"-c"
)
flags+
=(
"--follow"
)
flags+
=(
"--follow"
)
flags+
=(
"-f"
)
flags+
=(
"-f"
)
flags+
=(
"--help"
)
flags+
=(
"--help"
)
...
...
docs/kubectl_logs.md
View file @
b42cac69
...
@@ -8,7 +8,7 @@ Print the logs for a container in a pod.
...
@@ -8,7 +8,7 @@ Print the logs for a container in a pod.
Print the logs for a container in a pod. If the pod has only one container, the container name is optional.
Print the logs for a container in a pod. If the pod has only one container, the container name is optional.
```
```
kubectl logs [-f] [-p] POD [CONTAINER]
kubectl logs [-f] [-p] POD [
-c
CONTAINER]
```
```
### Examples
### Examples
...
@@ -27,6 +27,7 @@ $ kubectl logs -f 123456-7890 ruby-container
...
@@ -27,6 +27,7 @@ $ kubectl logs -f 123456-7890 ruby-container
### Options
### Options
```
```
-c, --container="": Container name
-f, --follow=false: Specify if the logs should be streamed.
-f, --follow=false: Specify if the logs should be streamed.
-h, --help=false: help for logs
-h, --help=false: help for logs
--interactive=true: If true, prompt the user for input when required. Default true.
--interactive=true: If true, prompt the user for input when required. Default true.
...
@@ -65,6 +66,6 @@ $ kubectl logs -f 123456-7890 ruby-container
...
@@ -65,6 +66,6 @@ $ kubectl logs -f 123456-7890 ruby-container
### SEE ALSO
### SEE ALSO
*
[
kubectl
](
kubectl.md
)
- kubectl controls the Kubernetes cluster manager
*
[
kubectl
](
kubectl.md
)
- kubectl controls the Kubernetes cluster manager
###### Auto generated by spf13/cobra at 2015-0
5-21 20:24:03.0657868
5 +0000 UTC
###### Auto generated by spf13/cobra at 2015-0
6-30 16:27:32.98150772
5 +0000 UTC
[

]()
[

]()
docs/man/man1/kubectl-logs.1
View file @
b42cac69
...
@@ -18,6 +18,10 @@ Print the logs for a container in a pod. If the pod has only one container, the
...
@@ -18,6 +18,10 @@ Print the logs for a container in a pod. If the pod has only one container, the
.SH OPTIONS
.SH OPTIONS
.PP
.PP
\fB\-c\fP, \fB\-\-container\fP=""
Container name
.PP
\fB\-f\fP, \fB\-\-follow\fP=false
\fB\-f\fP, \fB\-\-follow\fP=false
Specify if the logs should be streamed.
Specify if the logs should be streamed.
...
...
pkg/kubectl/cmd/log.go
View file @
b42cac69
...
@@ -61,15 +61,20 @@ func selectContainer(pod *api.Pod, in io.Reader, out io.Writer) string {
...
@@ -61,15 +61,20 @@ func selectContainer(pod *api.Pod, in io.Reader, out io.Writer) string {
}
}
}
}
type
logParams
struct
{
containerName
string
}
// NewCmdLog creates a new pod log command
// NewCmdLog creates a new pod log command
func
NewCmdLog
(
f
*
cmdutil
.
Factory
,
out
io
.
Writer
)
*
cobra
.
Command
{
func
NewCmdLog
(
f
*
cmdutil
.
Factory
,
out
io
.
Writer
)
*
cobra
.
Command
{
params
:=
&
logParams
{}
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"logs [-f] [-p] POD [CONTAINER]"
,
Use
:
"logs [-f] [-p] POD [
-c
CONTAINER]"
,
Short
:
"Print the logs for a container in a pod."
,
Short
:
"Print the logs for a container in a pod."
,
Long
:
"Print the logs for a container in a pod. If the pod has only one container, the container name is optional."
,
Long
:
"Print the logs for a container in a pod. If the pod has only one container, the container name is optional."
,
Example
:
log_example
,
Example
:
log_example
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
err
:=
RunLog
(
f
,
out
,
cmd
,
args
)
err
:=
RunLog
(
f
,
out
,
cmd
,
args
,
params
)
cmdutil
.
CheckErr
(
err
)
cmdutil
.
CheckErr
(
err
)
},
},
Aliases
:
[]
string
{
"log"
},
Aliases
:
[]
string
{
"log"
},
...
@@ -77,11 +82,12 @@ func NewCmdLog(f *cmdutil.Factory, out io.Writer) *cobra.Command {
...
@@ -77,11 +82,12 @@ func NewCmdLog(f *cmdutil.Factory, out io.Writer) *cobra.Command {
cmd
.
Flags
()
.
BoolP
(
"follow"
,
"f"
,
false
,
"Specify if the logs should be streamed."
)
cmd
.
Flags
()
.
BoolP
(
"follow"
,
"f"
,
false
,
"Specify if the logs should be streamed."
)
cmd
.
Flags
()
.
Bool
(
"interactive"
,
true
,
"If true, prompt the user for input when required. Default true."
)
cmd
.
Flags
()
.
Bool
(
"interactive"
,
true
,
"If true, prompt the user for input when required. Default true."
)
cmd
.
Flags
()
.
BoolP
(
"previous"
,
"p"
,
false
,
"If true, print the logs for the previous instance of the container in a pod if it exists."
)
cmd
.
Flags
()
.
BoolP
(
"previous"
,
"p"
,
false
,
"If true, print the logs for the previous instance of the container in a pod if it exists."
)
cmd
.
Flags
()
.
StringVarP
(
&
params
.
containerName
,
"container"
,
"c"
,
""
,
"Container name"
)
return
cmd
return
cmd
}
}
// RunLog retrieves a pod log
// RunLog retrieves a pod log
func
RunLog
(
f
*
cmdutil
.
Factory
,
out
io
.
Writer
,
cmd
*
cobra
.
Command
,
args
[]
string
)
error
{
func
RunLog
(
f
*
cmdutil
.
Factory
,
out
io
.
Writer
,
cmd
*
cobra
.
Command
,
args
[]
string
,
p
*
logParams
)
error
{
if
len
(
os
.
Args
)
>
1
&&
os
.
Args
[
1
]
==
"log"
{
if
len
(
os
.
Args
)
>
1
&&
os
.
Args
[
1
]
==
"log"
{
printDeprecationWarning
(
"logs"
,
"log"
)
printDeprecationWarning
(
"logs"
,
"log"
)
}
}
...
@@ -111,13 +117,19 @@ func RunLog(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string
...
@@ -111,13 +117,19 @@ func RunLog(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string
}
}
var
container
string
var
container
string
if
len
(
args
)
==
1
{
if
cmdutil
.
GetFlagString
(
cmd
,
"container"
)
!=
""
{
if
len
(
pod
.
Spec
.
Containers
)
!=
1
{
// [-c CONTAINER]
return
fmt
.
Errorf
(
"POD %s has more than one container; please specify the container to print logs for"
,
pod
.
ObjectMeta
.
Name
)
container
=
p
.
containerName
}
container
=
pod
.
Spec
.
Containers
[
0
]
.
Name
}
else
{
}
else
{
container
=
args
[
1
]
// [CONTAINER] (container as arg not flag) is supported as legacy behavior. See PR #10519 for more details.
if
len
(
args
)
==
1
{
if
len
(
pod
.
Spec
.
Containers
)
!=
1
{
return
fmt
.
Errorf
(
"POD %s has more than one container; please specify the container to print logs for"
,
pod
.
ObjectMeta
.
Name
)
}
container
=
pod
.
Spec
.
Containers
[
0
]
.
Name
}
else
{
container
=
args
[
1
]
}
}
}
follow
:=
false
follow
:=
false
...
...
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