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
6b35ff72
Commit
6b35ff72
authored
Feb 09, 2017
by
Mayank Kumar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable Garbage collection by default for RS and RC
parent
8e13ee01
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
110 additions
and
143 deletions
+110
-143
core.go
cmd/kube-controller-manager/app/core.go
+0
-1
extensions.go
cmd/kube-controller-manager/app/extensions.go
+0
-1
replica_set.go
pkg/controller/replicaset/replica_set.go
+22
-39
replica_set_test.go
pkg/controller/replicaset/replica_set_test.go
+23
-21
replication_controller.go
pkg/controller/replication/replication_controller.go
+24
-43
replication_controller_test.go
pkg/controller/replication/replication_controller_test.go
+27
-21
master_utils.go
test/integration/framework/master_utils.go
+1
-1
quota_test.go
test/integration/quota/quota_test.go
+0
-2
replicaset_test.go
test/integration/replicaset/replicaset_test.go
+6
-7
replicationcontroller_test.go
...ation/replicationcontroller/replicationcontroller_test.go
+7
-7
No files found.
cmd/kube-controller-manager/app/core.go
View file @
6b35ff72
...
@@ -60,7 +60,6 @@ func startReplicationController(ctx ControllerContext) (bool, error) {
...
@@ -60,7 +60,6 @@ func startReplicationController(ctx ControllerContext) (bool, error) {
ctx
.
ClientBuilder
.
ClientOrDie
(
"replication-controller"
),
ctx
.
ClientBuilder
.
ClientOrDie
(
"replication-controller"
),
replicationcontroller
.
BurstReplicas
,
replicationcontroller
.
BurstReplicas
,
int
(
ctx
.
Options
.
LookupCacheSizeForRC
),
int
(
ctx
.
Options
.
LookupCacheSizeForRC
),
ctx
.
Options
.
EnableGarbageCollector
,
)
.
Run
(
int
(
ctx
.
Options
.
ConcurrentRCSyncs
),
ctx
.
Stop
)
)
.
Run
(
int
(
ctx
.
Options
.
ConcurrentRCSyncs
),
ctx
.
Stop
)
return
true
,
nil
return
true
,
nil
}
}
...
...
cmd/kube-controller-manager/app/extensions.go
View file @
6b35ff72
...
@@ -64,7 +64,6 @@ func startReplicaSetController(ctx ControllerContext) (bool, error) {
...
@@ -64,7 +64,6 @@ func startReplicaSetController(ctx ControllerContext) (bool, error) {
ctx
.
ClientBuilder
.
ClientOrDie
(
"replicaset-controller"
),
ctx
.
ClientBuilder
.
ClientOrDie
(
"replicaset-controller"
),
replicaset
.
BurstReplicas
,
replicaset
.
BurstReplicas
,
int
(
ctx
.
Options
.
LookupCacheSizeForRS
),
int
(
ctx
.
Options
.
LookupCacheSizeForRS
),
ctx
.
Options
.
EnableGarbageCollector
,
)
.
Run
(
int
(
ctx
.
Options
.
ConcurrentRSSyncs
),
ctx
.
Stop
)
)
.
Run
(
int
(
ctx
.
Options
.
ConcurrentRSSyncs
),
ctx
.
Stop
)
return
true
,
nil
return
true
,
nil
}
}
pkg/controller/replicaset/replica_set.go
View file @
6b35ff72
...
@@ -94,14 +94,10 @@ type ReplicaSetController struct {
...
@@ -94,14 +94,10 @@ type ReplicaSetController struct {
// Controllers that need to be synced
// Controllers that need to be synced
queue
workqueue
.
RateLimitingInterface
queue
workqueue
.
RateLimitingInterface
// garbageCollectorEnabled denotes if the garbage collector is enabled. RC
// manager behaves differently if GC is enabled.
garbageCollectorEnabled
bool
}
}
// NewReplicaSetController configures a replica set controller with the specified event recorder
// NewReplicaSetController configures a replica set controller with the specified event recorder
func
NewReplicaSetController
(
rsInformer
extensionsinformers
.
ReplicaSetInformer
,
podInformer
coreinformers
.
PodInformer
,
kubeClient
clientset
.
Interface
,
burstReplicas
int
,
lookupCacheSize
int
,
garbageCollectorEnabled
bool
)
*
ReplicaSetController
{
func
NewReplicaSetController
(
rsInformer
extensionsinformers
.
ReplicaSetInformer
,
podInformer
coreinformers
.
PodInformer
,
kubeClient
clientset
.
Interface
,
burstReplicas
int
,
lookupCacheSize
int
)
*
ReplicaSetController
{
if
kubeClient
!=
nil
&&
kubeClient
.
Core
()
.
RESTClient
()
.
GetRateLimiter
()
!=
nil
{
if
kubeClient
!=
nil
&&
kubeClient
.
Core
()
.
RESTClient
()
.
GetRateLimiter
()
!=
nil
{
metrics
.
RegisterMetricAndTrackRateLimiterUsage
(
"replicaset_controller"
,
kubeClient
.
Core
()
.
RESTClient
()
.
GetRateLimiter
())
metrics
.
RegisterMetricAndTrackRateLimiterUsage
(
"replicaset_controller"
,
kubeClient
.
Core
()
.
RESTClient
()
.
GetRateLimiter
())
}
}
...
@@ -118,7 +114,6 @@ func NewReplicaSetController(rsInformer extensionsinformers.ReplicaSetInformer,
...
@@ -118,7 +114,6 @@ func NewReplicaSetController(rsInformer extensionsinformers.ReplicaSetInformer,
burstReplicas
:
burstReplicas
,
burstReplicas
:
burstReplicas
,
expectations
:
controller
.
NewUIDTrackingControllerExpectations
(
controller
.
NewControllerExpectations
()),
expectations
:
controller
.
NewUIDTrackingControllerExpectations
(
controller
.
NewControllerExpectations
()),
queue
:
workqueue
.
NewNamedRateLimitingQueue
(
workqueue
.
DefaultControllerRateLimiter
(),
"replicaset"
),
queue
:
workqueue
.
NewNamedRateLimitingQueue
(
workqueue
.
DefaultControllerRateLimiter
(),
"replicaset"
),
garbageCollectorEnabled
:
garbageCollectorEnabled
,
}
}
rsInformer
.
Informer
()
.
AddEventHandler
(
cache
.
ResourceEventHandlerFuncs
{
rsInformer
.
Informer
()
.
AddEventHandler
(
cache
.
ResourceEventHandlerFuncs
{
...
@@ -487,19 +482,15 @@ func (rsc *ReplicaSetController) manageReplicas(filteredPods []*v1.Pod, rs *exte
...
@@ -487,19 +482,15 @@ func (rsc *ReplicaSetController) manageReplicas(filteredPods []*v1.Pod, rs *exte
defer
wg
.
Done
()
defer
wg
.
Done
()
var
err
error
var
err
error
if
rsc
.
garbageCollectorEnabled
{
var
trueVar
=
true
var
trueVar
=
true
controllerRef
:=
&
metav1
.
OwnerReference
{
controllerRef
:=
&
metav1
.
OwnerReference
{
APIVersion
:
getRSKind
()
.
GroupVersion
()
.
String
(),
APIVersion
:
getRSKind
()
.
GroupVersion
()
.
String
(),
Kind
:
getRSKind
()
.
Kind
,
Kind
:
getRSKind
()
.
Kind
,
Name
:
rs
.
Name
,
Name
:
rs
.
Name
,
UID
:
rs
.
UID
,
UID
:
rs
.
UID
,
Controller
:
&
trueVar
,
Controller
:
&
trueVar
,
}
err
=
rsc
.
podControl
.
CreatePodsWithControllerRef
(
rs
.
Namespace
,
&
rs
.
Spec
.
Template
,
rs
,
controllerRef
)
}
else
{
err
=
rsc
.
podControl
.
CreatePods
(
rs
.
Namespace
,
&
rs
.
Spec
.
Template
,
rs
)
}
}
err
=
rsc
.
podControl
.
CreatePodsWithControllerRef
(
rs
.
Namespace
,
&
rs
.
Spec
.
Template
,
rs
,
controllerRef
)
if
err
!=
nil
{
if
err
!=
nil
{
// Decrement the expected number of creates because the informer won't observe this pod
// Decrement the expected number of creates because the informer won't observe this pod
glog
.
V
(
2
)
.
Infof
(
"Failed creation, decrementing expectations for replica set %q/%q"
,
rs
.
Namespace
,
rs
.
Name
)
glog
.
V
(
2
)
.
Infof
(
"Failed creation, decrementing expectations for replica set %q/%q"
,
rs
.
Namespace
,
rs
.
Name
)
...
@@ -595,27 +586,19 @@ func (rsc *ReplicaSetController) syncReplicaSet(key string) error {
...
@@ -595,27 +586,19 @@ func (rsc *ReplicaSetController) syncReplicaSet(key string) error {
// modify them, you need to copy it first.
// modify them, you need to copy it first.
// TODO: Do the List and Filter in a single pass, or use an index.
// TODO: Do the List and Filter in a single pass, or use an index.
var
filteredPods
[]
*
v1
.
Pod
var
filteredPods
[]
*
v1
.
Pod
if
rsc
.
garbageCollectorEnabled
{
// list all pods to include the pods that don't match the rs`s selector
// list all pods to include the pods that don't match the rs`s selector
// anymore but has the stale controller ref.
// anymore but has the stale controller ref.
pods
,
err
:=
rsc
.
podLister
.
Pods
(
rs
.
Namespace
)
.
List
(
labels
.
Everything
())
pods
,
err
:=
rsc
.
podLister
.
Pods
(
rs
.
Namespace
)
.
List
(
labels
.
Everything
())
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
cm
:=
controller
.
NewPodControllerRefManager
(
rsc
.
podControl
,
rs
,
selector
,
getRSKind
())
cm
:=
controller
.
NewPodControllerRefManager
(
rsc
.
podControl
,
rs
,
selector
,
getRSKind
())
filteredPods
,
err
=
cm
.
ClaimPods
(
pods
)
filteredPods
,
err
=
cm
.
ClaimPods
(
pods
)
if
err
!=
nil
{
if
err
!=
nil
{
// Something went wrong with adoption or release.
// Something went wrong with adoption or release.
// Requeue and try again so we don't leave orphans sitting around.
// Requeue and try again so we don't leave orphans sitting around.
rsc
.
queue
.
Add
(
key
)
rsc
.
queue
.
Add
(
key
)
return
err
return
err
}
}
else
{
pods
,
err
:=
rsc
.
podLister
.
Pods
(
rs
.
Namespace
)
.
List
(
selector
)
if
err
!=
nil
{
return
err
}
filteredPods
=
controller
.
FilterActivePods
(
pods
)
}
}
var
manageReplicasErr
error
var
manageReplicasErr
error
...
...
pkg/controller/replicaset/replica_set_test.go
View file @
6b35ff72
...
@@ -60,7 +60,6 @@ func testNewReplicaSetControllerFromClient(client clientset.Interface, stopCh ch
...
@@ -60,7 +60,6 @@ func testNewReplicaSetControllerFromClient(client clientset.Interface, stopCh ch
client
,
client
,
burstReplicas
,
burstReplicas
,
lookupCacheSize
,
lookupCacheSize
,
false
,
)
)
ret
.
podListerSynced
=
alwaysReady
ret
.
podListerSynced
=
alwaysReady
...
@@ -147,7 +146,7 @@ func newReplicaSet(replicas int, selectorMap map[string]string) *extensions.Repl
...
@@ -147,7 +146,7 @@ func newReplicaSet(replicas int, selectorMap map[string]string) *extensions.Repl
}
}
// create a pod with the given phase for the given rs (same selectors and namespace)
// create a pod with the given phase for the given rs (same selectors and namespace)
func
newPod
(
name
string
,
rs
*
extensions
.
ReplicaSet
,
status
v1
.
PodPhase
,
lastTransitionTime
*
metav1
.
Time
)
*
v1
.
Pod
{
func
newPod
(
name
string
,
rs
*
extensions
.
ReplicaSet
,
status
v1
.
PodPhase
,
lastTransitionTime
*
metav1
.
Time
,
properlyOwned
bool
)
*
v1
.
Pod
{
var
conditions
[]
v1
.
PodCondition
var
conditions
[]
v1
.
PodCondition
if
status
==
v1
.
PodRunning
{
if
status
==
v1
.
PodRunning
{
condition
:=
v1
.
PodCondition
{
Type
:
v1
.
PodReady
,
Status
:
v1
.
ConditionTrue
}
condition
:=
v1
.
PodCondition
{
Type
:
v1
.
PodReady
,
Status
:
v1
.
ConditionTrue
}
...
@@ -156,11 +155,17 @@ func newPod(name string, rs *extensions.ReplicaSet, status v1.PodPhase, lastTran
...
@@ -156,11 +155,17 @@ func newPod(name string, rs *extensions.ReplicaSet, status v1.PodPhase, lastTran
}
}
conditions
=
append
(
conditions
,
condition
)
conditions
=
append
(
conditions
,
condition
)
}
}
var
controllerReference
metav1
.
OwnerReference
if
properlyOwned
{
var
trueVar
=
true
controllerReference
=
metav1
.
OwnerReference
{
UID
:
rs
.
UID
,
APIVersion
:
"v1beta1"
,
Kind
:
"ReplicaSet"
,
Name
:
rs
.
Name
,
Controller
:
&
trueVar
}
}
return
&
v1
.
Pod
{
return
&
v1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
name
,
Name
:
name
,
Namespace
:
rs
.
Namespace
,
Namespace
:
rs
.
Namespace
,
Labels
:
rs
.
Spec
.
Selector
.
MatchLabels
,
Labels
:
rs
.
Spec
.
Selector
.
MatchLabels
,
OwnerReferences
:
[]
metav1
.
OwnerReference
{
controllerReference
},
},
},
Status
:
v1
.
PodStatus
{
Phase
:
status
,
Conditions
:
conditions
},
Status
:
v1
.
PodStatus
{
Phase
:
status
,
Conditions
:
conditions
},
}
}
...
@@ -172,7 +177,7 @@ func newPodList(store cache.Store, count int, status v1.PodPhase, labelMap map[s
...
@@ -172,7 +177,7 @@ func newPodList(store cache.Store, count int, status v1.PodPhase, labelMap map[s
var
trueVar
=
true
var
trueVar
=
true
controllerReference
:=
metav1
.
OwnerReference
{
UID
:
rs
.
UID
,
APIVersion
:
"v1beta1"
,
Kind
:
"ReplicaSet"
,
Name
:
rs
.
Name
,
Controller
:
&
trueVar
}
controllerReference
:=
metav1
.
OwnerReference
{
UID
:
rs
.
UID
,
APIVersion
:
"v1beta1"
,
Kind
:
"ReplicaSet"
,
Name
:
rs
.
Name
,
Controller
:
&
trueVar
}
for
i
:=
0
;
i
<
count
;
i
++
{
for
i
:=
0
;
i
<
count
;
i
++
{
pod
:=
newPod
(
fmt
.
Sprintf
(
"%s%d"
,
name
,
i
),
rs
,
status
,
nil
)
pod
:=
newPod
(
fmt
.
Sprintf
(
"%s%d"
,
name
,
i
),
rs
,
status
,
nil
,
false
)
pod
.
ObjectMeta
.
Labels
=
labelMap
pod
.
ObjectMeta
.
Labels
=
labelMap
pod
.
OwnerReferences
=
[]
metav1
.
OwnerReference
{
controllerReference
}
pod
.
OwnerReferences
=
[]
metav1
.
OwnerReference
{
controllerReference
}
if
store
!=
nil
{
if
store
!=
nil
{
...
@@ -532,7 +537,6 @@ func TestWatchControllers(t *testing.T) {
...
@@ -532,7 +537,6 @@ func TestWatchControllers(t *testing.T) {
client
,
client
,
BurstReplicas
,
BurstReplicas
,
0
,
0
,
false
,
)
)
informers
.
Start
(
stopCh
)
informers
.
Start
(
stopCh
)
...
@@ -1135,12 +1139,10 @@ func TestDeletionTimestamp(t *testing.T) {
...
@@ -1135,12 +1139,10 @@ func TestDeletionTimestamp(t *testing.T) {
}
}
// setupManagerWithGCEnabled creates a RS manager with a fakePodControl
// setupManagerWithGCEnabled creates a RS manager with a fakePodControl
// and with garbageCollectorEnabled set to true
func
setupManagerWithGCEnabled
(
stopCh
chan
struct
{},
objs
...
runtime
.
Object
)
(
manager
*
ReplicaSetController
,
fakePodControl
*
controller
.
FakePodControl
,
informers
informers
.
SharedInformerFactory
)
{
func
setupManagerWithGCEnabled
(
stopCh
chan
struct
{},
objs
...
runtime
.
Object
)
(
manager
*
ReplicaSetController
,
fakePodControl
*
controller
.
FakePodControl
,
informers
informers
.
SharedInformerFactory
)
{
c
:=
fakeclientset
.
NewSimpleClientset
(
objs
...
)
c
:=
fakeclientset
.
NewSimpleClientset
(
objs
...
)
fakePodControl
=
&
controller
.
FakePodControl
{}
fakePodControl
=
&
controller
.
FakePodControl
{}
manager
,
informers
=
testNewReplicaSetControllerFromClient
(
c
,
stopCh
,
BurstReplicas
,
0
)
manager
,
informers
=
testNewReplicaSetControllerFromClient
(
c
,
stopCh
,
BurstReplicas
,
0
)
manager
.
garbageCollectorEnabled
=
true
manager
.
podControl
=
fakePodControl
manager
.
podControl
=
fakePodControl
return
manager
,
fakePodControl
,
informers
return
manager
,
fakePodControl
,
informers
...
@@ -1156,7 +1158,7 @@ func TestDoNotPatchPodWithOtherControlRef(t *testing.T) {
...
@@ -1156,7 +1158,7 @@ func TestDoNotPatchPodWithOtherControlRef(t *testing.T) {
var
trueVar
=
true
var
trueVar
=
true
otherControllerReference
:=
metav1
.
OwnerReference
{
UID
:
uuid
.
NewUUID
(),
APIVersion
:
"v1beta1"
,
Kind
:
"ReplicaSet"
,
Name
:
"AnotherRS"
,
Controller
:
&
trueVar
}
otherControllerReference
:=
metav1
.
OwnerReference
{
UID
:
uuid
.
NewUUID
(),
APIVersion
:
"v1beta1"
,
Kind
:
"ReplicaSet"
,
Name
:
"AnotherRS"
,
Controller
:
&
trueVar
}
// add to podLister a matching Pod controlled by another controller. Expect no patch.
// add to podLister a matching Pod controlled by another controller. Expect no patch.
pod
:=
newPod
(
"pod"
,
rs
,
v1
.
PodRunning
,
nil
)
pod
:=
newPod
(
"pod"
,
rs
,
v1
.
PodRunning
,
nil
,
true
)
pod
.
OwnerReferences
=
[]
metav1
.
OwnerReference
{
otherControllerReference
}
pod
.
OwnerReferences
=
[]
metav1
.
OwnerReference
{
otherControllerReference
}
informers
.
Core
()
.
V1
()
.
Pods
()
.
Informer
()
.
GetIndexer
()
.
Add
(
pod
)
informers
.
Core
()
.
V1
()
.
Pods
()
.
Informer
()
.
GetIndexer
()
.
Add
(
pod
)
err
:=
manager
.
syncReplicaSet
(
getKey
(
rs
,
t
))
err
:=
manager
.
syncReplicaSet
(
getKey
(
rs
,
t
))
...
@@ -1178,7 +1180,7 @@ func TestPatchPodWithOtherOwnerRef(t *testing.T) {
...
@@ -1178,7 +1180,7 @@ func TestPatchPodWithOtherOwnerRef(t *testing.T) {
// ref, but has an owner ref pointing to other object. Expect a patch to
// ref, but has an owner ref pointing to other object. Expect a patch to
// take control of it.
// take control of it.
unrelatedOwnerReference
:=
metav1
.
OwnerReference
{
UID
:
uuid
.
NewUUID
(),
APIVersion
:
"batch/v1"
,
Kind
:
"Job"
,
Name
:
"Job"
}
unrelatedOwnerReference
:=
metav1
.
OwnerReference
{
UID
:
uuid
.
NewUUID
(),
APIVersion
:
"batch/v1"
,
Kind
:
"Job"
,
Name
:
"Job"
}
pod
:=
newPod
(
"pod"
,
rs
,
v1
.
PodRunning
,
nil
)
pod
:=
newPod
(
"pod"
,
rs
,
v1
.
PodRunning
,
nil
,
false
)
pod
.
OwnerReferences
=
[]
metav1
.
OwnerReference
{
unrelatedOwnerReference
}
pod
.
OwnerReferences
=
[]
metav1
.
OwnerReference
{
unrelatedOwnerReference
}
informers
.
Core
()
.
V1
()
.
Pods
()
.
Informer
()
.
GetIndexer
()
.
Add
(
pod
)
informers
.
Core
()
.
V1
()
.
Pods
()
.
Informer
()
.
GetIndexer
()
.
Add
(
pod
)
...
@@ -1200,7 +1202,7 @@ func TestPatchPodWithCorrectOwnerRef(t *testing.T) {
...
@@ -1200,7 +1202,7 @@ func TestPatchPodWithCorrectOwnerRef(t *testing.T) {
// add to podLister a matching pod that has an ownerRef pointing to the rs,
// add to podLister a matching pod that has an ownerRef pointing to the rs,
// but ownerRef.Controller is false. Expect a patch to take control it.
// but ownerRef.Controller is false. Expect a patch to take control it.
rsOwnerReference
:=
metav1
.
OwnerReference
{
UID
:
rs
.
UID
,
APIVersion
:
"v1"
,
Kind
:
"ReplicaSet"
,
Name
:
rs
.
Name
}
rsOwnerReference
:=
metav1
.
OwnerReference
{
UID
:
rs
.
UID
,
APIVersion
:
"v1"
,
Kind
:
"ReplicaSet"
,
Name
:
rs
.
Name
}
pod
:=
newPod
(
"pod"
,
rs
,
v1
.
PodRunning
,
nil
)
pod
:=
newPod
(
"pod"
,
rs
,
v1
.
PodRunning
,
nil
,
false
)
pod
.
OwnerReferences
=
[]
metav1
.
OwnerReference
{
rsOwnerReference
}
pod
.
OwnerReferences
=
[]
metav1
.
OwnerReference
{
rsOwnerReference
}
informers
.
Core
()
.
V1
()
.
Pods
()
.
Informer
()
.
GetIndexer
()
.
Add
(
pod
)
informers
.
Core
()
.
V1
()
.
Pods
()
.
Informer
()
.
GetIndexer
()
.
Add
(
pod
)
...
@@ -1221,8 +1223,8 @@ func TestPatchPodFails(t *testing.T) {
...
@@ -1221,8 +1223,8 @@ func TestPatchPodFails(t *testing.T) {
informers
.
Extensions
()
.
V1beta1
()
.
ReplicaSets
()
.
Informer
()
.
GetIndexer
()
.
Add
(
rs
)
informers
.
Extensions
()
.
V1beta1
()
.
ReplicaSets
()
.
Informer
()
.
GetIndexer
()
.
Add
(
rs
)
// add to podLister two matching pods. Expect two patches to take control
// add to podLister two matching pods. Expect two patches to take control
// them.
// them.
informers
.
Core
()
.
V1
()
.
Pods
()
.
Informer
()
.
GetIndexer
()
.
Add
(
newPod
(
"pod1"
,
rs
,
v1
.
PodRunning
,
nil
))
informers
.
Core
()
.
V1
()
.
Pods
()
.
Informer
()
.
GetIndexer
()
.
Add
(
newPod
(
"pod1"
,
rs
,
v1
.
PodRunning
,
nil
,
false
))
informers
.
Core
()
.
V1
()
.
Pods
()
.
Informer
()
.
GetIndexer
()
.
Add
(
newPod
(
"pod2"
,
rs
,
v1
.
PodRunning
,
nil
))
informers
.
Core
()
.
V1
()
.
Pods
()
.
Informer
()
.
GetIndexer
()
.
Add
(
newPod
(
"pod2"
,
rs
,
v1
.
PodRunning
,
nil
,
false
))
// let both patches fail. The rs controller will assume it fails to take
// let both patches fail. The rs controller will assume it fails to take
// control of the pods and requeue to try again.
// control of the pods and requeue to try again.
fakePodControl
.
Err
=
fmt
.
Errorf
(
"Fake Error"
)
fakePodControl
.
Err
=
fmt
.
Errorf
(
"Fake Error"
)
...
@@ -1249,9 +1251,9 @@ func TestPatchExtraPodsThenDelete(t *testing.T) {
...
@@ -1249,9 +1251,9 @@ func TestPatchExtraPodsThenDelete(t *testing.T) {
informers
.
Extensions
()
.
V1beta1
()
.
ReplicaSets
()
.
Informer
()
.
GetIndexer
()
.
Add
(
rs
)
informers
.
Extensions
()
.
V1beta1
()
.
ReplicaSets
()
.
Informer
()
.
GetIndexer
()
.
Add
(
rs
)
// add to podLister three matching pods. Expect three patches to take control
// add to podLister three matching pods. Expect three patches to take control
// them, and later delete one of them.
// them, and later delete one of them.
informers
.
Core
()
.
V1
()
.
Pods
()
.
Informer
()
.
GetIndexer
()
.
Add
(
newPod
(
"pod1"
,
rs
,
v1
.
PodRunning
,
nil
))
informers
.
Core
()
.
V1
()
.
Pods
()
.
Informer
()
.
GetIndexer
()
.
Add
(
newPod
(
"pod1"
,
rs
,
v1
.
PodRunning
,
nil
,
false
))
informers
.
Core
()
.
V1
()
.
Pods
()
.
Informer
()
.
GetIndexer
()
.
Add
(
newPod
(
"pod2"
,
rs
,
v1
.
PodRunning
,
nil
))
informers
.
Core
()
.
V1
()
.
Pods
()
.
Informer
()
.
GetIndexer
()
.
Add
(
newPod
(
"pod2"
,
rs
,
v1
.
PodRunning
,
nil
,
false
))
informers
.
Core
()
.
V1
()
.
Pods
()
.
Informer
()
.
GetIndexer
()
.
Add
(
newPod
(
"pod3"
,
rs
,
v1
.
PodRunning
,
nil
))
informers
.
Core
()
.
V1
()
.
Pods
()
.
Informer
()
.
GetIndexer
()
.
Add
(
newPod
(
"pod3"
,
rs
,
v1
.
PodRunning
,
nil
,
false
))
err
:=
manager
.
syncReplicaSet
(
getKey
(
rs
,
t
))
err
:=
manager
.
syncReplicaSet
(
getKey
(
rs
,
t
))
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
...
@@ -1268,7 +1270,7 @@ func TestUpdateLabelsRemoveControllerRef(t *testing.T) {
...
@@ -1268,7 +1270,7 @@ func TestUpdateLabelsRemoveControllerRef(t *testing.T) {
manager
,
fakePodControl
,
informers
:=
setupManagerWithGCEnabled
(
stopCh
,
rs
)
manager
,
fakePodControl
,
informers
:=
setupManagerWithGCEnabled
(
stopCh
,
rs
)
informers
.
Extensions
()
.
V1beta1
()
.
ReplicaSets
()
.
Informer
()
.
GetIndexer
()
.
Add
(
rs
)
informers
.
Extensions
()
.
V1beta1
()
.
ReplicaSets
()
.
Informer
()
.
GetIndexer
()
.
Add
(
rs
)
// put one pod in the podLister
// put one pod in the podLister
pod
:=
newPod
(
"pod"
,
rs
,
v1
.
PodRunning
,
nil
)
pod
:=
newPod
(
"pod"
,
rs
,
v1
.
PodRunning
,
nil
,
false
)
pod
.
ResourceVersion
=
"1"
pod
.
ResourceVersion
=
"1"
var
trueVar
=
true
var
trueVar
=
true
rsOwnerReference
:=
metav1
.
OwnerReference
{
UID
:
rs
.
UID
,
APIVersion
:
"v1beta1"
,
Kind
:
"ReplicaSet"
,
Name
:
rs
.
Name
,
Controller
:
&
trueVar
}
rsOwnerReference
:=
metav1
.
OwnerReference
{
UID
:
rs
.
UID
,
APIVersion
:
"v1beta1"
,
Kind
:
"ReplicaSet"
,
Name
:
rs
.
Name
,
Controller
:
&
trueVar
}
...
@@ -1346,7 +1348,7 @@ func TestDoNotAdoptOrCreateIfBeingDeleted(t *testing.T) {
...
@@ -1346,7 +1348,7 @@ func TestDoNotAdoptOrCreateIfBeingDeleted(t *testing.T) {
now
:=
metav1
.
Now
()
now
:=
metav1
.
Now
()
rs
.
DeletionTimestamp
=
&
now
rs
.
DeletionTimestamp
=
&
now
informers
.
Extensions
()
.
V1beta1
()
.
ReplicaSets
()
.
Informer
()
.
GetIndexer
()
.
Add
(
rs
)
informers
.
Extensions
()
.
V1beta1
()
.
ReplicaSets
()
.
Informer
()
.
GetIndexer
()
.
Add
(
rs
)
pod1
:=
newPod
(
"pod1"
,
rs
,
v1
.
PodRunning
,
nil
)
pod1
:=
newPod
(
"pod1"
,
rs
,
v1
.
PodRunning
,
nil
,
false
)
informers
.
Core
()
.
V1
()
.
Pods
()
.
Informer
()
.
GetIndexer
()
.
Add
(
pod1
)
informers
.
Core
()
.
V1
()
.
Pods
()
.
Informer
()
.
GetIndexer
()
.
Add
(
pod1
)
// no patch, no create
// no patch, no create
...
@@ -1425,12 +1427,12 @@ func TestAvailableReplicas(t *testing.T) {
...
@@ -1425,12 +1427,12 @@ func TestAvailableReplicas(t *testing.T) {
// First pod becomes ready 20s ago
// First pod becomes ready 20s ago
moment
:=
metav1
.
Time
{
Time
:
time
.
Now
()
.
Add
(
-
2e10
)}
moment
:=
metav1
.
Time
{
Time
:
time
.
Now
()
.
Add
(
-
2e10
)}
pod
:=
newPod
(
"pod"
,
rs
,
v1
.
PodRunning
,
&
moment
)
pod
:=
newPod
(
"pod"
,
rs
,
v1
.
PodRunning
,
&
moment
,
true
)
informers
.
Core
()
.
V1
()
.
Pods
()
.
Informer
()
.
GetIndexer
()
.
Add
(
pod
)
informers
.
Core
()
.
V1
()
.
Pods
()
.
Informer
()
.
GetIndexer
()
.
Add
(
pod
)
// Second pod becomes ready now
// Second pod becomes ready now
otherMoment
:=
metav1
.
Now
()
otherMoment
:=
metav1
.
Now
()
otherPod
:=
newPod
(
"otherPod"
,
rs
,
v1
.
PodRunning
,
&
otherMoment
)
otherPod
:=
newPod
(
"otherPod"
,
rs
,
v1
.
PodRunning
,
&
otherMoment
,
true
)
informers
.
Core
()
.
V1
()
.
Pods
()
.
Informer
()
.
GetIndexer
()
.
Add
(
otherPod
)
informers
.
Core
()
.
V1
()
.
Pods
()
.
Informer
()
.
GetIndexer
()
.
Add
(
otherPod
)
// This response body is just so we don't err out decoding the http response
// This response body is just so we don't err out decoding the http response
...
...
pkg/controller/replication/replication_controller.go
View file @
6b35ff72
...
@@ -89,14 +89,10 @@ type ReplicationManager struct {
...
@@ -89,14 +89,10 @@ type ReplicationManager struct {
// Controllers that need to be synced
// Controllers that need to be synced
queue
workqueue
.
RateLimitingInterface
queue
workqueue
.
RateLimitingInterface
// garbageCollectorEnabled denotes if the garbage collector is enabled. RC
// manager behaves differently if GC is enabled.
garbageCollectorEnabled
bool
}
}
// NewReplicationManager configures a replication manager with the specified event recorder
// NewReplicationManager configures a replication manager with the specified event recorder
func
NewReplicationManager
(
podInformer
coreinformers
.
PodInformer
,
rcInformer
coreinformers
.
ReplicationControllerInformer
,
kubeClient
clientset
.
Interface
,
burstReplicas
int
,
lookupCacheSize
int
,
garbageCollectorEnabled
bool
)
*
ReplicationManager
{
func
NewReplicationManager
(
podInformer
coreinformers
.
PodInformer
,
rcInformer
coreinformers
.
ReplicationControllerInformer
,
kubeClient
clientset
.
Interface
,
burstReplicas
int
,
lookupCacheSize
int
)
*
ReplicationManager
{
if
kubeClient
!=
nil
&&
kubeClient
.
Core
()
.
RESTClient
()
.
GetRateLimiter
()
!=
nil
{
if
kubeClient
!=
nil
&&
kubeClient
.
Core
()
.
RESTClient
()
.
GetRateLimiter
()
!=
nil
{
metrics
.
RegisterMetricAndTrackRateLimiterUsage
(
"replication_controller"
,
kubeClient
.
Core
()
.
RESTClient
()
.
GetRateLimiter
())
metrics
.
RegisterMetricAndTrackRateLimiterUsage
(
"replication_controller"
,
kubeClient
.
Core
()
.
RESTClient
()
.
GetRateLimiter
())
}
}
...
@@ -114,7 +110,6 @@ func NewReplicationManager(podInformer coreinformers.PodInformer, rcInformer cor
...
@@ -114,7 +110,6 @@ func NewReplicationManager(podInformer coreinformers.PodInformer, rcInformer cor
burstReplicas
:
burstReplicas
,
burstReplicas
:
burstReplicas
,
expectations
:
controller
.
NewUIDTrackingControllerExpectations
(
controller
.
NewControllerExpectations
()),
expectations
:
controller
.
NewUIDTrackingControllerExpectations
(
controller
.
NewControllerExpectations
()),
queue
:
workqueue
.
NewNamedRateLimitingQueue
(
workqueue
.
DefaultControllerRateLimiter
(),
"replicationmanager"
),
queue
:
workqueue
.
NewNamedRateLimitingQueue
(
workqueue
.
DefaultControllerRateLimiter
(),
"replicationmanager"
),
garbageCollectorEnabled
:
garbageCollectorEnabled
,
}
}
rcInformer
.
Informer
()
.
AddEventHandler
(
cache
.
ResourceEventHandlerFuncs
{
rcInformer
.
Informer
()
.
AddEventHandler
(
cache
.
ResourceEventHandlerFuncs
{
...
@@ -484,19 +479,15 @@ func (rm *ReplicationManager) manageReplicas(filteredPods []*v1.Pod, rc *v1.Repl
...
@@ -484,19 +479,15 @@ func (rm *ReplicationManager) manageReplicas(filteredPods []*v1.Pod, rc *v1.Repl
go
func
()
{
go
func
()
{
defer
wg
.
Done
()
defer
wg
.
Done
()
var
err
error
var
err
error
if
rm
.
garbageCollectorEnabled
{
var
trueVar
=
true
var
trueVar
=
true
controllerRef
:=
&
metav1
.
OwnerReference
{
controllerRef
:=
&
metav1
.
OwnerReference
{
APIVersion
:
getRCKind
()
.
GroupVersion
()
.
String
(),
APIVersion
:
getRCKind
()
.
GroupVersion
()
.
String
(),
Kind
:
getRCKind
()
.
Kind
,
Kind
:
getRCKind
()
.
Kind
,
Name
:
rc
.
Name
,
Name
:
rc
.
Name
,
UID
:
rc
.
UID
,
UID
:
rc
.
UID
,
Controller
:
&
trueVar
,
Controller
:
&
trueVar
,
}
err
=
rm
.
podControl
.
CreatePodsWithControllerRef
(
rc
.
Namespace
,
rc
.
Spec
.
Template
,
rc
,
controllerRef
)
}
else
{
err
=
rm
.
podControl
.
CreatePods
(
rc
.
Namespace
,
rc
.
Spec
.
Template
,
rc
)
}
}
err
=
rm
.
podControl
.
CreatePodsWithControllerRef
(
rc
.
Namespace
,
rc
.
Spec
.
Template
,
rc
,
controllerRef
)
if
err
!=
nil
{
if
err
!=
nil
{
// Decrement the expected number of creates because the informer won't observe this pod
// Decrement the expected number of creates because the informer won't observe this pod
glog
.
V
(
2
)
.
Infof
(
"Failed creation, decrementing expectations for controller %q/%q"
,
rc
.
Namespace
,
rc
.
Name
)
glog
.
V
(
2
)
.
Infof
(
"Failed creation, decrementing expectations for controller %q/%q"
,
rc
.
Namespace
,
rc
.
Name
)
...
@@ -610,31 +601,21 @@ func (rm *ReplicationManager) syncReplicationController(key string) error {
...
@@ -610,31 +601,21 @@ func (rm *ReplicationManager) syncReplicationController(key string) error {
// modify them, you need to copy it first.
// modify them, you need to copy it first.
// TODO: Do the List and Filter in a single pass, or use an index.
// TODO: Do the List and Filter in a single pass, or use an index.
var
filteredPods
[]
*
v1
.
Pod
var
filteredPods
[]
*
v1
.
Pod
if
rm
.
garbageCollectorEnabled
{
// list all pods to include the pods that don't match the rc's selector
// list all pods to include the pods that don't match the rc's selector
// anymore but has the stale controller ref.
// anymore but has the stale controller ref.
pods
,
err
:=
rm
.
podLister
.
Pods
(
rc
.
Namespace
)
.
List
(
labels
.
Everything
())
pods
,
err
:=
rm
.
podLister
.
Pods
(
rc
.
Namespace
)
.
List
(
labels
.
Everything
())
if
err
!=
nil
{
if
err
!=
nil
{
utilruntime
.
HandleError
(
fmt
.
Errorf
(
"Error getting pods for rc %q: %v"
,
key
,
err
))
utilruntime
.
HandleError
(
fmt
.
Errorf
(
"Error getting pods for rc %q: %v"
,
key
,
err
))
rm
.
queue
.
Add
(
key
)
rm
.
queue
.
Add
(
key
)
return
err
return
err
}
}
cm
:=
controller
.
NewPodControllerRefManager
(
rm
.
podControl
,
rc
,
labels
.
Set
(
rc
.
Spec
.
Selector
)
.
AsSelectorPreValidated
(),
getRCKind
())
cm
:=
controller
.
NewPodControllerRefManager
(
rm
.
podControl
,
rc
,
labels
.
Set
(
rc
.
Spec
.
Selector
)
.
AsSelectorPreValidated
(),
getRCKind
())
filteredPods
,
err
=
cm
.
ClaimPods
(
pods
)
filteredPods
,
err
=
cm
.
ClaimPods
(
pods
)
if
err
!=
nil
{
if
err
!=
nil
{
// Something went wrong with adoption or release.
// Something went wrong with adoption or release.
// Requeue and try again so we don't leave orphans sitting around.
// Requeue and try again so we don't leave orphans sitting around.
rm
.
queue
.
Add
(
key
)
rm
.
queue
.
Add
(
key
)
return
err
return
err
}
}
else
{
pods
,
err
:=
rm
.
podLister
.
Pods
(
rc
.
Namespace
)
.
List
(
labels
.
Set
(
rc
.
Spec
.
Selector
)
.
AsSelectorPreValidated
())
if
err
!=
nil
{
utilruntime
.
HandleError
(
fmt
.
Errorf
(
"Error getting pods for rc %q: %v"
,
key
,
err
))
rm
.
queue
.
Add
(
key
)
return
err
}
filteredPods
=
controller
.
FilterActivePods
(
pods
)
}
}
var
manageReplicasErr
error
var
manageReplicasErr
error
...
...
pkg/controller/replication/replication_controller_test.go
View file @
6b35ff72
...
@@ -102,7 +102,7 @@ func newReplicationController(replicas int) *v1.ReplicationController {
...
@@ -102,7 +102,7 @@ func newReplicationController(replicas int) *v1.ReplicationController {
}
}
// create a pod with the given phase for the given rc (same selectors and namespace).
// create a pod with the given phase for the given rc (same selectors and namespace).
func
newPod
(
name
string
,
rc
*
v1
.
ReplicationController
,
status
v1
.
PodPhase
,
lastTransitionTime
*
metav1
.
Time
)
*
v1
.
Pod
{
func
newPod
(
name
string
,
rc
*
v1
.
ReplicationController
,
status
v1
.
PodPhase
,
lastTransitionTime
*
metav1
.
Time
,
properlyOwned
bool
)
*
v1
.
Pod
{
var
conditions
[]
v1
.
PodCondition
var
conditions
[]
v1
.
PodCondition
if
status
==
v1
.
PodRunning
{
if
status
==
v1
.
PodRunning
{
condition
:=
v1
.
PodCondition
{
Type
:
v1
.
PodReady
,
Status
:
v1
.
ConditionTrue
}
condition
:=
v1
.
PodCondition
{
Type
:
v1
.
PodReady
,
Status
:
v1
.
ConditionTrue
}
...
@@ -111,11 +111,18 @@ func newPod(name string, rc *v1.ReplicationController, status v1.PodPhase, lastT
...
@@ -111,11 +111,18 @@ func newPod(name string, rc *v1.ReplicationController, status v1.PodPhase, lastT
}
}
conditions
=
append
(
conditions
,
condition
)
conditions
=
append
(
conditions
,
condition
)
}
}
var
controllerReference
metav1
.
OwnerReference
if
properlyOwned
{
var
trueVar
=
true
controllerReference
=
metav1
.
OwnerReference
{
UID
:
rc
.
UID
,
APIVersion
:
"v1beta1"
,
Kind
:
"ReplicaSet"
,
Name
:
rc
.
Name
,
Controller
:
&
trueVar
}
}
return
&
v1
.
Pod
{
return
&
v1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
name
,
Name
:
name
,
Labels
:
rc
.
Spec
.
Selector
,
Labels
:
rc
.
Spec
.
Selector
,
Namespace
:
rc
.
Namespace
,
Namespace
:
rc
.
Namespace
,
OwnerReferences
:
[]
metav1
.
OwnerReference
{
controllerReference
},
},
},
Status
:
v1
.
PodStatus
{
Phase
:
status
,
Conditions
:
conditions
},
Status
:
v1
.
PodStatus
{
Phase
:
status
,
Conditions
:
conditions
},
}
}
...
@@ -127,7 +134,7 @@ func newPodList(store cache.Store, count int, status v1.PodPhase, rc *v1.Replica
...
@@ -127,7 +134,7 @@ func newPodList(store cache.Store, count int, status v1.PodPhase, rc *v1.Replica
var
trueVar
=
true
var
trueVar
=
true
controllerReference
:=
metav1
.
OwnerReference
{
UID
:
rc
.
UID
,
APIVersion
:
"v1"
,
Kind
:
"ReplicationController"
,
Name
:
rc
.
Name
,
Controller
:
&
trueVar
}
controllerReference
:=
metav1
.
OwnerReference
{
UID
:
rc
.
UID
,
APIVersion
:
"v1"
,
Kind
:
"ReplicationController"
,
Name
:
rc
.
Name
,
Controller
:
&
trueVar
}
for
i
:=
0
;
i
<
count
;
i
++
{
for
i
:=
0
;
i
<
count
;
i
++
{
pod
:=
newPod
(
fmt
.
Sprintf
(
"%s%d"
,
name
,
i
),
rc
,
status
,
nil
)
pod
:=
newPod
(
fmt
.
Sprintf
(
"%s%d"
,
name
,
i
),
rc
,
status
,
nil
,
false
)
pod
.
OwnerReferences
=
[]
metav1
.
OwnerReference
{
controllerReference
}
pod
.
OwnerReferences
=
[]
metav1
.
OwnerReference
{
controllerReference
}
if
store
!=
nil
{
if
store
!=
nil
{
store
.
Add
(
pod
)
store
.
Add
(
pod
)
...
@@ -164,7 +171,7 @@ func NewReplicationManagerFromClient(kubeClient clientset.Interface, burstReplic
...
@@ -164,7 +171,7 @@ func NewReplicationManagerFromClient(kubeClient clientset.Interface, burstReplic
informerFactory
:=
informers
.
NewSharedInformerFactory
(
kubeClient
,
controller
.
NoResyncPeriodFunc
())
informerFactory
:=
informers
.
NewSharedInformerFactory
(
kubeClient
,
controller
.
NoResyncPeriodFunc
())
podInformer
:=
informerFactory
.
Core
()
.
V1
()
.
Pods
()
podInformer
:=
informerFactory
.
Core
()
.
V1
()
.
Pods
()
rcInformer
:=
informerFactory
.
Core
()
.
V1
()
.
ReplicationControllers
()
rcInformer
:=
informerFactory
.
Core
()
.
V1
()
.
ReplicationControllers
()
rm
:=
NewReplicationManager
(
podInformer
,
rcInformer
,
kubeClient
,
burstReplicas
,
lookupCacheSize
,
false
)
rm
:=
NewReplicationManager
(
podInformer
,
rcInformer
,
kubeClient
,
burstReplicas
,
lookupCacheSize
)
rm
.
podListerSynced
=
alwaysReady
rm
.
podListerSynced
=
alwaysReady
rm
.
rcListerSynced
=
alwaysReady
rm
.
rcListerSynced
=
alwaysReady
return
rm
,
podInformer
,
rcInformer
return
rm
,
podInformer
,
rcInformer
...
@@ -459,7 +466,7 @@ func TestWatchControllers(t *testing.T) {
...
@@ -459,7 +466,7 @@ func TestWatchControllers(t *testing.T) {
informers
:=
informers
.
NewSharedInformerFactory
(
c
,
controller
.
NoResyncPeriodFunc
())
informers
:=
informers
.
NewSharedInformerFactory
(
c
,
controller
.
NoResyncPeriodFunc
())
podInformer
:=
informers
.
Core
()
.
V1
()
.
Pods
()
podInformer
:=
informers
.
Core
()
.
V1
()
.
Pods
()
rcInformer
:=
informers
.
Core
()
.
V1
()
.
ReplicationControllers
()
rcInformer
:=
informers
.
Core
()
.
V1
()
.
ReplicationControllers
()
manager
:=
NewReplicationManager
(
podInformer
,
rcInformer
,
c
,
BurstReplicas
,
0
,
false
)
manager
:=
NewReplicationManager
(
podInformer
,
rcInformer
,
c
,
BurstReplicas
,
0
)
informers
.
Start
(
stopCh
)
informers
.
Start
(
stopCh
)
var
testControllerSpec
v1
.
ReplicationController
var
testControllerSpec
v1
.
ReplicationController
...
@@ -1114,12 +1121,11 @@ func BenchmarkGetPodControllerSingleNS(b *testing.B) {
...
@@ -1114,12 +1121,11 @@ func BenchmarkGetPodControllerSingleNS(b *testing.B) {
}
}
}
}
// setupManagerWithGCEnabled creates a RC manager with a fakePodControl
and with garbageCollectorEnabled set to true
// setupManagerWithGCEnabled creates a RC manager with a fakePodControl
func
setupManagerWithGCEnabled
(
objs
...
runtime
.
Object
)
(
manager
*
ReplicationManager
,
fakePodControl
*
controller
.
FakePodControl
,
podInformer
coreinformers
.
PodInformer
,
rcInformer
coreinformers
.
ReplicationControllerInformer
)
{
func
setupManagerWithGCEnabled
(
objs
...
runtime
.
Object
)
(
manager
*
ReplicationManager
,
fakePodControl
*
controller
.
FakePodControl
,
podInformer
coreinformers
.
PodInformer
,
rcInformer
coreinformers
.
ReplicationControllerInformer
)
{
c
:=
fakeclientset
.
NewSimpleClientset
(
objs
...
)
c
:=
fakeclientset
.
NewSimpleClientset
(
objs
...
)
fakePodControl
=
&
controller
.
FakePodControl
{}
fakePodControl
=
&
controller
.
FakePodControl
{}
manager
,
podInformer
,
rcInformer
=
NewReplicationManagerFromClient
(
c
,
BurstReplicas
,
0
)
manager
,
podInformer
,
rcInformer
=
NewReplicationManagerFromClient
(
c
,
BurstReplicas
,
0
)
manager
.
garbageCollectorEnabled
=
true
manager
.
podControl
=
fakePodControl
manager
.
podControl
=
fakePodControl
return
manager
,
fakePodControl
,
podInformer
,
rcInformer
return
manager
,
fakePodControl
,
podInformer
,
rcInformer
}
}
...
@@ -1131,7 +1137,7 @@ func TestDoNotPatchPodWithOtherControlRef(t *testing.T) {
...
@@ -1131,7 +1137,7 @@ func TestDoNotPatchPodWithOtherControlRef(t *testing.T) {
var
trueVar
=
true
var
trueVar
=
true
otherControllerReference
:=
metav1
.
OwnerReference
{
UID
:
uuid
.
NewUUID
(),
APIVersion
:
"v1"
,
Kind
:
"ReplicationController"
,
Name
:
"AnotherRC"
,
Controller
:
&
trueVar
}
otherControllerReference
:=
metav1
.
OwnerReference
{
UID
:
uuid
.
NewUUID
(),
APIVersion
:
"v1"
,
Kind
:
"ReplicationController"
,
Name
:
"AnotherRC"
,
Controller
:
&
trueVar
}
// add to podLister a matching Pod controlled by another controller. Expect no patch.
// add to podLister a matching Pod controlled by another controller. Expect no patch.
pod
:=
newPod
(
"pod"
,
rc
,
v1
.
PodRunning
,
nil
)
pod
:=
newPod
(
"pod"
,
rc
,
v1
.
PodRunning
,
nil
,
false
)
pod
.
OwnerReferences
=
[]
metav1
.
OwnerReference
{
otherControllerReference
}
pod
.
OwnerReferences
=
[]
metav1
.
OwnerReference
{
otherControllerReference
}
podInformer
.
Informer
()
.
GetIndexer
()
.
Add
(
pod
)
podInformer
.
Informer
()
.
GetIndexer
()
.
Add
(
pod
)
err
:=
manager
.
syncReplicationController
(
getKey
(
rc
,
t
))
err
:=
manager
.
syncReplicationController
(
getKey
(
rc
,
t
))
...
@@ -1150,7 +1156,7 @@ func TestPatchPodWithOtherOwnerRef(t *testing.T) {
...
@@ -1150,7 +1156,7 @@ func TestPatchPodWithOtherOwnerRef(t *testing.T) {
// ref, but has an owner ref pointing to other object. Expect a patch to
// ref, but has an owner ref pointing to other object. Expect a patch to
// take control of it.
// take control of it.
unrelatedOwnerReference
:=
metav1
.
OwnerReference
{
UID
:
uuid
.
NewUUID
(),
APIVersion
:
"batch/v1"
,
Kind
:
"Job"
,
Name
:
"Job"
}
unrelatedOwnerReference
:=
metav1
.
OwnerReference
{
UID
:
uuid
.
NewUUID
(),
APIVersion
:
"batch/v1"
,
Kind
:
"Job"
,
Name
:
"Job"
}
pod
:=
newPod
(
"pod"
,
rc
,
v1
.
PodRunning
,
nil
)
pod
:=
newPod
(
"pod"
,
rc
,
v1
.
PodRunning
,
nil
,
false
)
pod
.
OwnerReferences
=
[]
metav1
.
OwnerReference
{
unrelatedOwnerReference
}
pod
.
OwnerReferences
=
[]
metav1
.
OwnerReference
{
unrelatedOwnerReference
}
podInformer
.
Informer
()
.
GetIndexer
()
.
Add
(
pod
)
podInformer
.
Informer
()
.
GetIndexer
()
.
Add
(
pod
)
...
@@ -1169,7 +1175,7 @@ func TestPatchPodWithCorrectOwnerRef(t *testing.T) {
...
@@ -1169,7 +1175,7 @@ func TestPatchPodWithCorrectOwnerRef(t *testing.T) {
// add to podLister a matching pod that has an ownerRef pointing to the rc,
// add to podLister a matching pod that has an ownerRef pointing to the rc,
// but ownerRef.Controller is false. Expect a patch to take control it.
// but ownerRef.Controller is false. Expect a patch to take control it.
rcOwnerReference
:=
metav1
.
OwnerReference
{
UID
:
rc
.
UID
,
APIVersion
:
"v1"
,
Kind
:
"ReplicationController"
,
Name
:
rc
.
Name
}
rcOwnerReference
:=
metav1
.
OwnerReference
{
UID
:
rc
.
UID
,
APIVersion
:
"v1"
,
Kind
:
"ReplicationController"
,
Name
:
rc
.
Name
}
pod
:=
newPod
(
"pod"
,
rc
,
v1
.
PodRunning
,
nil
)
pod
:=
newPod
(
"pod"
,
rc
,
v1
.
PodRunning
,
nil
,
false
)
pod
.
OwnerReferences
=
[]
metav1
.
OwnerReference
{
rcOwnerReference
}
pod
.
OwnerReferences
=
[]
metav1
.
OwnerReference
{
rcOwnerReference
}
podInformer
.
Informer
()
.
GetIndexer
()
.
Add
(
pod
)
podInformer
.
Informer
()
.
GetIndexer
()
.
Add
(
pod
)
...
@@ -1187,8 +1193,8 @@ func TestPatchPodFails(t *testing.T) {
...
@@ -1187,8 +1193,8 @@ func TestPatchPodFails(t *testing.T) {
rcInformer
.
Informer
()
.
GetIndexer
()
.
Add
(
rc
)
rcInformer
.
Informer
()
.
GetIndexer
()
.
Add
(
rc
)
// add to podLister two matching pods. Expect two patches to take control
// add to podLister two matching pods. Expect two patches to take control
// them.
// them.
podInformer
.
Informer
()
.
GetIndexer
()
.
Add
(
newPod
(
"pod1"
,
rc
,
v1
.
PodRunning
,
nil
))
podInformer
.
Informer
()
.
GetIndexer
()
.
Add
(
newPod
(
"pod1"
,
rc
,
v1
.
PodRunning
,
nil
,
false
))
podInformer
.
Informer
()
.
GetIndexer
()
.
Add
(
newPod
(
"pod2"
,
rc
,
v1
.
PodRunning
,
nil
))
podInformer
.
Informer
()
.
GetIndexer
()
.
Add
(
newPod
(
"pod2"
,
rc
,
v1
.
PodRunning
,
nil
,
false
))
// let both patches fail. The rc manager will assume it fails to take
// let both patches fail. The rc manager will assume it fails to take
// control of the pods and requeue to try again.
// control of the pods and requeue to try again.
fakePodControl
.
Err
=
fmt
.
Errorf
(
"Fake Error"
)
fakePodControl
.
Err
=
fmt
.
Errorf
(
"Fake Error"
)
...
@@ -1212,9 +1218,9 @@ func TestPatchExtraPodsThenDelete(t *testing.T) {
...
@@ -1212,9 +1218,9 @@ func TestPatchExtraPodsThenDelete(t *testing.T) {
rcInformer
.
Informer
()
.
GetIndexer
()
.
Add
(
rc
)
rcInformer
.
Informer
()
.
GetIndexer
()
.
Add
(
rc
)
// add to podLister three matching pods. Expect three patches to take control
// add to podLister three matching pods. Expect three patches to take control
// them, and later delete one of them.
// them, and later delete one of them.
podInformer
.
Informer
()
.
GetIndexer
()
.
Add
(
newPod
(
"pod1"
,
rc
,
v1
.
PodRunning
,
nil
))
podInformer
.
Informer
()
.
GetIndexer
()
.
Add
(
newPod
(
"pod1"
,
rc
,
v1
.
PodRunning
,
nil
,
false
))
podInformer
.
Informer
()
.
GetIndexer
()
.
Add
(
newPod
(
"pod2"
,
rc
,
v1
.
PodRunning
,
nil
))
podInformer
.
Informer
()
.
GetIndexer
()
.
Add
(
newPod
(
"pod2"
,
rc
,
v1
.
PodRunning
,
nil
,
false
))
podInformer
.
Informer
()
.
GetIndexer
()
.
Add
(
newPod
(
"pod3"
,
rc
,
v1
.
PodRunning
,
nil
))
podInformer
.
Informer
()
.
GetIndexer
()
.
Add
(
newPod
(
"pod3"
,
rc
,
v1
.
PodRunning
,
nil
,
false
))
err
:=
manager
.
syncReplicationController
(
getKey
(
rc
,
t
))
err
:=
manager
.
syncReplicationController
(
getKey
(
rc
,
t
))
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
...
@@ -1228,7 +1234,7 @@ func TestUpdateLabelsRemoveControllerRef(t *testing.T) {
...
@@ -1228,7 +1234,7 @@ func TestUpdateLabelsRemoveControllerRef(t *testing.T) {
rc
:=
newReplicationController
(
2
)
rc
:=
newReplicationController
(
2
)
rcInformer
.
Informer
()
.
GetIndexer
()
.
Add
(
rc
)
rcInformer
.
Informer
()
.
GetIndexer
()
.
Add
(
rc
)
// put one pod in the podLister
// put one pod in the podLister
pod
:=
newPod
(
"pod"
,
rc
,
v1
.
PodRunning
,
nil
)
pod
:=
newPod
(
"pod"
,
rc
,
v1
.
PodRunning
,
nil
,
false
)
pod
.
ResourceVersion
=
"1"
pod
.
ResourceVersion
=
"1"
var
trueVar
=
true
var
trueVar
=
true
rcOwnerReference
:=
metav1
.
OwnerReference
{
UID
:
rc
.
UID
,
APIVersion
:
"v1"
,
Kind
:
"ReplicationController"
,
Name
:
rc
.
Name
,
Controller
:
&
trueVar
}
rcOwnerReference
:=
metav1
.
OwnerReference
{
UID
:
rc
.
UID
,
APIVersion
:
"v1"
,
Kind
:
"ReplicationController"
,
Name
:
rc
.
Name
,
Controller
:
&
trueVar
}
...
@@ -1300,7 +1306,7 @@ func TestDoNotAdoptOrCreateIfBeingDeleted(t *testing.T) {
...
@@ -1300,7 +1306,7 @@ func TestDoNotAdoptOrCreateIfBeingDeleted(t *testing.T) {
now
:=
metav1
.
Now
()
now
:=
metav1
.
Now
()
rc
.
DeletionTimestamp
=
&
now
rc
.
DeletionTimestamp
=
&
now
rcInformer
.
Informer
()
.
GetIndexer
()
.
Add
(
rc
)
rcInformer
.
Informer
()
.
GetIndexer
()
.
Add
(
rc
)
pod1
:=
newPod
(
"pod1"
,
rc
,
v1
.
PodRunning
,
nil
)
pod1
:=
newPod
(
"pod1"
,
rc
,
v1
.
PodRunning
,
nil
,
false
)
podInformer
.
Informer
()
.
GetIndexer
()
.
Add
(
pod1
)
podInformer
.
Informer
()
.
GetIndexer
()
.
Add
(
pod1
)
// no patch, no create
// no patch, no create
...
@@ -1371,12 +1377,12 @@ func TestAvailableReplicas(t *testing.T) {
...
@@ -1371,12 +1377,12 @@ func TestAvailableReplicas(t *testing.T) {
// First pod becomes ready 20s ago
// First pod becomes ready 20s ago
moment
:=
metav1
.
Time
{
Time
:
time
.
Now
()
.
Add
(
-
2e10
)}
moment
:=
metav1
.
Time
{
Time
:
time
.
Now
()
.
Add
(
-
2e10
)}
pod
:=
newPod
(
"pod"
,
rc
,
v1
.
PodRunning
,
&
moment
)
pod
:=
newPod
(
"pod"
,
rc
,
v1
.
PodRunning
,
&
moment
,
true
)
podInformer
.
Informer
()
.
GetIndexer
()
.
Add
(
pod
)
podInformer
.
Informer
()
.
GetIndexer
()
.
Add
(
pod
)
// Second pod becomes ready now
// Second pod becomes ready now
otherMoment
:=
metav1
.
Now
()
otherMoment
:=
metav1
.
Now
()
otherPod
:=
newPod
(
"otherPod"
,
rc
,
v1
.
PodRunning
,
&
otherMoment
)
otherPod
:=
newPod
(
"otherPod"
,
rc
,
v1
.
PodRunning
,
&
otherMoment
,
true
)
podInformer
.
Informer
()
.
GetIndexer
()
.
Add
(
otherPod
)
podInformer
.
Informer
()
.
GetIndexer
()
.
Add
(
otherPod
)
// This response body is just so we don't err out decoding the http response
// This response body is just so we don't err out decoding the http response
...
...
test/integration/framework/master_utils.go
View file @
6b35ff72
...
@@ -124,7 +124,7 @@ func NewMasterComponents(c *Config) *MasterComponents {
...
@@ -124,7 +124,7 @@ func NewMasterComponents(c *Config) *MasterComponents {
clientset
:=
clientset
.
NewForConfigOrDie
(
&
restclient
.
Config
{
Host
:
s
.
URL
,
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
&
api
.
Registry
.
GroupOrDie
(
v1
.
GroupName
)
.
GroupVersion
},
QPS
:
c
.
QPS
,
Burst
:
c
.
Burst
})
clientset
:=
clientset
.
NewForConfigOrDie
(
&
restclient
.
Config
{
Host
:
s
.
URL
,
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
&
api
.
Registry
.
GroupOrDie
(
v1
.
GroupName
)
.
GroupVersion
},
QPS
:
c
.
QPS
,
Burst
:
c
.
Burst
})
rcStopCh
:=
make
(
chan
struct
{})
rcStopCh
:=
make
(
chan
struct
{})
informerFactory
:=
informers
.
NewSharedInformerFactory
(
clientset
,
controller
.
NoResyncPeriodFunc
())
informerFactory
:=
informers
.
NewSharedInformerFactory
(
clientset
,
controller
.
NoResyncPeriodFunc
())
controllerManager
:=
replicationcontroller
.
NewReplicationManager
(
informerFactory
.
Core
()
.
V1
()
.
Pods
(),
informerFactory
.
Core
()
.
V1
()
.
ReplicationControllers
(),
clientset
,
c
.
Burst
,
4096
,
false
)
controllerManager
:=
replicationcontroller
.
NewReplicationManager
(
informerFactory
.
Core
()
.
V1
()
.
Pods
(),
informerFactory
.
Core
()
.
V1
()
.
ReplicationControllers
(),
clientset
,
c
.
Burst
,
4096
)
// TODO: Support events once we can cleanly shutdown an event recorder.
// TODO: Support events once we can cleanly shutdown an event recorder.
controllerManager
.
SetEventRecorder
(
&
record
.
FakeRecorder
{})
controllerManager
.
SetEventRecorder
(
&
record
.
FakeRecorder
{})
...
...
test/integration/quota/quota_test.go
View file @
6b35ff72
...
@@ -97,7 +97,6 @@ func TestQuota(t *testing.T) {
...
@@ -97,7 +97,6 @@ func TestQuota(t *testing.T) {
clientset
,
clientset
,
replicationcontroller
.
BurstReplicas
,
replicationcontroller
.
BurstReplicas
,
4096
,
4096
,
false
,
)
)
rm
.
SetEventRecorder
(
&
record
.
FakeRecorder
{})
rm
.
SetEventRecorder
(
&
record
.
FakeRecorder
{})
go
rm
.
Run
(
3
,
controllerCh
)
go
rm
.
Run
(
3
,
controllerCh
)
...
@@ -282,7 +281,6 @@ func TestQuotaLimitedResourceDenial(t *testing.T) {
...
@@ -282,7 +281,6 @@ func TestQuotaLimitedResourceDenial(t *testing.T) {
clientset
,
clientset
,
replicationcontroller
.
BurstReplicas
,
replicationcontroller
.
BurstReplicas
,
4096
,
4096
,
false
,
)
)
rm
.
SetEventRecorder
(
&
record
.
FakeRecorder
{})
rm
.
SetEventRecorder
(
&
record
.
FakeRecorder
{})
go
rm
.
Run
(
3
,
controllerCh
)
go
rm
.
Run
(
3
,
controllerCh
)
...
...
test/integration/replicaset/replicaset_test.go
View file @
6b35ff72
...
@@ -126,7 +126,7 @@ func verifyRemainingObjects(t *testing.T, clientSet clientset.Interface, namespa
...
@@ -126,7 +126,7 @@ func verifyRemainingObjects(t *testing.T, clientSet clientset.Interface, namespa
return
ret
,
nil
return
ret
,
nil
}
}
func
rmSetup
(
t
*
testing
.
T
,
enableGarbageCollector
bool
)
(
*
httptest
.
Server
,
*
replicaset
.
ReplicaSetController
,
informers
.
SharedInformerFactory
,
clientset
.
Interface
)
{
func
rmSetup
(
t
*
testing
.
T
)
(
*
httptest
.
Server
,
*
replicaset
.
ReplicaSetController
,
informers
.
SharedInformerFactory
,
clientset
.
Interface
)
{
masterConfig
:=
framework
.
NewIntegrationTestMasterConfig
()
masterConfig
:=
framework
.
NewIntegrationTestMasterConfig
()
_
,
s
:=
framework
.
RunAMaster
(
masterConfig
)
_
,
s
:=
framework
.
RunAMaster
(
masterConfig
)
...
@@ -144,7 +144,6 @@ func rmSetup(t *testing.T, enableGarbageCollector bool) (*httptest.Server, *repl
...
@@ -144,7 +144,6 @@ func rmSetup(t *testing.T, enableGarbageCollector bool) (*httptest.Server, *repl
clientset
.
NewForConfigOrDie
(
restclient
.
AddUserAgent
(
&
config
,
"replicaset-controller"
)),
clientset
.
NewForConfigOrDie
(
restclient
.
AddUserAgent
(
&
config
,
"replicaset-controller"
)),
replicaset
.
BurstReplicas
,
replicaset
.
BurstReplicas
,
4096
,
4096
,
enableGarbageCollector
,
)
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -220,7 +219,7 @@ func TestAdoption(t *testing.T) {
...
@@ -220,7 +219,7 @@ func TestAdoption(t *testing.T) {
},
},
}
}
for
i
,
tc
:=
range
testCases
{
for
i
,
tc
:=
range
testCases
{
s
,
rm
,
informers
,
clientSet
:=
rmSetup
(
t
,
true
)
s
,
rm
,
informers
,
clientSet
:=
rmSetup
(
t
)
podInformer
:=
informers
.
Core
()
.
V1
()
.
Pods
()
.
Informer
()
podInformer
:=
informers
.
Core
()
.
V1
()
.
Pods
()
.
Informer
()
ns
:=
framework
.
CreateTestingNamespace
(
fmt
.
Sprintf
(
"rs-adoption-%d"
,
i
),
s
,
t
)
ns
:=
framework
.
CreateTestingNamespace
(
fmt
.
Sprintf
(
"rs-adoption-%d"
,
i
),
s
,
t
)
defer
framework
.
DeleteTestingNamespace
(
ns
,
s
,
t
)
defer
framework
.
DeleteTestingNamespace
(
ns
,
s
,
t
)
...
@@ -298,7 +297,7 @@ func TestUpdateSelectorToAdopt(t *testing.T) {
...
@@ -298,7 +297,7 @@ func TestUpdateSelectorToAdopt(t *testing.T) {
// We have pod1, pod2 and rs. rs.spec.replicas=1. At first rs.Selector
// We have pod1, pod2 and rs. rs.spec.replicas=1. At first rs.Selector
// matches pod1 only; change the selector to match pod2 as well. Verify
// matches pod1 only; change the selector to match pod2 as well. Verify
// there is only one pod left.
// there is only one pod left.
s
,
rm
,
informers
,
clientSet
:=
rmSetup
(
t
,
true
)
s
,
rm
,
informers
,
clientSet
:=
rmSetup
(
t
)
ns
:=
framework
.
CreateTestingNamespace
(
"rs-update-selector-to-adopt"
,
s
,
t
)
ns
:=
framework
.
CreateTestingNamespace
(
"rs-update-selector-to-adopt"
,
s
,
t
)
defer
framework
.
DeleteTestingNamespace
(
ns
,
s
,
t
)
defer
framework
.
DeleteTestingNamespace
(
ns
,
s
,
t
)
rs
:=
newRS
(
"rs"
,
ns
.
Name
,
1
)
rs
:=
newRS
(
"rs"
,
ns
.
Name
,
1
)
...
@@ -338,7 +337,7 @@ func TestUpdateSelectorToRemoveControllerRef(t *testing.T) {
...
@@ -338,7 +337,7 @@ func TestUpdateSelectorToRemoveControllerRef(t *testing.T) {
// matches pod1 and pod2; change the selector to match only pod1. Verify
// matches pod1 and pod2; change the selector to match only pod1. Verify
// that rs creates one more pod, so there are 3 pods. Also verify that
// that rs creates one more pod, so there are 3 pods. Also verify that
// pod2's controllerRef is cleared.
// pod2's controllerRef is cleared.
s
,
rm
,
informers
,
clientSet
:=
rmSetup
(
t
,
true
)
s
,
rm
,
informers
,
clientSet
:=
rmSetup
(
t
)
podInformer
:=
informers
.
Core
()
.
V1
()
.
Pods
()
.
Informer
()
podInformer
:=
informers
.
Core
()
.
V1
()
.
Pods
()
.
Informer
()
ns
:=
framework
.
CreateTestingNamespace
(
"rs-update-selector-to-remove-controllerref"
,
s
,
t
)
ns
:=
framework
.
CreateTestingNamespace
(
"rs-update-selector-to-remove-controllerref"
,
s
,
t
)
defer
framework
.
DeleteTestingNamespace
(
ns
,
s
,
t
)
defer
framework
.
DeleteTestingNamespace
(
ns
,
s
,
t
)
...
@@ -385,7 +384,7 @@ func TestUpdateLabelToRemoveControllerRef(t *testing.T) {
...
@@ -385,7 +384,7 @@ func TestUpdateLabelToRemoveControllerRef(t *testing.T) {
// matches pod1 and pod2; change pod2's labels to non-matching. Verify
// matches pod1 and pod2; change pod2's labels to non-matching. Verify
// that rs creates one more pod, so there are 3 pods. Also verify that
// that rs creates one more pod, so there are 3 pods. Also verify that
// pod2's controllerRef is cleared.
// pod2's controllerRef is cleared.
s
,
rm
,
informers
,
clientSet
:=
rmSetup
(
t
,
true
)
s
,
rm
,
informers
,
clientSet
:=
rmSetup
(
t
)
ns
:=
framework
.
CreateTestingNamespace
(
"rs-update-label-to-remove-controllerref"
,
s
,
t
)
ns
:=
framework
.
CreateTestingNamespace
(
"rs-update-label-to-remove-controllerref"
,
s
,
t
)
defer
framework
.
DeleteTestingNamespace
(
ns
,
s
,
t
)
defer
framework
.
DeleteTestingNamespace
(
ns
,
s
,
t
)
rs
:=
newRS
(
"rs"
,
ns
.
Name
,
2
)
rs
:=
newRS
(
"rs"
,
ns
.
Name
,
2
)
...
@@ -427,7 +426,7 @@ func TestUpdateLabelToBeAdopted(t *testing.T) {
...
@@ -427,7 +426,7 @@ func TestUpdateLabelToBeAdopted(t *testing.T) {
// matches pod1 only; change pod2's labels to be matching. Verify the RS
// matches pod1 only; change pod2's labels to be matching. Verify the RS
// controller adopts pod2 and delete one of them, so there is only 1 pod
// controller adopts pod2 and delete one of them, so there is only 1 pod
// left.
// left.
s
,
rm
,
informers
,
clientSet
:=
rmSetup
(
t
,
true
)
s
,
rm
,
informers
,
clientSet
:=
rmSetup
(
t
)
ns
:=
framework
.
CreateTestingNamespace
(
"rs-update-label-to-be-adopted"
,
s
,
t
)
ns
:=
framework
.
CreateTestingNamespace
(
"rs-update-label-to-be-adopted"
,
s
,
t
)
defer
framework
.
DeleteTestingNamespace
(
ns
,
s
,
t
)
defer
framework
.
DeleteTestingNamespace
(
ns
,
s
,
t
)
rs
:=
newRS
(
"rs"
,
ns
.
Name
,
1
)
rs
:=
newRS
(
"rs"
,
ns
.
Name
,
1
)
...
...
test/integration/replicationcontroller/replicationcontroller_test.go
View file @
6b35ff72
...
@@ -123,7 +123,7 @@ func verifyRemainingObjects(t *testing.T, clientSet clientset.Interface, namespa
...
@@ -123,7 +123,7 @@ func verifyRemainingObjects(t *testing.T, clientSet clientset.Interface, namespa
return
ret
,
nil
return
ret
,
nil
}
}
func
rmSetup
(
t
*
testing
.
T
,
stopCh
chan
struct
{}
,
enableGarbageCollector
bool
)
(
*
httptest
.
Server
,
*
replication
.
ReplicationManager
,
informers
.
SharedInformerFactory
,
clientset
.
Interface
)
{
func
rmSetup
(
t
*
testing
.
T
,
stopCh
chan
struct
{})
(
*
httptest
.
Server
,
*
replication
.
ReplicationManager
,
informers
.
SharedInformerFactory
,
clientset
.
Interface
)
{
masterConfig
:=
framework
.
NewIntegrationTestMasterConfig
()
masterConfig
:=
framework
.
NewIntegrationTestMasterConfig
()
_
,
s
:=
framework
.
RunAMaster
(
masterConfig
)
_
,
s
:=
framework
.
RunAMaster
(
masterConfig
)
...
@@ -135,7 +135,7 @@ func rmSetup(t *testing.T, stopCh chan struct{}, enableGarbageCollector bool) (*
...
@@ -135,7 +135,7 @@ func rmSetup(t *testing.T, stopCh chan struct{}, enableGarbageCollector bool) (*
resyncPeriod
:=
12
*
time
.
Hour
resyncPeriod
:=
12
*
time
.
Hour
informers
:=
informers
.
NewSharedInformerFactory
(
clientSet
,
resyncPeriod
)
informers
:=
informers
.
NewSharedInformerFactory
(
clientSet
,
resyncPeriod
)
rm
:=
replication
.
NewReplicationManager
(
informers
.
Core
()
.
V1
()
.
Pods
(),
informers
.
Core
()
.
V1
()
.
ReplicationControllers
(),
clientSet
,
replication
.
BurstReplicas
,
4096
,
enableGarbageCollector
)
rm
:=
replication
.
NewReplicationManager
(
informers
.
Core
()
.
V1
()
.
Pods
(),
informers
.
Core
()
.
V1
()
.
ReplicationControllers
(),
clientSet
,
replication
.
BurstReplicas
,
4096
)
informers
.
Start
(
stopCh
)
informers
.
Start
(
stopCh
)
return
s
,
rm
,
informers
,
clientSet
return
s
,
rm
,
informers
,
clientSet
...
@@ -209,7 +209,7 @@ func TestAdoption(t *testing.T) {
...
@@ -209,7 +209,7 @@ func TestAdoption(t *testing.T) {
}
}
for
i
,
tc
:=
range
testCases
{
for
i
,
tc
:=
range
testCases
{
stopCh
:=
make
(
chan
struct
{})
stopCh
:=
make
(
chan
struct
{})
s
,
rm
,
informers
,
clientSet
:=
rmSetup
(
t
,
stopCh
,
true
)
s
,
rm
,
informers
,
clientSet
:=
rmSetup
(
t
,
stopCh
)
ns
:=
framework
.
CreateTestingNamespace
(
fmt
.
Sprintf
(
"adoption-%d"
,
i
),
s
,
t
)
ns
:=
framework
.
CreateTestingNamespace
(
fmt
.
Sprintf
(
"adoption-%d"
,
i
),
s
,
t
)
defer
framework
.
DeleteTestingNamespace
(
ns
,
s
,
t
)
defer
framework
.
DeleteTestingNamespace
(
ns
,
s
,
t
)
...
@@ -286,7 +286,7 @@ func TestUpdateSelectorToAdopt(t *testing.T) {
...
@@ -286,7 +286,7 @@ func TestUpdateSelectorToAdopt(t *testing.T) {
// matches pod1 only; change the selector to match pod2 as well. Verify
// matches pod1 only; change the selector to match pod2 as well. Verify
// there is only one pod left.
// there is only one pod left.
stopCh
:=
make
(
chan
struct
{})
stopCh
:=
make
(
chan
struct
{})
s
,
rm
,
_
,
clientSet
:=
rmSetup
(
t
,
stopCh
,
true
)
s
,
rm
,
_
,
clientSet
:=
rmSetup
(
t
,
stopCh
)
ns
:=
framework
.
CreateTestingNamespace
(
"update-selector-to-adopt"
,
s
,
t
)
ns
:=
framework
.
CreateTestingNamespace
(
"update-selector-to-adopt"
,
s
,
t
)
defer
framework
.
DeleteTestingNamespace
(
ns
,
s
,
t
)
defer
framework
.
DeleteTestingNamespace
(
ns
,
s
,
t
)
rc
:=
newRC
(
"rc"
,
ns
.
Name
,
1
)
rc
:=
newRC
(
"rc"
,
ns
.
Name
,
1
)
...
@@ -325,7 +325,7 @@ func TestUpdateSelectorToRemoveControllerRef(t *testing.T) {
...
@@ -325,7 +325,7 @@ func TestUpdateSelectorToRemoveControllerRef(t *testing.T) {
// that rc creates one more pod, so there are 3 pods. Also verify that
// that rc creates one more pod, so there are 3 pods. Also verify that
// pod2's controllerRef is cleared.
// pod2's controllerRef is cleared.
stopCh
:=
make
(
chan
struct
{})
stopCh
:=
make
(
chan
struct
{})
s
,
rm
,
informers
,
clientSet
:=
rmSetup
(
t
,
stopCh
,
true
)
s
,
rm
,
informers
,
clientSet
:=
rmSetup
(
t
,
stopCh
)
ns
:=
framework
.
CreateTestingNamespace
(
"update-selector-to-remove-controllerref"
,
s
,
t
)
ns
:=
framework
.
CreateTestingNamespace
(
"update-selector-to-remove-controllerref"
,
s
,
t
)
defer
framework
.
DeleteTestingNamespace
(
ns
,
s
,
t
)
defer
framework
.
DeleteTestingNamespace
(
ns
,
s
,
t
)
rc
:=
newRC
(
"rc"
,
ns
.
Name
,
2
)
rc
:=
newRC
(
"rc"
,
ns
.
Name
,
2
)
...
@@ -370,7 +370,7 @@ func TestUpdateLabelToRemoveControllerRef(t *testing.T) {
...
@@ -370,7 +370,7 @@ func TestUpdateLabelToRemoveControllerRef(t *testing.T) {
// that rc creates one more pod, so there are 3 pods. Also verify that
// that rc creates one more pod, so there are 3 pods. Also verify that
// pod2's controllerRef is cleared.
// pod2's controllerRef is cleared.
stopCh
:=
make
(
chan
struct
{})
stopCh
:=
make
(
chan
struct
{})
s
,
rm
,
_
,
clientSet
:=
rmSetup
(
t
,
stopCh
,
true
)
s
,
rm
,
_
,
clientSet
:=
rmSetup
(
t
,
stopCh
)
ns
:=
framework
.
CreateTestingNamespace
(
"update-label-to-remove-controllerref"
,
s
,
t
)
ns
:=
framework
.
CreateTestingNamespace
(
"update-label-to-remove-controllerref"
,
s
,
t
)
defer
framework
.
DeleteTestingNamespace
(
ns
,
s
,
t
)
defer
framework
.
DeleteTestingNamespace
(
ns
,
s
,
t
)
rc
:=
newRC
(
"rc"
,
ns
.
Name
,
2
)
rc
:=
newRC
(
"rc"
,
ns
.
Name
,
2
)
...
@@ -411,7 +411,7 @@ func TestUpdateLabelToBeAdopted(t *testing.T) {
...
@@ -411,7 +411,7 @@ func TestUpdateLabelToBeAdopted(t *testing.T) {
// controller adopts pod2 and delete one of them, so there is only 1 pod
// controller adopts pod2 and delete one of them, so there is only 1 pod
// left.
// left.
stopCh
:=
make
(
chan
struct
{})
stopCh
:=
make
(
chan
struct
{})
s
,
rm
,
_
,
clientSet
:=
rmSetup
(
t
,
stopCh
,
true
)
s
,
rm
,
_
,
clientSet
:=
rmSetup
(
t
,
stopCh
)
ns
:=
framework
.
CreateTestingNamespace
(
"update-label-to-be-adopted"
,
s
,
t
)
ns
:=
framework
.
CreateTestingNamespace
(
"update-label-to-be-adopted"
,
s
,
t
)
defer
framework
.
DeleteTestingNamespace
(
ns
,
s
,
t
)
defer
framework
.
DeleteTestingNamespace
(
ns
,
s
,
t
)
rc
:=
newRC
(
"rc"
,
ns
.
Name
,
1
)
rc
:=
newRC
(
"rc"
,
ns
.
Name
,
1
)
...
...
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