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
025f24aa
Commit
025f24aa
authored
Sep 22, 2015
by
derekwaynecarr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make requests defaulting only work on pods
parent
8258c1b0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
89 additions
and
13 deletions
+89
-13
defaults.go
pkg/api/v1/defaults.go
+18
-13
defaults_test.go
pkg/api/v1/defaults_test.go
+71
-0
No files found.
pkg/api/v1/defaults.go
View file @
025f24aa
...
...
@@ -93,6 +93,24 @@ func addDefaultingFuncs() {
}
}
},
func
(
obj
*
Pod
)
{
// If limits are specified, but requests are not, default requests to limits
// This is done here rather than a more specific defaulting pass on ResourceRequirements
// because we only want this defaulting semantic to take place on a Pod and not a PodTemplate
for
i
:=
range
obj
.
Spec
.
Containers
{
// set requests to limits if requests are not specified, but limits are
if
obj
.
Spec
.
Containers
[
i
]
.
Resources
.
Limits
!=
nil
{
if
obj
.
Spec
.
Containers
[
i
]
.
Resources
.
Requests
==
nil
{
obj
.
Spec
.
Containers
[
i
]
.
Resources
.
Requests
=
make
(
ResourceList
)
}
for
key
,
value
:=
range
obj
.
Spec
.
Containers
[
i
]
.
Resources
.
Limits
{
if
_
,
exists
:=
obj
.
Spec
.
Containers
[
i
]
.
Resources
.
Requests
[
key
];
!
exists
{
obj
.
Spec
.
Containers
[
i
]
.
Resources
.
Requests
[
key
]
=
*
(
value
.
Copy
())
}
}
}
}
},
func
(
obj
*
PodSpec
)
{
if
obj
.
DNSPolicy
==
""
{
obj
.
DNSPolicy
=
DNSClusterFirst
...
...
@@ -165,19 +183,6 @@ func addDefaultingFuncs() {
obj
.
APIVersion
=
"v1"
}
},
func
(
obj
*
ResourceRequirements
)
{
// Set requests to limits if requests are not specified (but limits are).
if
obj
.
Limits
!=
nil
{
if
obj
.
Requests
==
nil
{
obj
.
Requests
=
make
(
ResourceList
)
}
for
key
,
value
:=
range
obj
.
Limits
{
if
_
,
exists
:=
obj
.
Requests
[
key
];
!
exists
{
obj
.
Requests
[
key
]
=
*
(
value
.
Copy
())
}
}
}
},
func
(
obj
*
LimitRangeItem
)
{
// for container limits, we apply default values
if
obj
.
Type
==
LimitTypeContainer
{
...
...
pkg/api/v1/defaults_test.go
View file @
025f24aa
...
...
@@ -433,6 +433,77 @@ func TestSetDefaultObjectFieldSelectorAPIVersion(t *testing.T) {
}
}
func
TestSetDefaultRequestsPod
(
t
*
testing
.
T
)
{
// verify we default if limits are specified
s
:=
versioned
.
PodSpec
{}
s
.
Containers
=
[]
versioned
.
Container
{
{
Resources
:
versioned
.
ResourceRequirements
{
Limits
:
versioned
.
ResourceList
{
versioned
.
ResourceCPU
:
resource
.
MustParse
(
"100m"
),
},
},
},
}
pod
:=
&
versioned
.
Pod
{
Spec
:
s
,
}
output
:=
roundTrip
(
t
,
runtime
.
Object
(
pod
))
pod2
:=
output
.
(
*
versioned
.
Pod
)
defaultRequest
:=
pod2
.
Spec
.
Containers
[
0
]
.
Resources
.
Requests
requestValue
:=
defaultRequest
[
versioned
.
ResourceCPU
]
if
requestValue
.
String
()
!=
"100m"
{
t
.
Errorf
(
"Expected request cpu: %s, got: %s"
,
"100m"
,
requestValue
.
String
())
}
// verify we do nothing if no limits are specified
s
=
versioned
.
PodSpec
{}
s
.
Containers
=
[]
versioned
.
Container
{{}}
pod
=
&
versioned
.
Pod
{
Spec
:
s
,
}
output
=
roundTrip
(
t
,
runtime
.
Object
(
pod
))
pod2
=
output
.
(
*
versioned
.
Pod
)
defaultRequest
=
pod2
.
Spec
.
Containers
[
0
]
.
Resources
.
Requests
requestValue
=
defaultRequest
[
versioned
.
ResourceCPU
]
if
requestValue
.
String
()
!=
"0"
{
t
.
Errorf
(
"Expected 0 request value, got: %s"
,
requestValue
.
String
())
}
}
func
TestDefaultRequestIsNotSetForReplicationController
(
t
*
testing
.
T
)
{
s
:=
versioned
.
PodSpec
{}
s
.
Containers
=
[]
versioned
.
Container
{
{
Resources
:
versioned
.
ResourceRequirements
{
Limits
:
versioned
.
ResourceList
{
versioned
.
ResourceCPU
:
resource
.
MustParse
(
"100m"
),
},
},
},
}
rc
:=
&
versioned
.
ReplicationController
{
Spec
:
versioned
.
ReplicationControllerSpec
{
Replicas
:
newInt
(
3
),
Template
:
&
versioned
.
PodTemplateSpec
{
ObjectMeta
:
versioned
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
"foo"
:
"bar"
,
},
},
Spec
:
s
,
},
},
}
output
:=
roundTrip
(
t
,
runtime
.
Object
(
rc
))
rc2
:=
output
.
(
*
versioned
.
ReplicationController
)
defaultRequest
:=
rc2
.
Spec
.
Template
.
Spec
.
Containers
[
0
]
.
Resources
.
Requests
requestValue
:=
defaultRequest
[
versioned
.
ResourceCPU
]
if
requestValue
.
String
()
!=
"0"
{
t
.
Errorf
(
"Expected 0 request value, got: %s"
,
requestValue
.
String
())
}
}
func
TestSetDefaultLimitRangeItem
(
t
*
testing
.
T
)
{
limitRange
:=
&
versioned
.
LimitRange
{
ObjectMeta
:
versioned
.
ObjectMeta
{
...
...
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