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
9723ff7f
Commit
9723ff7f
authored
Dec 13, 2015
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #12043 from derekwaynecarr/describe_node
Auto commit by PR queue bot
parents
c458cd7b
9cdeb4cb
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
22 deletions
+29
-22
describe.go
pkg/kubectl/describe.go
+25
-20
describe_test.go
pkg/kubectl/describe_test.go
+4
-2
No files found.
pkg/kubectl/describe.go
View file @
9723ff7f
...
...
@@ -27,6 +27,7 @@ import (
"github.com/golang/glog"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/apis/extensions"
...
...
@@ -1312,17 +1313,19 @@ func (d *NodeDescriber) Describe(namespace, name string) (string, error) {
return
""
,
err
}
var
pods
[]
*
api
.
Pod
allPods
,
err
:=
d
.
Pods
(
namespace
)
.
List
(
unversioned
.
ListOptions
{})
fieldSelector
,
err
:=
fields
.
ParseSelector
(
"spec.nodeName="
+
name
+
",status.phase!="
+
string
(
api
.
PodSucceeded
)
+
",status.phase!="
+
string
(
api
.
PodFailed
))
if
err
!=
nil
{
return
""
,
err
}
for
i
:=
range
allPods
.
Items
{
pod
:=
&
allPods
.
Items
[
i
]
if
pod
.
Spec
.
NodeName
!=
name
{
continue
// in a policy aware setting, users may have access to a node, but not all pods
// in that case, we note that the user does not have access to the pods
canViewPods
:=
true
nodeNonTerminatedPodsList
,
err
:=
d
.
Pods
(
namespace
)
.
List
(
unversioned
.
ListOptions
{
FieldSelector
:
unversioned
.
FieldSelector
{
fieldSelector
}})
if
err
!=
nil
{
if
!
errors
.
IsForbidden
(
err
)
{
return
""
,
err
}
pods
=
append
(
pods
,
pod
)
canViewPods
=
false
}
var
events
*
api
.
EventList
...
...
@@ -1334,10 +1337,10 @@ func (d *NodeDescriber) Describe(namespace, name string) (string, error) {
events
,
_
=
d
.
Events
(
""
)
.
Search
(
ref
)
}
return
describeNode
(
node
,
pods
,
event
s
)
return
describeNode
(
node
,
nodeNonTerminatedPodsList
,
events
,
canViewPod
s
)
}
func
describeNode
(
node
*
api
.
Node
,
pods
[]
*
api
.
Pod
,
events
*
api
.
EventList
)
(
string
,
error
)
{
func
describeNode
(
node
*
api
.
Node
,
nodeNonTerminatedPodsList
*
api
.
PodList
,
events
*
api
.
EventList
,
canViewPods
bool
)
(
string
,
error
)
{
return
tabbedString
(
func
(
out
io
.
Writer
)
error
{
fmt
.
Fprintf
(
out
,
"Name:
\t
%s
\n
"
,
node
.
Name
)
fmt
.
Fprintf
(
out
,
"Labels:
\t
%s
\n
"
,
labels
.
FormatLabels
(
node
.
Labels
))
...
...
@@ -1384,10 +1387,13 @@ func describeNode(node *api.Node, pods []*api.Pod, events *api.EventList) (strin
if
len
(
node
.
Spec
.
ExternalID
)
>
0
{
fmt
.
Fprintf
(
out
,
"ExternalID:
\t
%s
\n
"
,
node
.
Spec
.
ExternalID
)
}
if
err
:=
describeNodeResource
(
pods
,
node
,
out
);
err
!=
nil
{
if
canViewPods
&&
nodeNonTerminatedPodsList
!=
nil
{
if
err
:=
describeNodeResource
(
nodeNonTerminatedPodsList
,
node
,
out
);
err
!=
nil
{
return
err
}
}
else
{
fmt
.
Fprintf
(
out
,
"Pods:
\t
not authorized
\n
"
)
}
if
events
!=
nil
{
DescribeEvents
(
events
,
out
)
}
...
...
@@ -1444,13 +1450,12 @@ func (d *HorizontalPodAutoscalerDescriber) Describe(namespace, name string) (str
})
}
func
describeNodeResource
(
pods
[]
*
api
.
Pod
,
node
*
api
.
Node
,
out
io
.
Writer
)
error
{
nonTerminatedPods
:=
filterTerminatedPods
(
pods
)
fmt
.
Fprintf
(
out
,
"Non-terminated Pods:
\t
(%d in total)
\n
"
,
len
(
nonTerminatedPods
))
func
describeNodeResource
(
nodeNonTerminatedPodsList
*
api
.
PodList
,
node
*
api
.
Node
,
out
io
.
Writer
)
error
{
fmt
.
Fprintf
(
out
,
"Non-terminated Pods:
\t
(%d in total)
\n
"
,
len
(
nodeNonTerminatedPodsList
.
Items
))
fmt
.
Fprint
(
out
,
" Namespace
\t
Name
\t\t
CPU Requests
\t
CPU Limits
\t
Memory Requests
\t
Memory Limits
\n
"
)
fmt
.
Fprint
(
out
,
" ---------
\t
----
\t\t
------------
\t
----------
\t
---------------
\t
-------------
\n
"
)
for
_
,
pod
:=
range
no
nTerminatedPod
s
{
req
,
limit
,
err
:=
api
.
PodRequestsAndLimits
(
pod
)
for
_
,
pod
:=
range
no
deNonTerminatedPodsList
.
Item
s
{
req
,
limit
,
err
:=
api
.
PodRequestsAndLimits
(
&
pod
)
if
err
!=
nil
{
return
err
}
...
...
@@ -1466,7 +1471,7 @@ func describeNodeResource(pods []*api.Pod, node *api.Node, out io.Writer) error
fmt
.
Fprint
(
out
,
"Allocated resources:
\n
(Total limits may be over 100%, i.e., overcommitted. More info: http://releases.k8s.io/HEAD/docs/user-guide/compute-resources.md)
\n
CPU Requests
\t
CPU Limits
\t
Memory Requests
\t
Memory Limits
\n
"
)
fmt
.
Fprint
(
out
,
" ------------
\t
----------
\t
---------------
\t
-------------
\n
"
)
reqs
,
limits
,
err
:=
getPodsTotalRequestsAndLimits
(
no
nTerminatedPods
)
reqs
,
limits
,
err
:=
getPodsTotalRequestsAndLimits
(
no
deNonTerminatedPodsList
)
if
err
!=
nil
{
return
err
}
...
...
@@ -1495,10 +1500,10 @@ func filterTerminatedPods(pods []*api.Pod) []*api.Pod {
return
result
}
func
getPodsTotalRequestsAndLimits
(
pod
s
[]
*
api
.
Pod
)
(
reqs
map
[
api
.
ResourceName
]
resource
.
Quantity
,
limits
map
[
api
.
ResourceName
]
resource
.
Quantity
,
err
error
)
{
func
getPodsTotalRequestsAndLimits
(
pod
List
*
api
.
PodList
)
(
reqs
map
[
api
.
ResourceName
]
resource
.
Quantity
,
limits
map
[
api
.
ResourceName
]
resource
.
Quantity
,
err
error
)
{
reqs
,
limits
=
map
[
api
.
ResourceName
]
resource
.
Quantity
{},
map
[
api
.
ResourceName
]
resource
.
Quantity
{}
for
_
,
pod
:=
range
pods
{
podReqs
,
podLimits
,
err
:=
api
.
PodRequestsAndLimits
(
pod
)
for
_
,
pod
:=
range
pod
List
.
Item
s
{
podReqs
,
podLimits
,
err
:=
api
.
PodRequestsAndLimits
(
&
pod
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
...
...
pkg/kubectl/describe_test.go
View file @
9723ff7f
...
...
@@ -359,11 +359,12 @@ func TestDefaultDescribers(t *testing.T) {
func
TestGetPodsTotalRequests
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
pods
[]
*
api
.
Pod
pods
*
api
.
PodList
expectedReqs
,
expectedLimits
map
[
api
.
ResourceName
]
resource
.
Quantity
}{
{
pods
:
[]
*
api
.
Pod
{
pods
:
&
api
.
PodList
{
Items
:
[]
api
.
Pod
{
{
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
...
...
@@ -413,6 +414,7 @@ func TestGetPodsTotalRequests(t *testing.T) {
},
},
},
},
expectedReqs
:
map
[
api
.
ResourceName
]
resource
.
Quantity
{
api
.
ResourceName
(
api
.
ResourceCPU
)
:
resource
.
MustParse
(
"1.184"
),
api
.
ResourceName
(
api
.
ResourceMemory
)
:
resource
.
MustParse
(
"546Mi"
),
...
...
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