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
c4b32cc8
Commit
c4b32cc8
authored
Oct 29, 2015
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #16223 from timstclair/status-deadlock
Auto commit by PR queue bot
parents
0d29759b
9a2089ad
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
124 additions
and
14 deletions
+124
-14
worker_test.go
pkg/kubelet/prober/worker_test.go
+3
-1
manager.go
pkg/kubelet/status/manager.go
+0
-0
manager_test.go
pkg/kubelet/status/manager_test.go
+121
-13
No files found.
pkg/kubelet/prober/worker_test.go
View file @
c4b32cc8
...
...
@@ -24,8 +24,10 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/client/record"
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
kubecontainer
"k8s.io/kubernetes/pkg/kubelet/container"
"k8s.io/kubernetes/pkg/kubelet/prober/results"
"k8s.io/kubernetes/pkg/kubelet/status"
"k8s.io/kubernetes/pkg/probe"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/exec"
...
...
@@ -117,7 +119,7 @@ func TestDoProbe(t *testing.T) {
}
// Clean up.
m
.
statusManager
.
DeletePodStatus
(
podUID
)
m
.
statusManager
=
status
.
NewManager
(
&
testclient
.
Fake
{}
)
resultsManager
(
m
,
probeType
)
.
Remove
(
containerID
)
}
}
...
...
pkg/kubelet/status/manager.go
View file @
c4b32cc8
This diff is collapsed.
Click to expand it.
pkg/kubelet/status/manager_test.go
View file @
c4b32cc8
...
...
@@ -24,9 +24,11 @@ import (
"time"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/unversioned"
client
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
"k8s.io/kubernetes/pkg/runtime"
)
var
testPod
*
api
.
Pod
=
&
api
.
Pod
{
...
...
@@ -244,12 +246,15 @@ func TestUnchangedStatusPreservesLastTransitionTime(t *testing.T) {
}
func
TestSyncBatchIgnoresNotFound
(
t
*
testing
.
T
)
{
syncer
:=
newTestManager
()
client
:=
testclient
.
Fake
{}
syncer
:=
NewManager
(
&
client
)
.
(
*
manager
)
client
.
AddReactor
(
"get"
,
"pods"
,
func
(
action
testclient
.
Action
)
(
bool
,
runtime
.
Object
,
error
)
{
return
true
,
nil
,
errors
.
NewNotFound
(
"pods"
,
"test-pod"
)
})
syncer
.
SetPodStatus
(
testPod
,
getRandomPodStatus
())
err
:=
syncer
.
syncBatch
()
if
err
!=
nil
{
t
.
Errorf
(
"unexpected syncing error: %v"
,
err
)
}
syncer
.
syncBatch
()
verifyActions
(
t
,
syncer
.
kubeClient
,
[]
testclient
.
Action
{
testclient
.
GetActionImpl
{
ActionImpl
:
testclient
.
ActionImpl
{
Verb
:
"get"
,
Resource
:
"pods"
}},
})
...
...
@@ -259,10 +264,7 @@ func TestSyncBatch(t *testing.T) {
syncer
:=
newTestManager
()
syncer
.
kubeClient
=
testclient
.
NewSimpleFake
(
testPod
)
syncer
.
SetPodStatus
(
testPod
,
getRandomPodStatus
())
err
:=
syncer
.
syncBatch
()
if
err
!=
nil
{
t
.
Errorf
(
"unexpected syncing error: %v"
,
err
)
}
syncer
.
syncBatch
()
verifyActions
(
t
,
syncer
.
kubeClient
,
[]
testclient
.
Action
{
testclient
.
GetActionImpl
{
ActionImpl
:
testclient
.
ActionImpl
{
Verb
:
"get"
,
Resource
:
"pods"
}},
testclient
.
UpdateActionImpl
{
ActionImpl
:
testclient
.
ActionImpl
{
Verb
:
"update"
,
Resource
:
"pods"
,
Subresource
:
"status"
}},
...
...
@@ -277,15 +279,121 @@ func TestSyncBatchChecksMismatchedUID(t *testing.T) {
differentPod
.
UID
=
"second"
syncer
.
kubeClient
=
testclient
.
NewSimpleFake
(
testPod
)
syncer
.
SetPodStatus
(
&
differentPod
,
getRandomPodStatus
())
err
:=
syncer
.
syncBatch
()
if
err
!=
nil
{
t
.
Errorf
(
"unexpected syncing error: %v"
,
err
)
}
syncer
.
syncBatch
()
verifyActions
(
t
,
syncer
.
kubeClient
,
[]
testclient
.
Action
{
testclient
.
GetActionImpl
{
ActionImpl
:
testclient
.
ActionImpl
{
Verb
:
"get"
,
Resource
:
"pods"
}},
})
}
func
TestSyncBatchNoDeadlock
(
t
*
testing
.
T
)
{
client
:=
&
testclient
.
Fake
{}
m
:=
NewManager
(
client
)
.
(
*
manager
)
// Setup fake client.
var
ret
api
.
Pod
var
err
error
client
.
AddReactor
(
"*"
,
"pods"
,
func
(
action
testclient
.
Action
)
(
bool
,
runtime
.
Object
,
error
)
{
return
true
,
&
ret
,
err
})
pod
:=
new
(
api
.
Pod
)
*
pod
=
*
testPod
pod
.
Status
.
ContainerStatuses
=
[]
api
.
ContainerStatus
{{
State
:
api
.
ContainerState
{
Running
:
&
api
.
ContainerStateRunning
{}}}}
getAction
:=
testclient
.
GetActionImpl
{
ActionImpl
:
testclient
.
ActionImpl
{
Verb
:
"get"
,
Resource
:
"pods"
}}
updateAction
:=
testclient
.
UpdateActionImpl
{
ActionImpl
:
testclient
.
ActionImpl
{
Verb
:
"update"
,
Resource
:
"pods"
,
Subresource
:
"status"
}}
// Pod not found.
ret
=
*
pod
err
=
errors
.
NewNotFound
(
"pods"
,
pod
.
Name
)
m
.
SetPodStatus
(
pod
,
getRandomPodStatus
())
m
.
syncBatch
()
verifyActions
(
t
,
client
,
[]
testclient
.
Action
{
getAction
})
client
.
ClearActions
()
// Pod was recreated.
ret
.
UID
=
"other_pod"
err
=
nil
m
.
SetPodStatus
(
pod
,
getRandomPodStatus
())
m
.
syncBatch
()
verifyActions
(
t
,
client
,
[]
testclient
.
Action
{
getAction
})
client
.
ClearActions
()
// Pod not deleted (success case).
ret
=
*
pod
m
.
SetPodStatus
(
pod
,
getRandomPodStatus
())
m
.
syncBatch
()
verifyActions
(
t
,
client
,
[]
testclient
.
Action
{
getAction
,
updateAction
})
client
.
ClearActions
()
// Pod is terminated, but still running.
pod
.
DeletionTimestamp
=
new
(
unversioned
.
Time
)
m
.
SetPodStatus
(
pod
,
getRandomPodStatus
())
m
.
syncBatch
()
verifyActions
(
t
,
client
,
[]
testclient
.
Action
{
getAction
,
updateAction
})
client
.
ClearActions
()
// Pod is terminated successfully.
pod
.
Status
.
ContainerStatuses
[
0
]
.
State
.
Running
=
nil
pod
.
Status
.
ContainerStatuses
[
0
]
.
State
.
Terminated
=
&
api
.
ContainerStateTerminated
{}
m
.
SetPodStatus
(
pod
,
getRandomPodStatus
())
m
.
syncBatch
()
verifyActions
(
t
,
client
,
[]
testclient
.
Action
{
getAction
,
updateAction
})
client
.
ClearActions
()
// Error case.
err
=
fmt
.
Errorf
(
"intentional test error"
)
m
.
SetPodStatus
(
pod
,
getRandomPodStatus
())
m
.
syncBatch
()
verifyActions
(
t
,
client
,
[]
testclient
.
Action
{
getAction
})
client
.
ClearActions
()
}
func
TestStaleUpdates
(
t
*
testing
.
T
)
{
pod
:=
*
testPod
client
:=
testclient
.
NewSimpleFake
(
&
pod
)
m
:=
NewManager
(
client
)
.
(
*
manager
)
status
:=
api
.
PodStatus
{
Message
:
"initial status"
}
m
.
SetPodStatus
(
&
pod
,
status
)
status
.
Message
=
"first version bump"
m
.
SetPodStatus
(
&
pod
,
status
)
status
.
Message
=
"second version bump"
m
.
SetPodStatus
(
&
pod
,
status
)
verifyUpdates
(
t
,
m
,
3
)
t
.
Logf
(
"First sync pushes latest status."
)
m
.
syncBatch
()
verifyActions
(
t
,
m
.
kubeClient
,
[]
testclient
.
Action
{
testclient
.
GetActionImpl
{
ActionImpl
:
testclient
.
ActionImpl
{
Verb
:
"get"
,
Resource
:
"pods"
}},
testclient
.
UpdateActionImpl
{
ActionImpl
:
testclient
.
ActionImpl
{
Verb
:
"update"
,
Resource
:
"pods"
,
Subresource
:
"status"
}},
})
client
.
ClearActions
()
for
i
:=
0
;
i
<
2
;
i
++
{
t
.
Logf
(
"Next 2 syncs should be ignored (%d)."
,
i
)
m
.
syncBatch
()
verifyActions
(
t
,
m
.
kubeClient
,
[]
testclient
.
Action
{})
}
t
.
Log
(
"Unchanged status should not send an update."
)
m
.
SetPodStatus
(
&
pod
,
status
)
verifyUpdates
(
t
,
m
,
0
)
t
.
Log
(
"... unless it's stale."
)
m
.
apiStatusVersions
[
pod
.
UID
]
=
m
.
apiStatusVersions
[
pod
.
UID
]
-
1
m
.
SetPodStatus
(
&
pod
,
status
)
m
.
syncBatch
()
verifyActions
(
t
,
m
.
kubeClient
,
[]
testclient
.
Action
{
testclient
.
GetActionImpl
{
ActionImpl
:
testclient
.
ActionImpl
{
Verb
:
"get"
,
Resource
:
"pods"
}},
testclient
.
UpdateActionImpl
{
ActionImpl
:
testclient
.
ActionImpl
{
Verb
:
"update"
,
Resource
:
"pods"
,
Subresource
:
"status"
}},
})
// Nothing stuck in the pipe.
verifyUpdates
(
t
,
m
,
0
)
}
// shuffle returns a new shuffled list of container statuses.
func
shuffle
(
statuses
[]
api
.
ContainerStatus
)
[]
api
.
ContainerStatus
{
numStatuses
:=
len
(
statuses
)
...
...
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