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
cd6792ae
Commit
cd6792ae
authored
Dec 11, 2016
by
Klaus Ma
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add default imagePullPolicy for initContainers.
parent
4495af38
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
1 deletion
+73
-1
conversion.go
pkg/api/v1/conversion.go
+6
-0
defaults.go
pkg/api/v1/defaults.go
+0
-1
defaults_test.go
pkg/api/v1/defaults_test.go
+67
-0
No files found.
pkg/api/v1/conversion.go
View file @
cd6792ae
...
...
@@ -493,6 +493,12 @@ func Convert_v1_PodTemplateSpec_To_api_PodTemplateSpec(in *PodTemplateSpec, out
// taking responsibility to ensure mutation of in is not exposed
// back to the caller.
in
.
Spec
.
InitContainers
=
values
// Call defaulters explicitly until annotations are removed
for
i
:=
range
in
.
Spec
.
InitContainers
{
c
:=
&
in
.
Spec
.
InitContainers
[
i
]
SetDefaults_Container
(
c
)
}
}
if
err
:=
autoConvert_v1_PodTemplateSpec_To_api_PodTemplateSpec
(
in
,
out
,
s
);
err
!=
nil
{
...
...
pkg/api/v1/defaults.go
View file @
cd6792ae
...
...
@@ -112,7 +112,6 @@ func SetDefaults_Container(obj *Container) {
_
,
tag
,
_
,
_
:=
parsers
.
ParseImageName
(
obj
.
Image
)
// Check image tag
if
tag
==
"latest"
{
obj
.
ImagePullPolicy
=
PullAlways
}
else
{
...
...
pkg/api/v1/defaults_test.go
View file @
cd6792ae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
v1_test
import
(
"encoding/json"
"reflect"
"testing"
...
...
@@ -230,6 +231,72 @@ func TestSetDefaultReplicationControllerReplicas(t *testing.T) {
}
}
func
TestSetDefaultReplicationControllerImagePullPolicy
(
t
*
testing
.
T
)
{
containersWithoutPullPolicy
,
_
:=
json
.
Marshal
([]
map
[
string
]
interface
{}{
{
"name"
:
"install"
,
"image"
:
"busybox:latest"
,
},
})
containersWithPullPolicy
,
_
:=
json
.
Marshal
([]
map
[
string
]
interface
{}{
{
"name"
:
"install"
,
"imagePullPolicy"
:
"IfNotPresent"
,
},
})
tests
:=
[]
struct
{
rc
versioned
.
ReplicationController
expectPullPolicy
versioned
.
PullPolicy
}{
{
rc
:
versioned
.
ReplicationController
{
Spec
:
versioned
.
ReplicationControllerSpec
{
Template
:
&
versioned
.
PodTemplateSpec
{
ObjectMeta
:
versioned
.
ObjectMeta
{
Annotations
:
map
[
string
]
string
{
"pod.beta.kubernetes.io/init-containers"
:
string
(
containersWithoutPullPolicy
),
},
},
},
},
},
expectPullPolicy
:
versioned
.
PullAlways
,
},
{
rc
:
versioned
.
ReplicationController
{
Spec
:
versioned
.
ReplicationControllerSpec
{
Template
:
&
versioned
.
PodTemplateSpec
{
ObjectMeta
:
versioned
.
ObjectMeta
{
Annotations
:
map
[
string
]
string
{
"pod.beta.kubernetes.io/init-containers"
:
string
(
containersWithPullPolicy
),
},
},
},
},
},
expectPullPolicy
:
versioned
.
PullIfNotPresent
,
},
}
for
_
,
test
:=
range
tests
{
rc
:=
&
test
.
rc
obj2
:=
roundTrip
(
t
,
runtime
.
Object
(
rc
))
rc2
,
ok
:=
obj2
.
(
*
versioned
.
ReplicationController
)
if
!
ok
{
t
.
Errorf
(
"unexpected object: %v"
,
rc2
)
t
.
FailNow
()
}
if
test
.
expectPullPolicy
!=
rc2
.
Spec
.
Template
.
Spec
.
InitContainers
[
0
]
.
ImagePullPolicy
{
t
.
Errorf
(
"expected ImagePullPolicy: %s, got: %s"
,
test
.
expectPullPolicy
,
rc2
.
Spec
.
Template
.
Spec
.
InitContainers
[
0
]
.
ImagePullPolicy
,
)
}
}
}
func
TestSetDefaultService
(
t
*
testing
.
T
)
{
svc
:=
&
versioned
.
Service
{}
obj2
:=
roundTrip
(
t
,
runtime
.
Object
(
svc
))
...
...
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