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
e0b3cfbc
Commit
e0b3cfbc
authored
Nov 30, 2016
by
bruceauyeung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eliminate duplicated codes in estimateContainer method
Signed-off-by:
bruceauyeung
<
ouyang.qinhua@zte.com.cn
>
parent
e6c57c65
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
20 deletions
+19
-20
admission.go
plugin/pkg/admission/initialresources/admission.go
+19
-20
No files found.
plugin/pkg/admission/initialresources/admission.go
View file @
e0b3cfbc
...
...
@@ -109,26 +109,8 @@ func (ir initialResources) estimateAndFillResourcesIfNotSet(pod *api.Pod) {
func
(
ir
initialResources
)
estimateContainer
(
pod
*
api
.
Pod
,
c
*
api
.
Container
,
message
string
)
[]
string
{
var
annotations
[]
string
req
:=
c
.
Resources
.
Requests
lim
:=
c
.
Resources
.
Limits
var
cpu
,
mem
*
resource
.
Quantity
var
err
error
if
_
,
ok
:=
req
[
api
.
ResourceCPU
];
!
ok
{
if
_
,
ok2
:=
lim
[
api
.
ResourceCPU
];
!
ok2
{
cpu
,
err
=
ir
.
getEstimation
(
api
.
ResourceCPU
,
c
,
pod
.
ObjectMeta
.
Namespace
)
if
err
!=
nil
{
glog
.
Errorf
(
"Error while trying to estimate resources: %v"
,
err
)
}
}
}
if
_
,
ok
:=
req
[
api
.
ResourceMemory
];
!
ok
{
if
_
,
ok2
:=
lim
[
api
.
ResourceMemory
];
!
ok2
{
mem
,
err
=
ir
.
getEstimation
(
api
.
ResourceMemory
,
c
,
pod
.
ObjectMeta
.
Namespace
)
if
err
!=
nil
{
glog
.
Errorf
(
"Error while trying to estimate resources: %v"
,
err
)
}
}
}
cpu
:=
ir
.
getEstimationIfNeeded
(
api
.
ResourceCPU
,
c
,
pod
.
ObjectMeta
.
Namespace
)
mem
:=
ir
.
getEstimationIfNeeded
(
api
.
ResourceMemory
,
c
,
pod
.
ObjectMeta
.
Namespace
)
// If Requests doesn't exits and an estimation was made, create Requests.
if
req
==
nil
&&
(
cpu
!=
nil
||
mem
!=
nil
)
{
c
.
Resources
.
Requests
=
api
.
ResourceList
{}
...
...
@@ -153,6 +135,23 @@ func (ir initialResources) estimateContainer(pod *api.Pod, c *api.Container, mes
return
annotations
}
// getEstimationIfNeeded estimates compute resource for container if its corresponding
// Request(min amount) and Limit(max amount) both are not specified.
func
(
ir
initialResources
)
getEstimationIfNeeded
(
kind
api
.
ResourceName
,
c
*
api
.
Container
,
ns
string
)
*
resource
.
Quantity
{
requests
:=
c
.
Resources
.
Requests
limits
:=
c
.
Resources
.
Limits
var
quantity
*
resource
.
Quantity
var
err
error
if
_
,
requestFound
:=
requests
[
kind
];
!
requestFound
{
if
_
,
limitFound
:=
limits
[
kind
];
!
limitFound
{
quantity
,
err
=
ir
.
getEstimation
(
kind
,
c
,
ns
)
if
err
!=
nil
{
glog
.
Errorf
(
"Error while trying to estimate resources: %v"
,
err
)
}
}
}
return
quantity
}
func
(
ir
initialResources
)
getEstimation
(
kind
api
.
ResourceName
,
c
*
api
.
Container
,
ns
string
)
(
*
resource
.
Quantity
,
error
)
{
end
:=
time
.
Now
()
start
:=
end
.
Add
(
-
week
)
...
...
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