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
d8daa07f
Commit
d8daa07f
authored
May 11, 2016
by
Brendan Burns
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
address comments
parent
092afb62
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
16 deletions
+30
-16
clusterinfo.go
pkg/kubectl/cmd/clusterinfo.go
+5
-1
clusterinfo_dump.go
pkg/kubectl/cmd/clusterinfo_dump.go
+25
-15
No files found.
pkg/kubectl/cmd/clusterinfo.go
View file @
d8daa07f
...
@@ -30,13 +30,16 @@ import (
...
@@ -30,13 +30,16 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/cobra"
)
)
var
longDescr
=
`Display addresses of the master and services with label kubernetes.io/cluster-service=true
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.`
func
NewCmdClusterInfo
(
f
*
cmdutil
.
Factory
,
out
io
.
Writer
)
*
cobra
.
Command
{
func
NewCmdClusterInfo
(
f
*
cmdutil
.
Factory
,
out
io
.
Writer
)
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"cluster-info"
,
Use
:
"cluster-info"
,
// clusterinfo is deprecated.
// clusterinfo is deprecated.
Aliases
:
[]
string
{
"clusterinfo"
},
Aliases
:
[]
string
{
"clusterinfo"
},
Short
:
"Display cluster info"
,
Short
:
"Display cluster info"
,
Long
:
"Display addresses of the master and services with label kubernetes.io/cluster-service=true"
,
Long
:
longDescr
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
err
:=
RunClusterInfo
(
f
,
out
,
cmd
)
err
:=
RunClusterInfo
(
f
,
out
,
cmd
)
cmdutil
.
CheckErr
(
err
)
cmdutil
.
CheckErr
(
err
)
...
@@ -102,6 +105,7 @@ func RunClusterInfo(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command) error
...
@@ -102,6 +105,7 @@ func RunClusterInfo(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command) error
}
}
return
nil
return
nil
})
})
out
.
Write
([]
byte
(
"
\n
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
\n
"
))
return
nil
return
nil
// TODO consider printing more information about cluster
// TODO consider printing more information about cluster
...
...
pkg/kubectl/cmd/clusterinfo_dump.go
View file @
d8daa07f
...
@@ -35,7 +35,7 @@ func NewCmdClusterInfoDump(f *cmdutil.Factory, cmdOut io.Writer) *cobra.Command
...
@@ -35,7 +35,7 @@ func NewCmdClusterInfoDump(f *cmdutil.Factory, cmdOut io.Writer) *cobra.Command
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"dump"
,
Use
:
"dump"
,
Short
:
"Dump lots of relevant info for debugging and diagnosis."
,
Short
:
"Dump lots of relevant info for debugging and diagnosis."
,
Long
:
dumpLong
,
Long
:
dumpLong
+
"
\n
"
+
dumpExample
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
cmdutil
.
CheckErr
(
dumpClusterInfo
(
f
,
cmd
,
args
,
cmdOut
))
cmdutil
.
CheckErr
(
dumpClusterInfo
(
f
,
cmd
,
args
,
cmdOut
))
},
},
...
@@ -52,22 +52,25 @@ Dumps cluster info out suitable for debugging and diagnosing cluster problems.
...
@@ -52,22 +52,25 @@ Dumps cluster info out suitable for debugging and diagnosing cluster problems.
stdout. You can optionally specify a directory with --output-directory. If you specify a directory, kubernetes will
stdout. You can optionally specify a directory with --output-directory. If you specify a directory, kubernetes will
build a set of files in that directory. By default only dumps things in the 'kube-system' namespace, but you can
build a set of files in that directory. By default only dumps things in the 'kube-system' namespace, but you can
switch to a different namespace with the --namespaces flag, or specify --all-namespaces to dump all namespaces.
switch to a different namespace with the --namespaces flag, or specify --all-namespaces to dump all namespaces.
The command also dumps the logs of all of the pods in the cluster, these logs are dumped into different directories
based on namespace and pod name.
`
`
dumpExample
=
` # Dump current cluster state to stdout
dumpExample
=
` # Dump current cluster state to stdout
kubectl cluster-info dump
kubectl cluster-info dump
# Dump current cluster state to /
tmp
# Dump current cluster state to /
path/to/cluster-state
kubectl cluster-info dump --output-directory=/
tmp
kubectl cluster-info dump --output-directory=/
path/to/cluster-state
# Dump all namespaces to stdout
# Dump all namespaces to stdout
kubectl cluster-info dump --all-namespaces
kubectl cluster-info dump --all-namespaces
# Dump a set of namespaces to /
tmp
# Dump a set of namespaces to /
path/to/cluster-state
kubectl cluster-info dump --namespaces default,kube-system --output-directory=/
tmp
`
kubectl cluster-info dump --namespaces default,kube-system --output-directory=/
path/to/cluster-state
`
)
)
func
ge
tWriter
(
cmd
*
cobra
.
Command
,
defaultWriter
io
.
Writer
,
filename
string
)
io
.
Writer
{
func
setupOutpu
tWriter
(
cmd
*
cobra
.
Command
,
defaultWriter
io
.
Writer
,
filename
string
)
io
.
Writer
{
dir
:=
cmdutil
.
GetFlagString
(
cmd
,
"output-directory"
)
dir
:=
cmdutil
.
GetFlagString
(
cmd
,
"output-directory"
)
if
len
(
dir
)
==
0
||
dir
==
"-"
{
if
len
(
dir
)
==
0
||
dir
==
"-"
{
return
defaultWriter
return
defaultWriter
...
@@ -97,7 +100,7 @@ func dumpClusterInfo(f *cmdutil.Factory, cmd *cobra.Command, args []string, out
...
@@ -97,7 +100,7 @@ func dumpClusterInfo(f *cmdutil.Factory, cmd *cobra.Command, args []string, out
return
err
return
err
}
}
if
err
:=
printer
.
PrintObj
(
nodes
,
ge
tWriter
(
cmd
,
out
,
"nodes.json"
));
err
!=
nil
{
if
err
:=
printer
.
PrintObj
(
nodes
,
setupOutpu
tWriter
(
cmd
,
out
,
"nodes.json"
));
err
!=
nil
{
return
err
return
err
}
}
...
@@ -130,7 +133,7 @@ func dumpClusterInfo(f *cmdutil.Factory, cmd *cobra.Command, args []string, out
...
@@ -130,7 +133,7 @@ func dumpClusterInfo(f *cmdutil.Factory, cmd *cobra.Command, args []string, out
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
if
err
:=
printer
.
PrintObj
(
events
,
ge
tWriter
(
cmd
,
out
,
path
.
Join
(
namespace
,
"events.json"
)));
err
!=
nil
{
if
err
:=
printer
.
PrintObj
(
events
,
setupOutpu
tWriter
(
cmd
,
out
,
path
.
Join
(
namespace
,
"events.json"
)));
err
!=
nil
{
return
err
return
err
}
}
...
@@ -138,7 +141,7 @@ func dumpClusterInfo(f *cmdutil.Factory, cmd *cobra.Command, args []string, out
...
@@ -138,7 +141,7 @@ func dumpClusterInfo(f *cmdutil.Factory, cmd *cobra.Command, args []string, out
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
if
err
:=
printer
.
PrintObj
(
rcs
,
ge
tWriter
(
cmd
,
out
,
path
.
Join
(
namespace
,
"replication-controllers.json"
)));
err
!=
nil
{
if
err
:=
printer
.
PrintObj
(
rcs
,
setupOutpu
tWriter
(
cmd
,
out
,
path
.
Join
(
namespace
,
"replication-controllers.json"
)));
err
!=
nil
{
return
err
return
err
}
}
...
@@ -146,7 +149,7 @@ func dumpClusterInfo(f *cmdutil.Factory, cmd *cobra.Command, args []string, out
...
@@ -146,7 +149,7 @@ func dumpClusterInfo(f *cmdutil.Factory, cmd *cobra.Command, args []string, out
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
if
err
:=
printer
.
PrintObj
(
svcs
,
ge
tWriter
(
cmd
,
out
,
path
.
Join
(
namespace
,
"services.json"
)));
err
!=
nil
{
if
err
:=
printer
.
PrintObj
(
svcs
,
setupOutpu
tWriter
(
cmd
,
out
,
path
.
Join
(
namespace
,
"services.json"
)));
err
!=
nil
{
return
err
return
err
}
}
...
@@ -154,7 +157,7 @@ func dumpClusterInfo(f *cmdutil.Factory, cmd *cobra.Command, args []string, out
...
@@ -154,7 +157,7 @@ func dumpClusterInfo(f *cmdutil.Factory, cmd *cobra.Command, args []string, out
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
if
err
:=
printer
.
PrintObj
(
sets
,
ge
tWriter
(
cmd
,
out
,
path
.
Join
(
namespace
,
"daemonsets.json"
)));
err
!=
nil
{
if
err
:=
printer
.
PrintObj
(
sets
,
setupOutpu
tWriter
(
cmd
,
out
,
path
.
Join
(
namespace
,
"daemonsets.json"
)));
err
!=
nil
{
return
err
return
err
}
}
...
@@ -162,7 +165,7 @@ func dumpClusterInfo(f *cmdutil.Factory, cmd *cobra.Command, args []string, out
...
@@ -162,7 +165,7 @@ func dumpClusterInfo(f *cmdutil.Factory, cmd *cobra.Command, args []string, out
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
if
err
:=
printer
.
PrintObj
(
deps
,
ge
tWriter
(
cmd
,
out
,
path
.
Join
(
namespace
,
"deployments.json"
)));
err
!=
nil
{
if
err
:=
printer
.
PrintObj
(
deps
,
setupOutpu
tWriter
(
cmd
,
out
,
path
.
Join
(
namespace
,
"deployments.json"
)));
err
!=
nil
{
return
err
return
err
}
}
...
@@ -170,7 +173,7 @@ func dumpClusterInfo(f *cmdutil.Factory, cmd *cobra.Command, args []string, out
...
@@ -170,7 +173,7 @@ func dumpClusterInfo(f *cmdutil.Factory, cmd *cobra.Command, args []string, out
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
if
err
:=
printer
.
PrintObj
(
rps
,
ge
tWriter
(
cmd
,
out
,
path
.
Join
(
namespace
,
"replicasets.json"
)));
err
!=
nil
{
if
err
:=
printer
.
PrintObj
(
rps
,
setupOutpu
tWriter
(
cmd
,
out
,
path
.
Join
(
namespace
,
"replicasets.json"
)));
err
!=
nil
{
return
err
return
err
}
}
...
@@ -179,13 +182,13 @@ func dumpClusterInfo(f *cmdutil.Factory, cmd *cobra.Command, args []string, out
...
@@ -179,13 +182,13 @@ func dumpClusterInfo(f *cmdutil.Factory, cmd *cobra.Command, args []string, out
return
err
return
err
}
}
if
err
:=
printer
.
PrintObj
(
pods
,
ge
tWriter
(
cmd
,
out
,
path
.
Join
(
namespace
,
"pods.json"
)));
err
!=
nil
{
if
err
:=
printer
.
PrintObj
(
pods
,
setupOutpu
tWriter
(
cmd
,
out
,
path
.
Join
(
namespace
,
"pods.json"
)));
err
!=
nil
{
return
err
return
err
}
}
for
ix
:=
range
pods
.
Items
{
for
ix
:=
range
pods
.
Items
{
pod
:=
&
pods
.
Items
[
ix
]
pod
:=
&
pods
.
Items
[
ix
]
writer
:=
ge
tWriter
(
cmd
,
out
,
path
.
Join
(
namespace
,
pod
.
Name
,
"logs.txt"
))
writer
:=
setupOutpu
tWriter
(
cmd
,
out
,
path
.
Join
(
namespace
,
pod
.
Name
,
"logs.txt"
))
writer
.
Write
([]
byte
(
fmt
.
Sprintf
(
"==== START logs for %s/%s ====
\n
"
,
pod
.
Namespace
,
pod
.
Name
)))
writer
.
Write
([]
byte
(
fmt
.
Sprintf
(
"==== START logs for %s/%s ====
\n
"
,
pod
.
Namespace
,
pod
.
Name
)))
request
,
err
:=
f
.
LogsForObject
(
pod
,
&
api
.
PodLogOptions
{})
request
,
err
:=
f
.
LogsForObject
(
pod
,
&
api
.
PodLogOptions
{})
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -200,5 +203,12 @@ func dumpClusterInfo(f *cmdutil.Factory, cmd *cobra.Command, args []string, out
...
@@ -200,5 +203,12 @@ func dumpClusterInfo(f *cmdutil.Factory, cmd *cobra.Command, args []string, out
writer
.
Write
([]
byte
(
fmt
.
Sprintf
(
"==== END logs for %s/%s ====
\n
"
,
pod
.
Namespace
,
pod
.
Name
)))
writer
.
Write
([]
byte
(
fmt
.
Sprintf
(
"==== END logs for %s/%s ====
\n
"
,
pod
.
Namespace
,
pod
.
Name
)))
}
}
}
}
dir
:=
cmdutil
.
GetFlagString
(
cmd
,
"output-directory"
)
if
len
(
dir
)
==
0
{
dir
=
"."
}
if
dir
!=
"-"
{
fmt
.
Fprintf
(
out
,
"Cluster info dumped to %s"
,
dir
)
}
return
nil
return
nil
}
}
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