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
da0d37f1
Commit
da0d37f1
authored
Feb 05, 2016
by
Tim St. Clair
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix panic from multiple probe cleanup calls.
parent
b32078d8
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
7 deletions
+45
-7
manager.go
pkg/kubelet/prober/manager.go
+2
-2
manager_test.go
pkg/kubelet/prober/manager_test.go
+27
-0
worker.go
pkg/kubelet/prober/worker.go
+13
-4
worker_test.go
pkg/kubelet/prober/worker_test.go
+3
-1
No files found.
pkg/kubelet/prober/manager.go
View file @
da0d37f1
...
...
@@ -171,7 +171,7 @@ func (m *manager) RemovePod(pod *api.Pod) {
for
_
,
probeType
:=
range
[
...
]
probeType
{
readiness
,
liveness
}
{
key
.
probeType
=
probeType
if
worker
,
ok
:=
m
.
workers
[
key
];
ok
{
close
(
worker
.
stop
)
worker
.
stop
(
)
}
}
}
...
...
@@ -188,7 +188,7 @@ func (m *manager) CleanupPods(activePods []*api.Pod) {
for
key
,
worker
:=
range
m
.
workers
{
if
_
,
ok
:=
desiredPods
[
key
.
podUID
];
!
ok
{
close
(
worker
.
stop
)
worker
.
stop
(
)
}
}
}
...
...
pkg/kubelet/prober/manager_test.go
View file @
da0d37f1
...
...
@@ -18,6 +18,7 @@ package prober
import
(
"fmt"
"strconv"
"testing"
"time"
...
...
@@ -26,6 +27,7 @@ import (
kubecontainer
"k8s.io/kubernetes/pkg/kubelet/container"
"k8s.io/kubernetes/pkg/kubelet/prober/results"
"k8s.io/kubernetes/pkg/probe"
"k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/util/runtime"
"k8s.io/kubernetes/pkg/util/wait"
)
...
...
@@ -173,6 +175,31 @@ func TestCleanupPods(t *testing.T) {
}
}
func
TestCleanupRepeated
(
t
*
testing
.
T
)
{
m
:=
newTestManager
()
defer
cleanup
(
t
,
m
)
podTemplate
:=
api
.
Pod
{
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{{
Name
:
"prober1"
,
ReadinessProbe
:
defaultProbe
,
LivenessProbe
:
defaultProbe
,
}},
},
}
const
numTestPods
=
100
for
i
:=
0
;
i
<
numTestPods
;
i
++
{
pod
:=
podTemplate
pod
.
UID
=
types
.
UID
(
strconv
.
Itoa
(
i
))
m
.
AddPod
(
&
pod
)
}
for
i
:=
0
;
i
<
10
;
i
++
{
m
.
CleanupPods
([]
*
api
.
Pod
{})
}
}
func
TestUpdatePodStatus
(
t
*
testing
.
T
)
{
unprobed
:=
api
.
ContainerStatus
{
Name
:
"unprobed_container"
,
...
...
pkg/kubelet/prober/worker.go
View file @
da0d37f1
...
...
@@ -32,8 +32,8 @@ import (
// stop channel is closed. The worker uses the probe Manager's statusManager to get up-to-date
// container IDs.
type
worker
struct
{
// Channel for stopping the probe
, it should be closed to trigger a stop
.
stop
chan
struct
{}
// Channel for stopping the probe.
stop
Ch
chan
struct
{}
// The pod containing this probe (read-only)
pod
*
api
.
Pod
...
...
@@ -70,7 +70,7 @@ func newWorker(
container
api
.
Container
)
*
worker
{
w
:=
&
worker
{
stop
:
make
(
chan
struct
{}),
stop
Ch
:
make
(
chan
struct
{},
1
),
// Buffer so stop() can be non-blocking.
pod
:
pod
,
container
:
container
,
probeType
:
probeType
,
...
...
@@ -109,7 +109,7 @@ probeLoop:
for
w
.
doProbe
()
{
// Wait for next probe tick.
select
{
case
<-
w
.
stop
:
case
<-
w
.
stop
Ch
:
break
probeLoop
case
<-
probeTicker
.
C
:
// continue
...
...
@@ -117,6 +117,15 @@ probeLoop:
}
}
// stop stops the probe worker. The worker handles cleanup and removes itself from its manager.
// It is safe to call stop multiple times.
func
(
w
*
worker
)
stop
()
{
select
{
case
w
.
stopCh
<-
struct
{}{}
:
default
:
// Non-blocking.
}
}
// doProbe probes the container once and records the result.
// Returns whether the worker should continue.
func
(
w
*
worker
)
doProbe
()
(
keepGoing
bool
)
{
...
...
pkg/kubelet/prober/worker_test.go
View file @
da0d37f1
...
...
@@ -236,7 +236,9 @@ func TestCleanUp(t *testing.T) {
}
}
close
(
w
.
stop
)
for
i
:=
0
;
i
<
10
;
i
++
{
w
.
stop
()
// Stop should be callable multiple times without consequence.
}
if
err
:=
waitForWorkerExit
(
m
,
[]
probeKey
{
key
});
err
!=
nil
{
t
.
Fatalf
(
"[%s] error waiting for worker exit: %v"
,
probeType
,
err
)
}
...
...
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