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
fbbc5a85
Commit
fbbc5a85
authored
Nov 12, 2015
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #16782 from Random-Liu/past-active-deadline-check
Auto commit by PR queue bot
parents
646d9e79
d6b93cdf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
7 deletions
+82
-7
kubelet.go
pkg/kubelet/kubelet.go
+29
-7
kubelet_test.go
pkg/kubelet/kubelet_test.go
+53
-0
No files found.
pkg/kubelet/kubelet.go
View file @
fbbc5a85
...
@@ -1525,6 +1525,9 @@ func (kl *Kubelet) syncPod(pod *api.Pod, mirrorPod *api.Pod, runningPod kubecont
...
@@ -1525,6 +1525,9 @@ func (kl *Kubelet) syncPod(pod *api.Pod, mirrorPod *api.Pod, runningPod kubecont
}
else
{
}
else
{
var
err
error
var
err
error
podStatus
,
err
=
kl
.
generatePodStatus
(
pod
)
podStatus
,
err
=
kl
.
generatePodStatus
(
pod
)
// TODO (random-liu) It's strange that generatePodStatus generates some podStatus in
// the phase Failed, Pending etc, even with empty ContainerStatuses but still keep going
// on. Maybe need refactor here.
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Unable to get status for pod %q (uid %q): %v"
,
podFullName
,
uid
,
err
)
glog
.
Errorf
(
"Unable to get status for pod %q (uid %q): %v"
,
podFullName
,
uid
,
err
)
return
err
return
err
...
@@ -1776,6 +1779,31 @@ func (kl *Kubelet) pastActiveDeadline(pod *api.Pod) bool {
...
@@ -1776,6 +1779,31 @@ func (kl *Kubelet) pastActiveDeadline(pod *api.Pod) bool {
return
false
return
false
}
}
// Get pods which should be resynchronized. Currently, the following pod should be resynchronized:
// * pod whose work is ready.
// * pod past the active deadline.
func
(
kl
*
Kubelet
)
getPodsToSync
()
[]
*
api
.
Pod
{
allPods
:=
kl
.
podManager
.
GetPods
()
podUIDs
:=
kl
.
workQueue
.
GetWork
()
podUIDSet
:=
sets
.
NewString
()
for
_
,
podUID
:=
range
podUIDs
{
podUIDSet
.
Insert
(
string
(
podUID
))
}
var
podsToSync
[]
*
api
.
Pod
for
_
,
pod
:=
range
allPods
{
if
kl
.
pastActiveDeadline
(
pod
)
{
// The pod has passed the active deadline
podsToSync
=
append
(
podsToSync
,
pod
)
continue
}
if
podUIDSet
.
Has
(
string
(
pod
.
UID
))
{
// The work of the pod is ready
podsToSync
=
append
(
podsToSync
,
pod
)
}
}
return
podsToSync
}
// Returns true if pod is in the terminated state ("Failed" or "Succeeded").
// Returns true if pod is in the terminated state ("Failed" or "Succeeded").
func
(
kl
*
Kubelet
)
podIsTerminated
(
pod
*
api
.
Pod
)
bool
{
func
(
kl
*
Kubelet
)
podIsTerminated
(
pod
*
api
.
Pod
)
bool
{
var
status
api
.
PodStatus
var
status
api
.
PodStatus
...
@@ -2130,13 +2158,7 @@ func (kl *Kubelet) syncLoopIteration(updates <-chan kubetypes.PodUpdate, handler
...
@@ -2130,13 +2158,7 @@ func (kl *Kubelet) syncLoopIteration(updates <-chan kubetypes.PodUpdate, handler
glog
.
Errorf
(
"Kubelet does not support snapshot update"
)
glog
.
Errorf
(
"Kubelet does not support snapshot update"
)
}
}
case
<-
syncCh
:
case
<-
syncCh
:
podUIDs
:=
kl
.
workQueue
.
GetWork
()
podsToSync
:=
kl
.
getPodsToSync
()
var
podsToSync
[]
*
api
.
Pod
for
_
,
uid
:=
range
podUIDs
{
if
pod
,
ok
:=
kl
.
podManager
.
GetPodByUID
(
uid
);
ok
{
podsToSync
=
append
(
podsToSync
,
pod
)
}
}
if
len
(
podsToSync
)
==
0
{
if
len
(
podsToSync
)
==
0
{
break
break
}
}
...
...
pkg/kubelet/kubelet_test.go
View file @
fbbc5a85
...
@@ -4014,3 +4014,56 @@ func TestExtractBandwidthResources(t *testing.T) {
...
@@ -4014,3 +4014,56 @@ func TestExtractBandwidthResources(t *testing.T) {
}
}
}
}
}
}
func
TestGetPodsToSync
(
t
*
testing
.
T
)
{
testKubelet
:=
newTestKubelet
(
t
)
kubelet
:=
testKubelet
.
kubelet
pods
:=
newTestPods
(
5
)
podUIDs
:=
[]
types
.
UID
{}
for
_
,
pod
:=
range
pods
{
podUIDs
=
append
(
podUIDs
,
pod
.
UID
)
}
exceededActiveDeadlineSeconds
:=
int64
(
30
)
notYetActiveDeadlineSeconds
:=
int64
(
120
)
now
:=
unversioned
.
Now
()
startTime
:=
unversioned
.
NewTime
(
now
.
Time
.
Add
(
-
1
*
time
.
Minute
))
pods
[
0
]
.
Status
.
StartTime
=
&
startTime
pods
[
0
]
.
Spec
.
ActiveDeadlineSeconds
=
&
exceededActiveDeadlineSeconds
pods
[
1
]
.
Status
.
StartTime
=
&
startTime
pods
[
1
]
.
Spec
.
ActiveDeadlineSeconds
=
&
notYetActiveDeadlineSeconds
pods
[
2
]
.
Status
.
StartTime
=
&
startTime
pods
[
2
]
.
Spec
.
ActiveDeadlineSeconds
=
&
exceededActiveDeadlineSeconds
kubelet
.
podManager
.
SetPods
(
pods
)
kubelet
.
workQueue
.
Enqueue
(
pods
[
2
]
.
UID
,
0
)
kubelet
.
workQueue
.
Enqueue
(
pods
[
3
]
.
UID
,
0
)
kubelet
.
workQueue
.
Enqueue
(
pods
[
4
]
.
UID
,
time
.
Hour
)
expectedPodsUID
:=
[]
types
.
UID
{
pods
[
0
]
.
UID
,
pods
[
2
]
.
UID
,
pods
[
3
]
.
UID
}
podsToSync
:=
kubelet
.
getPodsToSync
()
if
len
(
podsToSync
)
==
len
(
expectedPodsUID
)
{
var
rightNum
int
for
_
,
podUID
:=
range
expectedPodsUID
{
for
_
,
podToSync
:=
range
podsToSync
{
if
podToSync
.
UID
==
podUID
{
rightNum
++
break
}
}
}
if
rightNum
!=
len
(
expectedPodsUID
)
{
// Just for report error
podsToSyncUID
:=
[]
types
.
UID
{}
for
_
,
podToSync
:=
range
podsToSync
{
podsToSyncUID
=
append
(
podsToSyncUID
,
podToSync
.
UID
)
}
t
.
Errorf
(
"expected pods %v to sync, got %v"
,
expectedPodsUID
,
podsToSyncUID
)
}
}
else
{
t
.
Errorf
(
"expected %d pods to sync, got %d"
,
3
,
len
(
podsToSync
))
}
}
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