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
ef33001d
Commit
ef33001d
authored
Oct 10, 2015
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #15429 from mikedanese/gc-fix
Auto commit by PR queue bot
parents
49a5f899
66ddde9f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
43 deletions
+16
-43
gc_controller.go
pkg/controller/gc/gc_controller.go
+5
-6
gc_controller_test.go
pkg/controller/gc/gc_controller_test.go
+11
-37
No files found.
pkg/controller/gc/gc_controller.go
View file @
ef33001d
...
...
@@ -42,9 +42,9 @@ const (
type
GCController
struct
{
kubeClient
client
.
Interface
podControl
controller
.
PodControlInterface
podStore
cache
.
StoreToPodLister
podStoreSyncer
*
framework
.
Controller
deletePod
func
(
namespace
,
name
string
)
error
threshold
int
}
...
...
@@ -55,11 +55,10 @@ func New(kubeClient client.Interface, resyncPeriod controller.ResyncPeriodFunc,
gcc
:=
&
GCController
{
kubeClient
:
kubeClient
,
podControl
:
controller
.
RealPodControl
{
Recorder
:
eventBroadcaster
.
NewRecorder
(
api
.
EventSource
{
Component
:
"pod-garbage-collector"
}),
KubeClient
:
kubeClient
,
threshold
:
threshold
,
deletePod
:
func
(
namespace
,
name
string
)
error
{
return
kubeClient
.
Pods
(
namespace
)
.
Delete
(
name
,
api
.
NewDeleteOptions
(
0
))
},
threshold
:
threshold
,
}
terminatedSelector
:=
compileTerminatedPodSelector
()
...
...
@@ -105,7 +104,7 @@ func (gcc *GCController) gc() {
wait
.
Add
(
1
)
go
func
(
namespace
string
,
name
string
)
{
defer
wait
.
Done
()
if
err
:=
gcc
.
podControl
.
D
eletePod
(
namespace
,
name
);
err
!=
nil
{
if
err
:=
gcc
.
d
eletePod
(
namespace
,
name
);
err
!=
nil
{
// ignore not founds
defer
util
.
HandleError
(
err
)
}
...
...
pkg/controller/gc/gc_controller_test.go
View file @
ef33001d
...
...
@@ -25,41 +25,9 @@ import (
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util/sets"
)
type
FakePodControl
struct
{
podSpec
[]
api
.
PodTemplateSpec
deletePodName
[]
string
lock
sync
.
Mutex
err
error
}
func
(
f
*
FakePodControl
)
CreatePods
(
namespace
string
,
spec
*
api
.
PodTemplateSpec
,
object
runtime
.
Object
)
error
{
panic
(
"unimplemented"
)
}
func
(
f
*
FakePodControl
)
CreatePodsOnNode
(
nodeName
,
namespace
string
,
spec
*
api
.
PodTemplateSpec
,
object
runtime
.
Object
)
error
{
panic
(
"unimplemented"
)
}
func
(
f
*
FakePodControl
)
DeletePod
(
namespace
string
,
podName
string
)
error
{
f
.
lock
.
Lock
()
defer
f
.
lock
.
Unlock
()
if
f
.
err
!=
nil
{
return
f
.
err
}
f
.
deletePodName
=
append
(
f
.
deletePodName
,
podName
)
return
nil
}
func
(
f
*
FakePodControl
)
clear
()
{
f
.
lock
.
Lock
()
defer
f
.
lock
.
Unlock
()
f
.
deletePodName
=
[]
string
{}
f
.
podSpec
=
[]
api
.
PodTemplateSpec
{}
}
func
TestGC
(
t
*
testing
.
T
)
{
type
nameToPhase
struct
{
name
string
...
...
@@ -100,8 +68,14 @@ func TestGC(t *testing.T) {
for
i
,
test
:=
range
testCases
{
client
:=
testclient
.
NewSimpleFake
()
gcc
:=
New
(
client
,
controller
.
NoResyncPeriodFunc
,
test
.
threshold
)
fake
:=
&
FakePodControl
{}
gcc
.
podControl
=
fake
deletedPodNames
:=
make
([]
string
,
0
)
var
lock
sync
.
Mutex
gcc
.
deletePod
=
func
(
_
,
name
string
)
error
{
lock
.
Lock
()
defer
lock
.
Unlock
()
deletedPodNames
=
append
(
deletedPodNames
,
name
)
return
nil
}
creationTime
:=
time
.
Unix
(
0
,
0
)
for
_
,
pod
:=
range
test
.
pods
{
...
...
@@ -115,16 +89,16 @@ func TestGC(t *testing.T) {
gcc
.
gc
()
pass
:=
true
for
_
,
pod
:=
range
fake
.
deletePodName
{
for
_
,
pod
:=
range
deletedPodNames
{
if
!
test
.
deletedPodNames
.
Has
(
pod
)
{
pass
=
false
}
}
if
len
(
fake
.
deletePodName
)
!=
len
(
test
.
deletedPodNames
)
{
if
len
(
deletedPodNames
)
!=
len
(
test
.
deletedPodNames
)
{
pass
=
false
}
if
!
pass
{
t
.
Errorf
(
"[%v]pod's deleted expected and actual did not match.
\n\t
expected: %v
\n\t
actual: %v"
,
i
,
test
.
deletedPodNames
,
fake
.
deletePodName
)
t
.
Errorf
(
"[%v]pod's deleted expected and actual did not match.
\n\t
expected: %v
\n\t
actual: %v"
,
i
,
test
.
deletedPodNames
,
deletedPodNames
)
}
}
}
...
...
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