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
21706384
Commit
21706384
authored
May 16, 2016
by
Chao Xu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use garbage queue drained instead of a watch
parent
c73406bc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
53 deletions
+19
-53
test-integration.sh
hack/test-integration.sh
+1
-1
garbage_collector_test.go
test/integration/garbage_collector_test.go
+18
-52
No files found.
hack/test-integration.sh
View file @
21706384
...
@@ -34,7 +34,7 @@ KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1,extensions/v1beta1;v1,autos
...
@@ -34,7 +34,7 @@ KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1,extensions/v1beta1;v1,autos
# Give integration tests longer to run
# Give integration tests longer to run
# TODO: allow a larger value to be passed in
# TODO: allow a larger value to be passed in
#KUBE_TIMEOUT=${KUBE_TIMEOUT:--timeout 240s}
#KUBE_TIMEOUT=${KUBE_TIMEOUT:--timeout 240s}
KUBE_TIMEOUT
=
"-timeout
12
00s"
KUBE_TIMEOUT
=
"-timeout
6
00s"
KUBE_INTEGRATION_TEST_MAX_CONCURRENCY
=
${
KUBE_INTEGRATION_TEST_MAX_CONCURRENCY
:-
"-1"
}
KUBE_INTEGRATION_TEST_MAX_CONCURRENCY
=
${
KUBE_INTEGRATION_TEST_MAX_CONCURRENCY
:-
"-1"
}
LOG_LEVEL
=
${
LOG_LEVEL
:-
2
}
LOG_LEVEL
=
${
LOG_LEVEL
:-
2
}
...
...
test/integration/garbage_collector_test.go
View file @
21706384
...
@@ -28,6 +28,7 @@ import (
...
@@ -28,6 +28,7 @@ import (
"time"
"time"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/api/v1"
clientset
"k8s.io/kubernetes/pkg/client/clientset_generated/release_1_3"
clientset
"k8s.io/kubernetes/pkg/client/clientset_generated/release_1_3"
...
@@ -37,7 +38,6 @@ import (
...
@@ -37,7 +38,6 @@ import (
"k8s.io/kubernetes/pkg/master"
"k8s.io/kubernetes/pkg/master"
"k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/util/wait"
"k8s.io/kubernetes/pkg/util/wait"
"k8s.io/kubernetes/pkg/watch"
"k8s.io/kubernetes/test/integration/framework"
"k8s.io/kubernetes/test/integration/framework"
)
)
...
@@ -102,29 +102,6 @@ func newOwnerRC(name string) *v1.ReplicationController {
...
@@ -102,29 +102,6 @@ func newOwnerRC(name string) *v1.ReplicationController {
}
}
}
}
func
observePodDeletion
(
t
*
testing
.
T
,
w
watch
.
Interface
)
(
deletedPod
*
api
.
Pod
)
{
deleted
:=
false
timeout
:=
false
timer
:=
time
.
After
(
60
*
time
.
Second
)
for
!
deleted
&&
!
timeout
{
select
{
case
event
,
_
:=
<-
w
.
ResultChan
()
:
if
event
.
Type
==
watch
.
Deleted
{
// TODO: used the commented code once we fix the client.
// deletedPod = event.Object.(*v1.Pod)
deletedPod
=
event
.
Object
.
(
*
api
.
Pod
)
deleted
=
true
}
case
<-
timer
:
timeout
=
true
}
}
if
!
deleted
{
t
.
Fatalf
(
"Failed to observe pod deletion"
)
}
return
}
func
setup
(
t
*
testing
.
T
)
(
*
garbagecollector
.
GarbageCollector
,
clientset
.
Interface
)
{
func
setup
(
t
*
testing
.
T
)
(
*
garbagecollector
.
GarbageCollector
,
clientset
.
Interface
)
{
var
m
*
master
.
Master
var
m
*
master
.
Master
s
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
s
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
...
@@ -211,13 +188,6 @@ func TestCascadingDeletion(t *testing.T) {
...
@@ -211,13 +188,6 @@ func TestCascadingDeletion(t *testing.T) {
if
len
(
pods
.
Items
)
!=
3
{
if
len
(
pods
.
Items
)
!=
3
{
t
.
Fatalf
(
"Expect only 3 pods"
)
t
.
Fatalf
(
"Expect only 3 pods"
)
}
}
options
:=
api
.
ListOptions
{
ResourceVersion
:
pods
.
ListMeta
.
ResourceVersion
,
}
w
,
err
:=
podClient
.
Watch
(
options
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to set up watch: %v"
,
err
)
}
stopCh
:=
make
(
chan
struct
{})
stopCh
:=
make
(
chan
struct
{})
go
gc
.
Run
(
5
,
stopCh
)
go
gc
.
Run
(
5
,
stopCh
)
defer
close
(
stopCh
)
defer
close
(
stopCh
)
...
@@ -225,16 +195,13 @@ func TestCascadingDeletion(t *testing.T) {
...
@@ -225,16 +195,13 @@ func TestCascadingDeletion(t *testing.T) {
if
err
:=
rcClient
.
Delete
(
toBeDeletedRCName
,
nil
);
err
!=
nil
{
if
err
:=
rcClient
.
Delete
(
toBeDeletedRCName
,
nil
);
err
!=
nil
{
t
.
Fatalf
(
"failed to delete replication controller: %v"
,
err
)
t
.
Fatalf
(
"failed to delete replication controller: %v"
,
err
)
}
}
// wait for the garbage collector to drain its queue
deletedPod
:=
observePodDeletion
(
t
,
w
)
if
err
:=
wait
.
Poll
(
10
*
time
.
Second
,
120
*
time
.
Second
,
func
()
(
bool
,
error
)
{
if
deletedPod
==
nil
{
return
gc
.
QueuesDrained
(),
nil
t
.
Fatalf
(
"empty deletedPod"
)
});
err
!=
nil
{
}
t
.
Fatal
(
err
)
if
deletedPod
.
Name
!=
garbageCollectedPodName
{
t
.
Fatalf
(
"deleted unexpected pod: %v"
,
*
deletedPod
)
}
}
// wait for another 30 seconds to give garbage collect a chance to make mistakes.
t
.
Logf
(
"garbage collector queues drained"
)
time
.
Sleep
(
30
*
time
.
Second
)
// checks the garbage collect doesn't delete pods it shouldn't do.
// checks the garbage collect doesn't delete pods it shouldn't do.
if
_
,
err
:=
podClient
.
Get
(
independentPodName
);
err
!=
nil
{
if
_
,
err
:=
podClient
.
Get
(
independentPodName
);
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
...
@@ -242,6 +209,9 @@ func TestCascadingDeletion(t *testing.T) {
...
@@ -242,6 +209,9 @@ func TestCascadingDeletion(t *testing.T) {
if
_
,
err
:=
podClient
.
Get
(
oneValidOwnerPodName
);
err
!=
nil
{
if
_
,
err
:=
podClient
.
Get
(
oneValidOwnerPodName
);
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
if
_
,
err
:=
podClient
.
Get
(
garbageCollectedPodName
);
err
==
nil
||
!
errors
.
IsNotFound
(
err
)
{
t
.
Fatalf
(
"expect pod %s to be garbage collected"
,
garbageCollectedPodName
)
}
}
}
// This test simulates the case where an object is created with an owner that
// This test simulates the case where an object is created with an owner that
...
@@ -264,22 +234,18 @@ func TestCreateWithNonExisitentOwner(t *testing.T) {
...
@@ -264,22 +234,18 @@ func TestCreateWithNonExisitentOwner(t *testing.T) {
if
len
(
pods
.
Items
)
!=
1
{
if
len
(
pods
.
Items
)
!=
1
{
t
.
Fatalf
(
"Expect only 1 pod"
)
t
.
Fatalf
(
"Expect only 1 pod"
)
}
}
options
:=
api
.
ListOptions
{
ResourceVersion
:
pods
.
ListMeta
.
ResourceVersion
,
}
w
,
err
:=
podClient
.
Watch
(
options
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to set up watch: %v"
,
err
)
}
stopCh
:=
make
(
chan
struct
{})
stopCh
:=
make
(
chan
struct
{})
go
gc
.
Run
(
5
,
stopCh
)
go
gc
.
Run
(
5
,
stopCh
)
defer
close
(
stopCh
)
defer
close
(
stopCh
)
deletedPod
:=
observePodDeletion
(
t
,
w
)
// wait for the garbage collector to drain its queue
if
deletedPod
==
nil
{
if
err
:=
wait
.
Poll
(
10
*
time
.
Second
,
120
*
time
.
Second
,
func
()
(
bool
,
error
)
{
t
.
Fatalf
(
"empty deletedPod"
)
return
gc
.
QueuesDrained
(),
nil
});
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
if
deletedPod
.
Name
!=
garbageCollectedPodName
{
t
.
Logf
(
"garbage collector queues drained"
)
t
.
Fatalf
(
"deleted unexpected pod: %v"
,
*
deletedPod
)
if
_
,
err
:=
podClient
.
Get
(
garbageCollectedPodName
);
err
==
nil
||
!
errors
.
IsNotFound
(
err
)
{
t
.
Fatalf
(
"expect pod %s to be garbage collected"
,
garbageCollectedPodName
)
}
}
}
}
...
...
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