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
7df64d59
Commit
7df64d59
authored
Aug 14, 2017
by
weekface
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove useless error
parent
21751996
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
23 deletions
+8
-23
helpers.go
pkg/api/resource/helpers.go
+1
-1
describe.go
pkg/printers/internalversion/describe.go
+6
-18
describe_test.go
pkg/printers/internalversion/describe_test.go
+1
-4
No files found.
pkg/api/resource/helpers.go
View file @
7df64d59
...
...
@@ -27,7 +27,7 @@ import (
// PodRequestsAndLimits returns a dictionary of all defined resources summed up for all
// containers of the pod.
func
PodRequestsAndLimits
(
pod
*
api
.
Pod
)
(
reqs
map
[
api
.
ResourceName
]
resource
.
Quantity
,
limits
map
[
api
.
ResourceName
]
resource
.
Quantity
,
err
error
)
{
func
PodRequestsAndLimits
(
pod
*
api
.
Pod
)
(
reqs
map
[
api
.
ResourceName
]
resource
.
Quantity
,
limits
map
[
api
.
ResourceName
]
resource
.
Quantity
)
{
reqs
,
limits
=
map
[
api
.
ResourceName
]
resource
.
Quantity
{},
map
[
api
.
ResourceName
]
resource
.
Quantity
{}
for
_
,
container
:=
range
pod
.
Spec
.
Containers
{
for
name
,
quantity
:=
range
container
.
Resources
.
Requests
{
...
...
pkg/printers/internalversion/describe.go
View file @
7df64d59
...
...
@@ -2626,9 +2626,7 @@ func describeNode(node *api.Node, nodeNonTerminatedPodsList *api.PodList, events
w
.
Write
(
LEVEL_0
,
"ExternalID:
\t
%s
\n
"
,
node
.
Spec
.
ExternalID
)
}
if
canViewPods
&&
nodeNonTerminatedPodsList
!=
nil
{
if
err
:=
describeNodeResource
(
nodeNonTerminatedPodsList
,
node
,
w
);
err
!=
nil
{
return
err
}
describeNodeResource
(
nodeNonTerminatedPodsList
,
node
,
w
)
}
else
{
w
.
Write
(
LEVEL_0
,
"Pods:
\t
not authorized
\n
"
)
}
...
...
@@ -2868,7 +2866,7 @@ func describeHorizontalPodAutoscaler(hpa *autoscaling.HorizontalPodAutoscaler, e
})
}
func
describeNodeResource
(
nodeNonTerminatedPodsList
*
api
.
PodList
,
node
*
api
.
Node
,
w
PrefixWriter
)
error
{
func
describeNodeResource
(
nodeNonTerminatedPodsList
*
api
.
PodList
,
node
*
api
.
Node
,
w
PrefixWriter
)
{
w
.
Write
(
LEVEL_0
,
"Non-terminated Pods:
\t
(%d in total)
\n
"
,
len
(
nodeNonTerminatedPodsList
.
Items
))
w
.
Write
(
LEVEL_1
,
"Namespace
\t
Name
\t\t
CPU Requests
\t
CPU Limits
\t
Memory Requests
\t
Memory Limits
\n
"
)
w
.
Write
(
LEVEL_1
,
"---------
\t
----
\t\t
------------
\t
----------
\t
---------------
\t
-------------
\n
"
)
...
...
@@ -2878,10 +2876,7 @@ func describeNodeResource(nodeNonTerminatedPodsList *api.PodList, node *api.Node
}
for
_
,
pod
:=
range
nodeNonTerminatedPodsList
.
Items
{
req
,
limit
,
err
:=
resourcehelper
.
PodRequestsAndLimits
(
&
pod
)
if
err
!=
nil
{
return
err
}
req
,
limit
:=
resourcehelper
.
PodRequestsAndLimits
(
&
pod
)
cpuReq
,
cpuLimit
,
memoryReq
,
memoryLimit
:=
req
[
api
.
ResourceCPU
],
limit
[
api
.
ResourceCPU
],
req
[
api
.
ResourceMemory
],
limit
[
api
.
ResourceMemory
]
fractionCpuReq
:=
float64
(
cpuReq
.
MilliValue
())
/
float64
(
allocatable
.
Cpu
()
.
MilliValue
())
*
100
fractionCpuLimit
:=
float64
(
cpuLimit
.
MilliValue
())
/
float64
(
allocatable
.
Cpu
()
.
MilliValue
())
*
100
...
...
@@ -2894,10 +2889,7 @@ func describeNodeResource(nodeNonTerminatedPodsList *api.PodList, node *api.Node
w
.
Write
(
LEVEL_0
,
"Allocated resources:
\n
(Total limits may be over 100 percent, i.e., overcommitted.)
\n
CPU Requests
\t
CPU Limits
\t
Memory Requests
\t
Memory Limits
\n
"
)
w
.
Write
(
LEVEL_1
,
"------------
\t
----------
\t
---------------
\t
-------------
\n
"
)
reqs
,
limits
,
err
:=
getPodsTotalRequestsAndLimits
(
nodeNonTerminatedPodsList
)
if
err
!=
nil
{
return
err
}
reqs
,
limits
:=
getPodsTotalRequestsAndLimits
(
nodeNonTerminatedPodsList
)
cpuReqs
,
cpuLimits
,
memoryReqs
,
memoryLimits
:=
reqs
[
api
.
ResourceCPU
],
limits
[
api
.
ResourceCPU
],
reqs
[
api
.
ResourceMemory
],
limits
[
api
.
ResourceMemory
]
fractionCpuReqs
:=
float64
(
cpuReqs
.
MilliValue
())
/
float64
(
allocatable
.
Cpu
()
.
MilliValue
())
*
100
fractionCpuLimits
:=
float64
(
cpuLimits
.
MilliValue
())
/
float64
(
allocatable
.
Cpu
()
.
MilliValue
())
*
100
...
...
@@ -2906,16 +2898,12 @@ func describeNodeResource(nodeNonTerminatedPodsList *api.PodList, node *api.Node
w
.
Write
(
LEVEL_1
,
"%s (%d%%)
\t
%s (%d%%)
\t
%s (%d%%)
\t
%s (%d%%)
\n
"
,
cpuReqs
.
String
(),
int64
(
fractionCpuReqs
),
cpuLimits
.
String
(),
int64
(
fractionCpuLimits
),
memoryReqs
.
String
(),
int64
(
fractionMemoryReqs
),
memoryLimits
.
String
(),
int64
(
fractionMemoryLimits
))
return
nil
}
func
getPodsTotalRequestsAndLimits
(
podList
*
api
.
PodList
)
(
reqs
map
[
api
.
ResourceName
]
resource
.
Quantity
,
limits
map
[
api
.
ResourceName
]
resource
.
Quantity
,
err
error
)
{
func
getPodsTotalRequestsAndLimits
(
podList
*
api
.
PodList
)
(
reqs
map
[
api
.
ResourceName
]
resource
.
Quantity
,
limits
map
[
api
.
ResourceName
]
resource
.
Quantity
)
{
reqs
,
limits
=
map
[
api
.
ResourceName
]
resource
.
Quantity
{},
map
[
api
.
ResourceName
]
resource
.
Quantity
{}
for
_
,
pod
:=
range
podList
.
Items
{
podReqs
,
podLimits
,
err
:=
resourcehelper
.
PodRequestsAndLimits
(
&
pod
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
podReqs
,
podLimits
:=
resourcehelper
.
PodRequestsAndLimits
(
&
pod
)
for
podReqName
,
podReqValue
:=
range
podReqs
{
if
value
,
ok
:=
reqs
[
podReqName
];
!
ok
{
reqs
[
podReqName
]
=
*
podReqValue
.
Copy
()
...
...
pkg/printers/internalversion/describe_test.go
View file @
7df64d59
...
...
@@ -848,10 +848,7 @@ func TestGetPodsTotalRequests(t *testing.T) {
}
for
_
,
testCase
:=
range
testCases
{
reqs
,
_
,
err
:=
getPodsTotalRequestsAndLimits
(
testCase
.
pods
)
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error %v"
,
err
)
}
reqs
,
_
:=
getPodsTotalRequestsAndLimits
(
testCase
.
pods
)
if
!
apiequality
.
Semantic
.
DeepEqual
(
reqs
,
testCase
.
expectedReqs
)
{
t
.
Errorf
(
"Expected %v, got %v"
,
testCase
.
expectedReqs
,
reqs
)
}
...
...
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