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
e9e8fe6c
Commit
e9e8fe6c
authored
Mar 06, 2017
by
Anthony Yeh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
RC/RS: Fix ignoring inactive Pods.
parent
e82834e4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
8 deletions
+20
-8
replica_set.go
pkg/controller/replicaset/replica_set.go
+2
-2
replica_set_test.go
pkg/controller/replicaset/replica_set_test.go
+7
-1
replication_controller.go
pkg/controller/replication/replication_controller.go
+3
-3
replication_controller_test.go
pkg/controller/replication/replication_controller_test.go
+8
-2
No files found.
pkg/controller/replicaset/replica_set.go
View file @
e9e8fe6c
...
...
@@ -553,13 +553,13 @@ func (rsc *ReplicaSetController) syncReplicaSet(key string) error {
// list all pods to include the pods that don't match the rs`s selector
// anymore but has the stale controller ref.
// TODO: Do the List and Filter in a single pass, or use an index.
p
ods
,
err
:=
rsc
.
podLister
.
Pods
(
rs
.
Namespace
)
.
List
(
labels
.
Everything
())
allP
ods
,
err
:=
rsc
.
podLister
.
Pods
(
rs
.
Namespace
)
.
List
(
labels
.
Everything
())
if
err
!=
nil
{
return
err
}
// Ignore inactive pods.
var
filteredPods
[]
*
v1
.
Pod
for
_
,
pod
:=
range
p
ods
{
for
_
,
pod
:=
range
allP
ods
{
if
controller
.
IsPodActive
(
pod
)
{
filteredPods
=
append
(
filteredPods
,
pod
)
}
...
...
pkg/controller/replicaset/replica_set_test.go
View file @
e9e8fe6c
...
...
@@ -305,10 +305,16 @@ func TestSyncReplicaSetCreates(t *testing.T) {
defer
close
(
stopCh
)
manager
,
informers
:=
testNewReplicaSetControllerFromClient
(
client
,
stopCh
,
BurstReplicas
)
// A controller with 2 replicas and no pods in the store, 2 creates expected
// A controller with 2 replicas and no active pods in the store.
// Inactive pods should be ignored. 2 creates expected.
labelMap
:=
map
[
string
]
string
{
"foo"
:
"bar"
}
rs
:=
newReplicaSet
(
2
,
labelMap
)
informers
.
Extensions
()
.
V1beta1
()
.
ReplicaSets
()
.
Informer
()
.
GetIndexer
()
.
Add
(
rs
)
failedPod
:=
newPod
(
"failed-pod"
,
rs
,
v1
.
PodFailed
,
nil
,
true
)
deletedPod
:=
newPod
(
"deleted-pod"
,
rs
,
v1
.
PodRunning
,
nil
,
true
)
deletedPod
.
DeletionTimestamp
=
&
metav1
.
Time
{
Time
:
time
.
Now
()}
informers
.
Core
()
.
V1
()
.
Pods
()
.
Informer
()
.
GetIndexer
()
.
Add
(
failedPod
)
informers
.
Core
()
.
V1
()
.
Pods
()
.
Informer
()
.
GetIndexer
()
.
Add
(
deletedPod
)
fakePodControl
:=
controller
.
FakePodControl
{}
manager
.
podControl
=
&
fakePodControl
...
...
pkg/controller/replication/replication_controller.go
View file @
e9e8fe6c
...
...
@@ -571,13 +571,13 @@ func (rm *ReplicationManager) syncReplicationController(key string) error {
// list all pods to include the pods that don't match the rc's selector
// anymore but has the stale controller ref.
// TODO: Do the List and Filter in a single pass, or use an index.
p
ods
,
err
:=
rm
.
podLister
.
Pods
(
rc
.
Namespace
)
.
List
(
labels
.
Everything
())
allP
ods
,
err
:=
rm
.
podLister
.
Pods
(
rc
.
Namespace
)
.
List
(
labels
.
Everything
())
if
err
!=
nil
{
return
err
}
// Ignore inactive pods.
var
filteredPods
[]
*
v1
.
Pod
for
_
,
pod
:=
range
p
ods
{
for
_
,
pod
:=
range
allP
ods
{
if
controller
.
IsPodActive
(
pod
)
{
filteredPods
=
append
(
filteredPods
,
pod
)
}
...
...
@@ -585,7 +585,7 @@ func (rm *ReplicationManager) syncReplicationController(key string) error {
cm
:=
controller
.
NewPodControllerRefManager
(
rm
.
podControl
,
rc
,
labels
.
Set
(
rc
.
Spec
.
Selector
)
.
AsSelectorPreValidated
(),
controllerKind
)
// NOTE: filteredPods are pointing to objects from cache - if you need to
// modify them, you need to copy it first.
filteredPods
,
err
=
cm
.
ClaimPods
(
p
ods
)
filteredPods
,
err
=
cm
.
ClaimPods
(
filteredP
ods
)
if
err
!=
nil
{
return
err
}
...
...
pkg/controller/replication/replication_controller_test.go
View file @
e9e8fe6c
...
...
@@ -259,11 +259,17 @@ func TestDeleteFinalStateUnknown(t *testing.T) {
func
TestSyncReplicationControllerCreates
(
t
*
testing
.
T
)
{
c
:=
clientset
.
NewForConfigOrDie
(
&
restclient
.
Config
{
Host
:
""
,
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
&
api
.
Registry
.
GroupOrDie
(
v1
.
GroupName
)
.
GroupVersion
}})
manager
,
_
,
rcInformer
:=
newReplicationManagerFromClient
(
c
,
BurstReplicas
)
manager
,
podInformer
,
rcInformer
:=
newReplicationManagerFromClient
(
c
,
BurstReplicas
)
// A controller with 2 replicas and no pods in the store, 2 creates expected
// A controller with 2 replicas and no active pods in the store.
// Inactive pods should be ignored. 2 creates expected.
rc
:=
newReplicationController
(
2
)
rcInformer
.
Informer
()
.
GetIndexer
()
.
Add
(
rc
)
failedPod
:=
newPod
(
"failed-pod"
,
rc
,
v1
.
PodFailed
,
nil
,
true
)
deletedPod
:=
newPod
(
"deleted-pod"
,
rc
,
v1
.
PodRunning
,
nil
,
true
)
deletedPod
.
DeletionTimestamp
=
&
metav1
.
Time
{
Time
:
time
.
Now
()}
podInformer
.
Informer
()
.
GetIndexer
()
.
Add
(
failedPod
)
podInformer
.
Informer
()
.
GetIndexer
()
.
Add
(
deletedPod
)
fakePodControl
:=
controller
.
FakePodControl
{}
manager
.
podControl
=
&
fakePodControl
...
...
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