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
a03361bd
Commit
a03361bd
authored
Feb 11, 2016
by
derekwaynecarr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make default format right for nil values
parent
acb16073
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 @
a03361bd
...
@@ -30,7 +30,7 @@ func (self *ResourceList) Cpu() *resource.Quantity {
...
@@ -30,7 +30,7 @@ func (self *ResourceList) Cpu() *resource.Quantity {
if
val
,
ok
:=
(
*
self
)[
ResourceCPU
];
ok
{
if
val
,
ok
:=
(
*
self
)[
ResourceCPU
];
ok
{
return
&
val
return
&
val
}
}
return
&
resource
.
Quantity
{}
return
&
resource
.
Quantity
{
Format
:
resource
.
DecimalSI
}
}
}
// Returns the Memory limit if specified.
// Returns the Memory limit if specified.
...
@@ -38,7 +38,7 @@ func (self *ResourceList) Memory() *resource.Quantity {
...
@@ -38,7 +38,7 @@ func (self *ResourceList) Memory() *resource.Quantity {
if
val
,
ok
:=
(
*
self
)[
ResourceMemory
];
ok
{
if
val
,
ok
:=
(
*
self
)[
ResourceMemory
];
ok
{
return
&
val
return
&
val
}
}
return
&
resource
.
Quantity
{}
return
&
resource
.
Quantity
{
Format
:
resource
.
BinarySI
}
}
}
func
(
self
*
ResourceList
)
Pods
()
*
resource
.
Quantity
{
func
(
self
*
ResourceList
)
Pods
()
*
resource
.
Quantity
{
...
...
pkg/api/resource_helpers_test.go
View file @
a03361bd
...
@@ -51,3 +51,13 @@ func TestResourceHelpers(t *testing.T) {
...
@@ -51,3 +51,13 @@ func TestResourceHelpers(t *testing.T) {
t
.
Errorf
(
"expected memorylimit %v, got %v"
,
memoryLimit
,
res
)
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 @
a03361bd
...
@@ -16,10 +16,7 @@ limitations under the License.
...
@@ -16,10 +16,7 @@ limitations under the License.
package
util
package
util
import
(
import
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/resource"
)
// For each of these resources, a pod that doesn't request the resource explicitly
// 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
// will be treated as having requested the amount indicated below, for the purpose
...
@@ -32,21 +29,22 @@ import (
...
@@ -32,21 +29,22 @@ import (
const
DefaultMilliCpuRequest
int64
=
100
// 0.1 core
const
DefaultMilliCpuRequest
int64
=
100
// 0.1 core
const
DefaultMemoryRequest
int64
=
200
*
1024
*
1024
// 200 MB
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"
// TODO: Consider setting default as a fixed fraction of machine capacity (take "capacity api.ResourceList"
// as an additional argument here) rather than using constants
// as an additional argument here) rather than using constants
func
GetNonzeroRequests
(
requests
*
api
.
ResourceList
)
(
int64
,
int64
)
{
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
// Override if un-set, but not if explicitly set to zero
if
(
*
requests
.
Cpu
()
==
resource
.
Quantity
{})
{
if
_
,
found
:=
(
*
requests
)[
api
.
ResourceCPU
];
!
found
{
out
_millicpu
=
DefaultMilliCpuRequest
out
MilliCPU
=
DefaultMilliCpuRequest
}
else
{
}
else
{
out
_millicpu
=
requests
.
Cpu
()
.
MilliValue
()
out
MilliCPU
=
requests
.
Cpu
()
.
MilliValue
()
}
}
// Override if un-set, but not if explicitly set to zero
// Override if un-set, but not if explicitly set to zero
if
(
*
requests
.
Memory
()
==
resource
.
Quantity
{})
{
if
_
,
found
:=
(
*
requests
)[
api
.
ResourceMemory
];
!
found
{
out
_m
emory
=
DefaultMemoryRequest
out
M
emory
=
DefaultMemoryRequest
}
else
{
}
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