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
3ff5cb6e
Unverified
Commit
3ff5cb6e
authored
Oct 26, 2016
by
Clayton Coleman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move resource.Quantity rounding to defaulter
This reverts commit
feb56cc4
.
parent
d089eda5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
3 deletions
+40
-3
conversion.go
pkg/api/v1/conversion.go
+3
-3
defaults.go
pkg/api/v1/defaults.go
+12
-0
defaults_test.go
pkg/api/v1/defaults_test.go
+25
-0
No files found.
pkg/api/v1/conversion.go
View file @
3ff5cb6e
...
...
@@ -739,15 +739,15 @@ func Convert_v1_ResourceList_To_api_ResourceList(in *ResourceList, out *api.Reso
if
*
in
==
nil
{
return
nil
}
if
*
out
==
nil
{
*
out
=
make
(
api
.
ResourceList
,
len
(
*
in
))
}
for
key
,
val
:=
range
*
in
{
// Moved to defaults
// TODO(#18538): We round up resource values to milli scale to maintain API compatibility.
// In the future, we should instead reject values that need rounding.
const
milliScale
=
-
3
val
.
RoundUp
(
milliScale
)
//
const milliScale = -3
//
val.RoundUp(milliScale)
(
*
out
)[
api
.
ResourceName
(
key
)]
=
val
}
...
...
pkg/api/v1/defaults.go
View file @
3ff5cb6e
...
...
@@ -52,9 +52,21 @@ func addDefaultingFuncs(scheme *runtime.Scheme) error {
SetDefaults_LimitRangeItem
,
SetDefaults_ConfigMap
,
SetDefaults_RBDVolumeSource
,
SetDefaults_ResourceList
,
)
}
func
SetDefaults_ResourceList
(
obj
*
ResourceList
)
{
for
key
,
val
:=
range
*
obj
{
// TODO(#18538): We round up resource values to milli scale to maintain API compatibility.
// In the future, we should instead reject values that need rounding.
const
milliScale
=
-
3
val
.
RoundUp
(
milliScale
)
(
*
obj
)[
ResourceName
(
key
)]
=
val
}
}
func
SetDefaults_PodExecOptions
(
obj
*
PodExecOptions
)
{
obj
.
Stdout
=
true
obj
.
Stderr
=
true
...
...
pkg/api/v1/defaults_test.go
View file @
3ff5cb6e
...
...
@@ -574,6 +574,31 @@ func TestSetDefaultObjectFieldSelectorAPIVersion(t *testing.T) {
}
}
func
TestSetMinimumScalePod
(
t
*
testing
.
T
)
{
// verify we default if limits are specified (and that request=0 is preserved)
s
:=
versioned
.
PodSpec
{}
s
.
Containers
=
[]
versioned
.
Container
{
{
Resources
:
versioned
.
ResourceRequirements
{
Requests
:
versioned
.
ResourceList
{
versioned
.
ResourceMemory
:
resource
.
MustParse
(
"1n"
),
},
Limits
:
versioned
.
ResourceList
{
versioned
.
ResourceCPU
:
resource
.
MustParse
(
"2n"
),
},
},
},
}
pod
:=
&
versioned
.
Pod
{
Spec
:
s
,
}
versioned
.
SetObjectDefaults_Pod
(
pod
)
if
expect
:=
resource
.
MustParse
(
"1m"
);
expect
.
Cmp
(
pod
.
Spec
.
Containers
[
0
]
.
Resources
.
Requests
[
versioned
.
ResourceMemory
])
!=
0
{
t
.
Errorf
(
"did not round resources: %#v"
,
pod
.
Spec
.
Containers
[
0
]
.
Resources
)
}
}
func
TestSetDefaultRequestsPod
(
t
*
testing
.
T
)
{
// verify we default if limits are specified (and that request=0 is preserved)
s
:=
versioned
.
PodSpec
{}
...
...
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