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
84da994d
Commit
84da994d
authored
Feb 15, 2016
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #21088 from derekwaynecarr/improve_helpers
Auto commit by PR queue bot
parents
88e4be7c
a03361bd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
14 deletions
+22
-14
resource_helpers.go
pkg/api/resource_helpers.go
+2
-2
resource_helpers_test.go
pkg/api/resource_helpers_test.go
+10
-0
non_zero.go
plugin/pkg/scheduler/algorithm/priorities/util/non_zero.go
+10
-12
No files found.
pkg/api/resource_helpers.go
View file @
84da994d
...
...
@@ -30,7 +30,7 @@ func (self *ResourceList) Cpu() *resource.Quantity {
if
val
,
ok
:=
(
*
self
)[
ResourceCPU
];
ok
{
return
&
val
}
return
&
resource
.
Quantity
{}
return
&
resource
.
Quantity
{
Format
:
resource
.
DecimalSI
}
}
// Returns the Memory limit if specified.
...
...
@@ -38,7 +38,7 @@ func (self *ResourceList) Memory() *resource.Quantity {
if
val
,
ok
:=
(
*
self
)[
ResourceMemory
];
ok
{
return
&
val
}
return
&
resource
.
Quantity
{}
return
&
resource
.
Quantity
{
Format
:
resource
.
BinarySI
}
}
func
(
self
*
ResourceList
)
Pods
()
*
resource
.
Quantity
{
...
...
pkg/api/resource_helpers_test.go
View file @
84da994d
...
...
@@ -51,3 +51,13 @@ func TestResourceHelpers(t *testing.T) {
t
.
Errorf
(
"expected memorylimit %v, got %v"
,
memoryLimit
,
res
)
}
}
func
TestDefaultResourceHelpers
(
t
*
testing
.
T
)
{
resourceList
:=
ResourceList
{}
if
resourceList
.
Cpu
()
.
Format
!=
resource
.
DecimalSI
{
t
.
Errorf
(
"expected %v, actual %v"
,
resource
.
DecimalSI
,
resourceList
.
Cpu
()
.
Format
)
}
if
resourceList
.
Memory
()
.
Format
!=
resource
.
BinarySI
{
t
.
Errorf
(
"expected %v, actual %v"
,
resource
.
BinarySI
,
resourceList
.
Memory
()
.
Format
)
}
}
plugin/pkg/scheduler/algorithm/priorities/util/non_zero.go
View file @
84da994d
...
...
@@ -16,10 +16,7 @@ limitations under the License.
package
util
import
(
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/resource"
)
import
"k8s.io/kubernetes/pkg/api"
// For each of these resources, a pod that doesn't request the resource explicitly
// will be treated as having requested the amount indicated below, for the purpose
...
...
@@ -32,21 +29,22 @@ import (
const
DefaultMilliCpuRequest
int64
=
100
// 0.1 core
const
DefaultMemoryRequest
int64
=
200
*
1024
*
1024
// 200 MB
// GetNonzeroRequests returns the default resource request if none is found or what is provided on the request
// TODO: Consider setting default as a fixed fraction of machine capacity (take "capacity api.ResourceList"
// as an additional argument here) rather than using constants
func
GetNonzeroRequests
(
requests
*
api
.
ResourceList
)
(
int64
,
int64
)
{
var
out
_millicpu
,
out_m
emory
int64
var
out
MilliCPU
,
outM
emory
int64
// Override if un-set, but not if explicitly set to zero
if
(
*
requests
.
Cpu
()
==
resource
.
Quantity
{})
{
out
_millicpu
=
DefaultMilliCpuRequest
if
_
,
found
:=
(
*
requests
)[
api
.
ResourceCPU
];
!
found
{
out
MilliCPU
=
DefaultMilliCpuRequest
}
else
{
out
_millicpu
=
requests
.
Cpu
()
.
MilliValue
()
out
MilliCPU
=
requests
.
Cpu
()
.
MilliValue
()
}
// Override if un-set, but not if explicitly set to zero
if
(
*
requests
.
Memory
()
==
resource
.
Quantity
{})
{
out
_m
emory
=
DefaultMemoryRequest
if
_
,
found
:=
(
*
requests
)[
api
.
ResourceMemory
];
!
found
{
out
M
emory
=
DefaultMemoryRequest
}
else
{
out
_m
emory
=
requests
.
Memory
()
.
Value
()
out
M
emory
=
requests
.
Memory
()
.
Value
()
}
return
out
_millicpu
,
out_m
emory
return
out
MilliCPU
,
outM
emory
}
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