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
2a117798
Commit
2a117798
authored
Sep 19, 2016
by
m1093782566
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix disruption hot loop
Change-Id: Ib8eb56cb87f688fe9b2016f574f3fb9b685ce796
parent
5975535d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
28 deletions
+34
-28
disruption.go
pkg/controller/disruption/disruption.go
+24
-28
disruption_test.go
pkg/controller/disruption/disruption_test.go
+10
-0
No files found.
pkg/controller/disruption/disruption.go
View file @
2a117798
...
@@ -31,6 +31,7 @@ import (
...
@@ -31,6 +31,7 @@ import (
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/util/intstr"
"k8s.io/kubernetes/pkg/util/intstr"
utilruntime
"k8s.io/kubernetes/pkg/util/runtime"
"k8s.io/kubernetes/pkg/util/wait"
"k8s.io/kubernetes/pkg/util/wait"
"k8s.io/kubernetes/pkg/util/workqueue"
"k8s.io/kubernetes/pkg/util/workqueue"
"k8s.io/kubernetes/pkg/watch"
"k8s.io/kubernetes/pkg/watch"
...
@@ -64,7 +65,8 @@ type DisruptionController struct {
...
@@ -64,7 +65,8 @@ type DisruptionController struct {
dController
*
cache
.
Controller
dController
*
cache
.
Controller
dLister
cache
.
StoreToDeploymentLister
dLister
cache
.
StoreToDeploymentLister
queue
*
workqueue
.
Type
// PodDisruptionBudget keys that need to be synced.
queue
workqueue
.
RateLimitingInterface
broadcaster
record
.
EventBroadcaster
broadcaster
record
.
EventBroadcaster
recorder
record
.
EventRecorder
recorder
record
.
EventRecorder
...
@@ -87,7 +89,7 @@ func NewDisruptionController(podInformer cache.SharedIndexInformer, kubeClient *
...
@@ -87,7 +89,7 @@ func NewDisruptionController(podInformer cache.SharedIndexInformer, kubeClient *
dc
:=
&
DisruptionController
{
dc
:=
&
DisruptionController
{
kubeClient
:
kubeClient
,
kubeClient
:
kubeClient
,
podController
:
podInformer
.
GetController
(),
podController
:
podInformer
.
GetController
(),
queue
:
workqueue
.
NewNamed
(
"disruption"
),
queue
:
workqueue
.
NewNamed
RateLimitingQueue
(
workqueue
.
DefaultControllerRateLimiter
(),
"disruption"
),
broadcaster
:
record
.
NewBroadcaster
(),
broadcaster
:
record
.
NewBroadcaster
(),
}
}
dc
.
recorder
=
dc
.
broadcaster
.
NewRecorder
(
api
.
EventSource
{
Component
:
"controllermanager"
})
dc
.
recorder
=
dc
.
broadcaster
.
NewRecorder
(
api
.
EventSource
{
Component
:
"controllermanager"
})
...
@@ -390,33 +392,27 @@ func (dc *DisruptionController) getPodsForPdb(pdb *policy.PodDisruptionBudget) (
...
@@ -390,33 +392,27 @@ func (dc *DisruptionController) getPodsForPdb(pdb *policy.PodDisruptionBudget) (
}
}
func
(
dc
*
DisruptionController
)
worker
()
{
func
(
dc
*
DisruptionController
)
worker
()
{
work
:=
func
()
bool
{
for
dc
.
processNextWorkItem
()
{
key
,
quit
:=
dc
.
queue
.
Get
()
}
if
quit
{
}
return
quit
}
func
(
dc
*
DisruptionController
)
processNextWorkItem
()
bool
{
defer
dc
.
queue
.
Done
(
key
)
dKey
,
quit
:=
dc
.
queue
.
Get
()
glog
.
V
(
4
)
.
Infof
(
"Syncing PodDisruptionBudget %q"
,
key
.
(
string
))
if
quit
{
if
err
:=
dc
.
sync
(
key
.
(
string
));
err
!=
nil
{
glog
.
Errorf
(
"Error syncing PodDisruptionBudget %v, requeuing: %v"
,
key
.
(
string
),
err
)
// TODO(mml): In order to be safe in the face of a total inability to write state
// changes, we should write an expiration timestamp here and consumers
// of the PDB state (the /evict subresource handler) should check that
// any 'true' state is relatively fresh.
// TODO(mml): file an issue to that effect
// TODO(mml): If we used a workqueue.RateLimitingInterface, we could
// improve our behavior (be a better citizen) when we need to retry.
dc
.
queue
.
Add
(
key
)
}
return
false
return
false
}
}
for
{
defer
dc
.
queue
.
Done
(
dKey
)
if
quit
:=
work
();
quit
{
return
err
:=
dc
.
sync
(
dKey
.
(
string
))
}
if
err
==
nil
{
dc
.
queue
.
Forget
(
dKey
)
return
true
}
}
utilruntime
.
HandleError
(
fmt
.
Errorf
(
"Error syncing PodDisruptionBudget %v, requeuing: %v"
,
dKey
.
(
string
),
err
))
dc
.
queue
.
AddRateLimited
(
dKey
)
return
true
}
}
func
(
dc
*
DisruptionController
)
sync
(
key
string
)
error
{
func
(
dc
*
DisruptionController
)
sync
(
key
string
)
error
{
...
@@ -427,10 +423,10 @@ func (dc *DisruptionController) sync(key string) error {
...
@@ -427,10 +423,10 @@ func (dc *DisruptionController) sync(key string) error {
obj
,
exists
,
err
:=
dc
.
pdbLister
.
Store
.
GetByKey
(
key
)
obj
,
exists
,
err
:=
dc
.
pdbLister
.
Store
.
GetByKey
(
key
)
if
!
exists
{
if
!
exists
{
return
err
glog
.
V
(
4
)
.
Infof
(
"PodDisruptionBudget %q has been deleted"
,
key
)
return
nil
}
}
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"unable to retrieve PodDisruptionBudget %v from store: %v"
,
key
,
err
)
return
err
return
err
}
}
...
...
pkg/controller/disruption/disruption_test.go
View file @
2a117798
...
@@ -490,3 +490,13 @@ func TestTwoControllers(t *testing.T) {
...
@@ -490,3 +490,13 @@ func TestTwoControllers(t *testing.T) {
dc
.
sync
(
pdbName
)
dc
.
sync
(
pdbName
)
ps
.
VerifyPdbStatus
(
t
,
pdbName
,
true
,
7
,
7
,
22
)
ps
.
VerifyPdbStatus
(
t
,
pdbName
,
true
,
7
,
7
,
22
)
}
}
// Test pdb doesn't exist
func
TestPDBNotExist
(
t
*
testing
.
T
)
{
dc
,
_
:=
newFakeDisruptionController
()
pdb
,
_
:=
newPodDisruptionBudget
(
t
,
intstr
.
FromString
(
"67%"
))
add
(
t
,
dc
.
pdbLister
.
Store
,
pdb
)
if
err
:=
dc
.
sync
(
"notExist"
);
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v, expect nil"
,
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