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
b471398f
Commit
b471398f
authored
Oct 07, 2016
by
deads2k
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
convert replica set controller to shared informer
parent
bcbdcd17
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
76 additions
and
99 deletions
+76
-99
controllermanager.go
cmd/kube-controller-manager/app/controllermanager.go
+1
-1
replica_set.go
pkg/controller/replicaset/replica_set.go
+32
-85
replica_set_test.go
pkg/controller/replicaset/replica_set_test.go
+0
-0
replica_set_utils.go
pkg/controller/replicaset/replica_set_utils.go
+11
-0
fake_handler.go
pkg/util/testing/fake_handler.go
+16
-0
replicaset_test.go
test/integration/replicaset/replicaset_test.go
+16
-13
No files found.
cmd/kube-controller-manager/app/controllermanager.go
View file @
b471398f
...
...
@@ -422,7 +422,7 @@ func StartControllers(s *options.CMServer, kubeconfig *restclient.Config, rootCl
if
containsResource
(
resources
,
"replicasets"
)
{
glog
.
Infof
(
"Starting ReplicaSet controller"
)
go
replicaset
.
NewReplicaSetController
(
sharedInformers
.
Pods
()
.
Informer
(),
client
(
"replicaset-controller"
),
ResyncPeriod
(
s
),
replicaset
.
BurstReplicas
,
int
(
s
.
LookupCacheSizeForRS
),
s
.
EnableGarbageCollector
)
.
go
replicaset
.
NewReplicaSetController
(
sharedInformers
.
ReplicaSets
(),
sharedInformers
.
Pods
(),
client
(
"replicaset-controller"
),
replicaset
.
BurstReplicas
,
int
(
s
.
LookupCacheSizeForRS
),
s
.
EnableGarbageCollector
)
.
Run
(
int
(
s
.
ConcurrentRSSyncs
),
wait
.
NeverStop
)
time
.
Sleep
(
wait
.
Jitter
(
s
.
ControllerStartInterval
.
Duration
,
ControllerStartJitter
))
}
...
...
pkg/controller/replicaset/replica_set.go
View file @
b471398f
This diff is collapsed.
Click to expand it.
pkg/controller/replicaset/replica_set_test.go
View file @
b471398f
This diff is collapsed.
Click to expand it.
pkg/controller/replicaset/replica_set_utils.go
View file @
b471398f
...
...
@@ -22,6 +22,8 @@ import (
"fmt"
"github.com/golang/glog"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/apis/extensions"
unversionedextensions
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/extensions/unversioned"
)
...
...
@@ -38,6 +40,15 @@ func updateReplicaCount(rsClient unversionedextensions.ReplicaSetInterface, rs e
rs
.
Generation
==
rs
.
Status
.
ObservedGeneration
{
return
nil
}
// deep copy to avoid mutation now.
// TODO this method need some work. Retry on conflict probably, though I suspect this is stomping status to something it probably shouldn't
copyObj
,
err
:=
api
.
Scheme
.
DeepCopy
(
rs
)
if
err
!=
nil
{
return
err
}
rs
=
copyObj
.
(
extensions
.
ReplicaSet
)
// Save the generation number we acted on, otherwise we might wrongfully indicate
// that we've seen a spec update when we retry.
// TODO: This can clobber an update if we allow multiple agents to write to the
...
...
pkg/util/testing/fake_handler.go
View file @
b471398f
...
...
@@ -52,11 +52,27 @@ type FakeHandler struct {
lock
sync
.
Mutex
requestCount
int
hasBeenChecked
bool
SkipRequestFn
func
(
verb
string
,
url
url
.
URL
)
bool
}
func
(
f
*
FakeHandler
)
SetResponseBody
(
responseBody
string
)
{
f
.
lock
.
Lock
()
defer
f
.
lock
.
Unlock
()
f
.
ResponseBody
=
responseBody
}
func
(
f
*
FakeHandler
)
ServeHTTP
(
response
http
.
ResponseWriter
,
request
*
http
.
Request
)
{
f
.
lock
.
Lock
()
defer
f
.
lock
.
Unlock
()
if
f
.
SkipRequestFn
!=
nil
&&
f
.
SkipRequestFn
(
request
.
Method
,
*
request
.
URL
)
{
response
.
Header
()
.
Set
(
"Content-Type"
,
"application/json"
)
response
.
WriteHeader
(
f
.
StatusCode
)
response
.
Write
([]
byte
(
f
.
ResponseBody
))
return
}
f
.
requestCount
++
if
f
.
hasBeenChecked
{
panic
(
"got request after having been validated"
)
...
...
test/integration/replicaset/replicaset_test.go
View file @
b471398f
...
...
@@ -127,7 +127,7 @@ func verifyRemainingObjects(t *testing.T, clientSet clientset.Interface, namespa
return
ret
,
nil
}
func
rmSetup
(
t
*
testing
.
T
,
enableGarbageCollector
bool
)
(
*
httptest
.
Server
,
*
replicaset
.
ReplicaSetController
,
cache
.
SharedIndexInformer
,
clientset
.
Interface
)
{
func
rmSetup
(
t
*
testing
.
T
,
enableGarbageCollector
bool
)
(
*
httptest
.
Server
,
*
replicaset
.
ReplicaSetController
,
cache
.
SharedIndexInformer
,
c
ache
.
SharedIndexInformer
,
c
lientset
.
Interface
)
{
masterConfig
:=
framework
.
NewIntegrationTestMasterConfig
()
_
,
s
:=
framework
.
RunAMaster
(
masterConfig
)
...
...
@@ -137,14 +137,12 @@ func rmSetup(t *testing.T, enableGarbageCollector bool) (*httptest.Server, *repl
t
.
Fatalf
(
"Error in create clientset: %v"
,
err
)
}
resyncPeriod
:=
12
*
time
.
Hour
resyncPeriodFunc
:=
func
()
time
.
Duration
{
return
resyncPeriod
}
podInformer
:=
informers
.
NewPodInformer
(
internalclientset
.
NewForConfigOrDie
(
restclient
.
AddUserAgent
(
&
config
,
"pod-informer"
)),
resyncPeriod
)
informers
:=
informers
.
NewSharedInformerFactory
(
internalclientset
.
NewForConfigOrDie
(
restclient
.
AddUserAgent
(
&
config
,
"rs-informers"
)),
resyncPeriod
)
rm
:=
replicaset
.
NewReplicaSetController
(
podInformer
,
informers
.
ReplicaSets
(),
informers
.
Pods
(),
internalclientset
.
NewForConfigOrDie
(
restclient
.
AddUserAgent
(
&
config
,
"replicaset-controller"
)),
resyncPeriodFunc
,
replicaset
.
BurstReplicas
,
4096
,
enableGarbageCollector
,
...
...
@@ -153,7 +151,7 @@ func rmSetup(t *testing.T, enableGarbageCollector bool) (*httptest.Server, *repl
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to create replicaset controller"
)
}
return
s
,
rm
,
podInformer
,
clientSet
return
s
,
rm
,
informers
.
ReplicaSets
()
.
Informer
(),
informers
.
Pods
()
.
Informer
()
,
clientSet
}
// wait for the podInformer to observe the pods. Call this function before
...
...
@@ -223,7 +221,7 @@ func TestAdoption(t *testing.T) {
},
}
for
i
,
tc
:=
range
testCases
{
s
,
rm
,
podInformer
,
clientSet
:=
rmSetup
(
t
,
true
)
s
,
rm
,
rsInformer
,
podInformer
,
clientSet
:=
rmSetup
(
t
,
true
)
ns
:=
framework
.
CreateTestingNamespace
(
fmt
.
Sprintf
(
"rs-adoption-%d"
,
i
),
s
,
t
)
defer
framework
.
DeleteTestingNamespace
(
ns
,
s
,
t
)
...
...
@@ -243,6 +241,7 @@ func TestAdoption(t *testing.T) {
}
stopCh
:=
make
(
chan
struct
{})
go
rsInformer
.
Run
(
stopCh
)
go
podInformer
.
Run
(
stopCh
)
waitToObservePods
(
t
,
podInformer
,
1
)
go
rm
.
Run
(
5
,
stopCh
)
...
...
@@ -300,7 +299,7 @@ func TestUpdateSelectorToAdopt(t *testing.T) {
// 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
// there is only one pod left.
s
,
rm
,
podInformer
,
clientSet
:=
rmSetup
(
t
,
true
)
s
,
rm
,
rsInformer
,
podInformer
,
clientSet
:=
rmSetup
(
t
,
true
)
ns
:=
framework
.
CreateTestingNamespace
(
"rs-update-selector-to-adopt"
,
s
,
t
)
defer
framework
.
DeleteTestingNamespace
(
ns
,
s
,
t
)
rs
:=
newRS
(
"rs"
,
ns
.
Name
,
1
)
...
...
@@ -314,6 +313,7 @@ func TestUpdateSelectorToAdopt(t *testing.T) {
createRSsPods
(
t
,
clientSet
,
[]
*
v1beta1
.
ReplicaSet
{
rs
},
[]
*
v1
.
Pod
{
pod1
,
pod2
},
ns
.
Name
)
stopCh
:=
make
(
chan
struct
{})
go
rsInformer
.
Run
(
stopCh
)
go
podInformer
.
Run
(
stopCh
)
go
rm
.
Run
(
5
,
stopCh
)
waitRSStable
(
t
,
clientSet
,
rs
,
ns
.
Name
)
...
...
@@ -340,7 +340,7 @@ func TestUpdateSelectorToRemoveControllerRef(t *testing.T) {
// 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
// pod2's controllerRef is cleared.
s
,
rm
,
podInformer
,
clientSet
:=
rmSetup
(
t
,
true
)
s
,
rm
,
rsInformer
,
podInformer
,
clientSet
:=
rmSetup
(
t
,
true
)
ns
:=
framework
.
CreateTestingNamespace
(
"rs-update-selector-to-remove-controllerref"
,
s
,
t
)
defer
framework
.
DeleteTestingNamespace
(
ns
,
s
,
t
)
rs
:=
newRS
(
"rs"
,
ns
.
Name
,
2
)
...
...
@@ -351,6 +351,7 @@ func TestUpdateSelectorToRemoveControllerRef(t *testing.T) {
createRSsPods
(
t
,
clientSet
,
[]
*
v1beta1
.
ReplicaSet
{
rs
},
[]
*
v1
.
Pod
{
pod1
,
pod2
},
ns
.
Name
)
stopCh
:=
make
(
chan
struct
{})
go
rsInformer
.
Run
(
stopCh
)
go
podInformer
.
Run
(
stopCh
)
waitToObservePods
(
t
,
podInformer
,
2
)
go
rm
.
Run
(
5
,
stopCh
)
...
...
@@ -386,7 +387,7 @@ func TestUpdateLabelToRemoveControllerRef(t *testing.T) {
// 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
// pod2's controllerRef is cleared.
s
,
rm
,
podInformer
,
clientSet
:=
rmSetup
(
t
,
true
)
s
,
rm
,
rsInformer
,
podInformer
,
clientSet
:=
rmSetup
(
t
,
true
)
ns
:=
framework
.
CreateTestingNamespace
(
"rs-update-label-to-remove-controllerref"
,
s
,
t
)
defer
framework
.
DeleteTestingNamespace
(
ns
,
s
,
t
)
rs
:=
newRS
(
"rs"
,
ns
.
Name
,
2
)
...
...
@@ -395,6 +396,7 @@ func TestUpdateLabelToRemoveControllerRef(t *testing.T) {
createRSsPods
(
t
,
clientSet
,
[]
*
v1beta1
.
ReplicaSet
{
rs
},
[]
*
v1
.
Pod
{
pod1
,
pod2
},
ns
.
Name
)
stopCh
:=
make
(
chan
struct
{})
go
rsInformer
.
Run
(
stopCh
)
go
podInformer
.
Run
(
stopCh
)
go
rm
.
Run
(
5
,
stopCh
)
waitRSStable
(
t
,
clientSet
,
rs
,
ns
.
Name
)
...
...
@@ -428,7 +430,7 @@ func TestUpdateLabelToBeAdopted(t *testing.T) {
// 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
// left.
s
,
rm
,
podInformer
,
clientSet
:=
rmSetup
(
t
,
true
)
s
,
rm
,
rsInformer
,
podInformer
,
clientSet
:=
rmSetup
(
t
,
true
)
ns
:=
framework
.
CreateTestingNamespace
(
"rs-update-label-to-be-adopted"
,
s
,
t
)
defer
framework
.
DeleteTestingNamespace
(
ns
,
s
,
t
)
rs
:=
newRS
(
"rs"
,
ns
.
Name
,
1
)
...
...
@@ -442,6 +444,7 @@ func TestUpdateLabelToBeAdopted(t *testing.T) {
createRSsPods
(
t
,
clientSet
,
[]
*
v1beta1
.
ReplicaSet
{
rs
},
[]
*
v1
.
Pod
{
pod1
,
pod2
},
ns
.
Name
)
stopCh
:=
make
(
chan
struct
{})
go
rsInformer
.
Run
(
stopCh
)
go
podInformer
.
Run
(
stopCh
)
go
rm
.
Run
(
5
,
stopCh
)
waitRSStable
(
t
,
clientSet
,
rs
,
ns
.
Name
)
...
...
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