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
b232eef5
Commit
b232eef5
authored
Apr 27, 2015
by
Victor Marmol
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move image PullPolicy logic to pullImage().
This will allow us to remove the Docker-specific logic in pullImageAndRunContainer() and re-use pullImage() in other runtimes.
parent
aa487b7c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
26 deletions
+30
-26
kubelet.go
pkg/kubelet/kubelet.go
+30
-26
No files found.
pkg/kubelet/kubelet.go
View file @
b232eef5
...
@@ -847,21 +847,43 @@ func parseResolvConf(reader io.Reader) (nameservers []string, searches []string,
...
@@ -847,21 +847,43 @@ func parseResolvConf(reader io.Reader) (nameservers []string, searches []string,
return
nameservers
,
searches
,
nil
return
nameservers
,
searches
,
nil
}
}
func
(
kl
*
Kubelet
)
pullImage
(
img
string
,
ref
*
api
.
ObjectReference
)
error
{
// Pull the image for the specified pod and container.
func
(
kl
*
Kubelet
)
pullImage
(
pod
*
api
.
Pod
,
container
*
api
.
Container
)
error
{
if
container
.
ImagePullPolicy
==
api
.
PullNever
{
return
nil
}
start
:=
time
.
Now
()
start
:=
time
.
Now
()
defer
func
()
{
defer
func
()
{
metrics
.
ImagePullLatency
.
Observe
(
metrics
.
SinceInMicroseconds
(
start
))
metrics
.
ImagePullLatency
.
Observe
(
metrics
.
SinceInMicroseconds
(
start
))
}()
}()
if
err
:=
kl
.
containerManager
.
Pull
(
img
);
err
!=
nil
{
ref
,
err
:=
kubecontainer
.
GenerateContainerRef
(
pod
,
container
)
if
err
!=
nil
{
glog
.
Errorf
(
"Couldn't make a ref to pod %v, container %v: '%v'"
,
pod
.
Name
,
container
.
Name
,
err
)
}
present
,
err
:=
kl
.
containerManager
.
IsImagePresent
(
container
.
Image
)
if
err
!=
nil
{
if
ref
!=
nil
{
if
ref
!=
nil
{
kl
.
recorder
.
Eventf
(
ref
,
"failed"
,
"Failed to
pull image %q: %v"
,
img
,
err
)
kl
.
recorder
.
Eventf
(
ref
,
"failed"
,
"Failed to
inspect image %q: %v"
,
container
.
Image
,
err
)
}
}
glog
.
Errorf
(
"Failed to inspect image %q: %v; skipping pod %q container %q"
,
container
.
Image
,
err
,
kubecontainer
.
GetPodFullName
(
pod
),
container
.
Name
)
return
err
return
err
}
}
if
ref
!=
nil
{
kl
.
recorder
.
Eventf
(
ref
,
"pulled"
,
"Successfully pulled image %q"
,
img
)
if
container
.
ImagePullPolicy
==
api
.
PullAlways
||
(
container
.
ImagePullPolicy
==
api
.
PullIfNotPresent
&&
(
!
present
))
{
if
err
:=
kl
.
containerManager
.
Pull
(
container
.
Image
);
err
!=
nil
{
if
ref
!=
nil
{
kl
.
recorder
.
Eventf
(
ref
,
"failed"
,
"Failed to pull image %q: %v"
,
container
.
Image
,
err
)
}
return
err
}
if
ref
!=
nil
{
kl
.
recorder
.
Eventf
(
ref
,
"pulled"
,
"Successfully pulled image %q"
,
container
.
Image
)
}
}
}
return
nil
return
nil
}
}
...
@@ -959,33 +981,15 @@ func shouldContainerBeRestarted(container *api.Container, pod *api.Pod, podStatu
...
@@ -959,33 +981,15 @@ func shouldContainerBeRestarted(container *api.Container, pod *api.Pod, podStatu
// Attempts to start a container pulling the image before that if necessary. It returns DockerID of a started container
// Attempts to start a container pulling the image before that if necessary. It returns DockerID of a started container
// if it was successful, and a non-nil error otherwise.
// if it was successful, and a non-nil error otherwise.
func
(
kl
*
Kubelet
)
pullImageAndRunContainer
(
pod
*
api
.
Pod
,
container
*
api
.
Container
,
podInfraContainerID
dockertools
.
DockerID
)
(
dockertools
.
DockerID
,
error
)
{
func
(
kl
*
Kubelet
)
pullImageAndRunContainer
(
pod
*
api
.
Pod
,
container
*
api
.
Container
,
podInfraContainerID
dockertools
.
DockerID
)
(
dockertools
.
DockerID
,
error
)
{
podFullName
:=
kubecontainer
.
GetPodFullName
(
pod
)
if
err
:=
kl
.
pullImage
(
pod
,
container
);
err
!=
nil
{
ref
,
err
:=
kubecontainer
.
GenerateContainerRef
(
pod
,
container
)
return
""
,
err
if
err
!=
nil
{
glog
.
Errorf
(
"Couldn't make a ref to pod %v, container %v: '%v'"
,
pod
.
Name
,
container
.
Name
,
err
)
}
if
container
.
ImagePullPolicy
!=
api
.
PullNever
{
present
,
err
:=
kl
.
containerManager
.
IsImagePresent
(
container
.
Image
)
if
err
!=
nil
{
if
ref
!=
nil
{
kl
.
recorder
.
Eventf
(
ref
,
"failed"
,
"Failed to inspect image %q: %v"
,
container
.
Image
,
err
)
}
glog
.
Errorf
(
"Failed to inspect image %q: %v; skipping pod %q container %q"
,
container
.
Image
,
err
,
podFullName
,
container
.
Name
)
return
""
,
err
}
if
container
.
ImagePullPolicy
==
api
.
PullAlways
||
(
container
.
ImagePullPolicy
==
api
.
PullIfNotPresent
&&
(
!
present
))
{
if
err
:=
kl
.
pullImage
(
container
.
Image
,
ref
);
err
!=
nil
{
return
""
,
err
}
}
}
}
// TODO(dawnchen): Check RestartPolicy.DelaySeconds before restart a container
// TODO(dawnchen): Check RestartPolicy.DelaySeconds before restart a container
namespaceMode
:=
fmt
.
Sprintf
(
"container:%v"
,
podInfraContainerID
)
namespaceMode
:=
fmt
.
Sprintf
(
"container:%v"
,
podInfraContainerID
)
containerID
,
err
:=
kl
.
containerManager
.
RunContainer
(
pod
,
container
,
kl
,
kl
.
handlerRunner
,
namespaceMode
,
namespaceMode
)
containerID
,
err
:=
kl
.
containerManager
.
RunContainer
(
pod
,
container
,
kl
,
kl
.
handlerRunner
,
namespaceMode
,
namespaceMode
)
if
err
!=
nil
{
if
err
!=
nil
{
// TODO(bburns) : Perhaps blacklist a container after N failures?
// TODO(bburns) : Perhaps blacklist a container after N failures?
glog
.
Errorf
(
"Error running pod %q container %q: %v"
,
podFullName
,
container
.
Name
,
err
)
glog
.
Errorf
(
"Error running pod %q container %q: %v"
,
kubecontainer
.
GetPodFullName
(
pod
)
,
container
.
Name
,
err
)
return
""
,
err
return
""
,
err
}
}
return
containerID
,
nil
return
containerID
,
nil
...
...
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