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
cfb1cd48
Unverified
Commit
cfb1cd48
authored
Feb 28, 2017
by
Jordan Liggitt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Apply custom defaults to init containers
parent
35c2e70d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
80 additions
and
0 deletions
+80
-0
defaults.go
pkg/api/v1/defaults.go
+13
-0
defaults_test.go
pkg/api/v1/defaults_test.go
+54
-0
defaults.go
staging/src/k8s.io/client-go/pkg/api/v1/defaults.go
+13
-0
No files found.
pkg/api/v1/defaults.go
View file @
cfb1cd48
...
...
@@ -160,6 +160,18 @@ func SetDefaults_Pod(obj *Pod) {
}
}
}
for
i
:=
range
obj
.
Spec
.
InitContainers
{
if
obj
.
Spec
.
InitContainers
[
i
]
.
Resources
.
Limits
!=
nil
{
if
obj
.
Spec
.
InitContainers
[
i
]
.
Resources
.
Requests
==
nil
{
obj
.
Spec
.
InitContainers
[
i
]
.
Resources
.
Requests
=
make
(
ResourceList
)
}
for
key
,
value
:=
range
obj
.
Spec
.
InitContainers
[
i
]
.
Resources
.
Limits
{
if
_
,
exists
:=
obj
.
Spec
.
InitContainers
[
i
]
.
Resources
.
Requests
[
key
];
!
exists
{
obj
.
Spec
.
InitContainers
[
i
]
.
Resources
.
Requests
[
key
]
=
*
(
value
.
Copy
())
}
}
}
}
}
func
SetDefaults_PodSpec
(
obj
*
PodSpec
)
{
if
obj
.
DNSPolicy
==
""
{
...
...
@@ -170,6 +182,7 @@ func SetDefaults_PodSpec(obj *PodSpec) {
}
if
obj
.
HostNetwork
{
defaultHostNetworkPorts
(
&
obj
.
Containers
)
defaultHostNetworkPorts
(
&
obj
.
InitContainers
)
}
if
obj
.
SecurityContext
==
nil
{
obj
.
SecurityContext
=
&
PodSecurityContext
{}
...
...
pkg/api/v1/defaults_test.go
View file @
cfb1cd48
...
...
@@ -536,6 +536,15 @@ func TestSetDefaultPodSpecHostNetwork(t *testing.T) {
},
},
}
s
.
InitContainers
=
[]
v1
.
Container
{
{
Ports
:
[]
v1
.
ContainerPort
{
{
ContainerPort
:
portNum
,
},
},
},
}
pod
:=
&
v1
.
Pod
{
Spec
:
s
,
}
...
...
@@ -547,6 +556,11 @@ func TestSetDefaultPodSpecHostNetwork(t *testing.T) {
if
hostPortNum
!=
portNum
{
t
.
Errorf
(
"Expected container port to be defaulted, was made %d instead of %d"
,
hostPortNum
,
portNum
)
}
hostPortNum
=
s2
.
InitContainers
[
0
]
.
Ports
[
0
]
.
HostPort
if
hostPortNum
!=
portNum
{
t
.
Errorf
(
"Expected container port to be defaulted, was made %d instead of %d"
,
hostPortNum
,
portNum
)
}
}
func
TestSetDefaultNodeExternalID
(
t
*
testing
.
T
)
{
...
...
@@ -679,6 +693,18 @@ func TestSetMinimumScalePod(t *testing.T) {
},
},
}
s
.
InitContainers
=
[]
v1
.
Container
{
{
Resources
:
v1
.
ResourceRequirements
{
Requests
:
v1
.
ResourceList
{
v1
.
ResourceMemory
:
resource
.
MustParse
(
"1n"
),
},
Limits
:
v1
.
ResourceList
{
v1
.
ResourceCPU
:
resource
.
MustParse
(
"2n"
),
},
},
},
}
pod
:=
&
v1
.
Pod
{
Spec
:
s
,
}
...
...
@@ -687,6 +713,9 @@ func TestSetMinimumScalePod(t *testing.T) {
if
expect
:=
resource
.
MustParse
(
"1m"
);
expect
.
Cmp
(
pod
.
Spec
.
Containers
[
0
]
.
Resources
.
Requests
[
v1
.
ResourceMemory
])
!=
0
{
t
.
Errorf
(
"did not round resources: %#v"
,
pod
.
Spec
.
Containers
[
0
]
.
Resources
)
}
if
expect
:=
resource
.
MustParse
(
"1m"
);
expect
.
Cmp
(
pod
.
Spec
.
InitContainers
[
0
]
.
Resources
.
Requests
[
v1
.
ResourceMemory
])
!=
0
{
t
.
Errorf
(
"did not round resources: %#v"
,
pod
.
Spec
.
InitContainers
[
0
]
.
Resources
)
}
}
func
TestSetDefaultRequestsPod
(
t
*
testing
.
T
)
{
...
...
@@ -705,6 +734,19 @@ func TestSetDefaultRequestsPod(t *testing.T) {
},
},
}
s
.
InitContainers
=
[]
v1
.
Container
{
{
Resources
:
v1
.
ResourceRequirements
{
Requests
:
v1
.
ResourceList
{
v1
.
ResourceMemory
:
resource
.
MustParse
(
"0"
),
},
Limits
:
v1
.
ResourceList
{
v1
.
ResourceCPU
:
resource
.
MustParse
(
"100m"
),
v1
.
ResourceMemory
:
resource
.
MustParse
(
"1Gi"
),
},
},
},
}
pod
:=
&
v1
.
Pod
{
Spec
:
s
,
}
...
...
@@ -717,10 +759,18 @@ func TestSetDefaultRequestsPod(t *testing.T) {
if
requestValue
:=
defaultRequest
[
v1
.
ResourceMemory
];
requestValue
.
String
()
!=
"0"
{
t
.
Errorf
(
"Expected request memory: %s, got: %s"
,
"0"
,
requestValue
.
String
())
}
defaultRequest
=
pod2
.
Spec
.
InitContainers
[
0
]
.
Resources
.
Requests
if
requestValue
:=
defaultRequest
[
v1
.
ResourceCPU
];
requestValue
.
String
()
!=
"100m"
{
t
.
Errorf
(
"Expected request cpu: %s, got: %s"
,
"100m"
,
requestValue
.
String
())
}
if
requestValue
:=
defaultRequest
[
v1
.
ResourceMemory
];
requestValue
.
String
()
!=
"0"
{
t
.
Errorf
(
"Expected request memory: %s, got: %s"
,
"0"
,
requestValue
.
String
())
}
// verify we do nothing if no limits are specified
s
=
v1
.
PodSpec
{}
s
.
Containers
=
[]
v1
.
Container
{{}}
s
.
InitContainers
=
[]
v1
.
Container
{{}}
pod
=
&
v1
.
Pod
{
Spec
:
s
,
}
...
...
@@ -730,6 +780,10 @@ func TestSetDefaultRequestsPod(t *testing.T) {
if
requestValue
:=
defaultRequest
[
v1
.
ResourceCPU
];
requestValue
.
String
()
!=
"0"
{
t
.
Errorf
(
"Expected 0 request value, got: %s"
,
requestValue
.
String
())
}
defaultRequest
=
pod2
.
Spec
.
InitContainers
[
0
]
.
Resources
.
Requests
if
requestValue
:=
defaultRequest
[
v1
.
ResourceCPU
];
requestValue
.
String
()
!=
"0"
{
t
.
Errorf
(
"Expected 0 request value, got: %s"
,
requestValue
.
String
())
}
}
func
TestDefaultRequestIsNotSetForReplicationController
(
t
*
testing
.
T
)
{
...
...
staging/src/k8s.io/client-go/pkg/api/v1/defaults.go
View file @
cfb1cd48
...
...
@@ -160,6 +160,18 @@ func SetDefaults_Pod(obj *Pod) {
}
}
}
for
i
:=
range
obj
.
Spec
.
InitContainers
{
if
obj
.
Spec
.
InitContainers
[
i
]
.
Resources
.
Limits
!=
nil
{
if
obj
.
Spec
.
InitContainers
[
i
]
.
Resources
.
Requests
==
nil
{
obj
.
Spec
.
InitContainers
[
i
]
.
Resources
.
Requests
=
make
(
ResourceList
)
}
for
key
,
value
:=
range
obj
.
Spec
.
InitContainers
[
i
]
.
Resources
.
Limits
{
if
_
,
exists
:=
obj
.
Spec
.
InitContainers
[
i
]
.
Resources
.
Requests
[
key
];
!
exists
{
obj
.
Spec
.
InitContainers
[
i
]
.
Resources
.
Requests
[
key
]
=
*
(
value
.
Copy
())
}
}
}
}
}
func
SetDefaults_PodSpec
(
obj
*
PodSpec
)
{
if
obj
.
DNSPolicy
==
""
{
...
...
@@ -170,6 +182,7 @@ func SetDefaults_PodSpec(obj *PodSpec) {
}
if
obj
.
HostNetwork
{
defaultHostNetworkPorts
(
&
obj
.
Containers
)
defaultHostNetworkPorts
(
&
obj
.
InitContainers
)
}
if
obj
.
SecurityContext
==
nil
{
obj
.
SecurityContext
=
&
PodSecurityContext
{}
...
...
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