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
f0c33d65
Commit
f0c33d65
authored
Apr 14, 2016
by
deads2k
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
start sharing the pod cache and list/watch
parent
96d1f48b
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
169 additions
and
82 deletions
+169
-82
integration.go
cmd/integration/integration.go
+7
-2
controllermanager.go
cmd/kube-controller-manager/app/controllermanager.go
+14
-1
controllermanager.go
contrib/mesos/pkg/controllermanager/controllermanager.go
+2
-2
endpoints_controller.go
pkg/controller/endpoint/endpoints_controller.go
+32
-20
endpoints_controller_test.go
pkg/controller/endpoint/endpoints_controller_test.go
+12
-12
factory.go
pkg/controller/framework/informers/factory.go
+44
-0
replication_controller.go
pkg/controller/replication/replication_controller.go
+36
-24
replication_controller_test.go
pkg/controller/replication/replication_controller_test.go
+21
-20
master_utils.go
test/integration/framework/master_utils.go
+1
-1
No files found.
cmd/integration/integration.go
View file @
f0c33d65
...
...
@@ -44,6 +44,7 @@ import (
client
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/controller"
endpointcontroller
"k8s.io/kubernetes/pkg/controller/endpoint"
"k8s.io/kubernetes/pkg/controller/framework/informers"
nodecontroller
"k8s.io/kubernetes/pkg/controller/node"
replicationcontroller
"k8s.io/kubernetes/pkg/controller/replication"
cadvisortest
"k8s.io/kubernetes/pkg/kubelet/cadvisor/testing"
...
...
@@ -194,14 +195,18 @@ func startComponents(firstManifestURL, secondManifestURL string) (string, string
eventBroadcaster
.
StartRecordingToSink
(
cl
.
Events
(
""
))
scheduler
.
New
(
schedulerConfig
)
.
Run
()
podInformer
:=
informers
.
CreateSharedPodInformer
(
clientset
,
controller
.
NoResyncPeriodFunc
())
// ensure the service endpoints are sync'd several times within the window that the integration tests wait
go
endpointcontroller
.
NewEndpointController
(
clientset
,
controller
.
NoResyncPeriodFunc
)
.
go
endpointcontroller
.
NewEndpointController
(
podInformer
,
clientset
)
.
Run
(
3
,
wait
.
NeverStop
)
// TODO: Write an integration test for the replication controllers watch.
go
replicationcontroller
.
NewReplicationManager
(
clientset
,
controller
.
NoResyncPeriodFunc
,
replicationcontroller
.
BurstReplicas
,
4096
)
.
go
replicationcontroller
.
NewReplicationManager
(
podInformer
,
clientset
,
controller
.
NoResyncPeriodFunc
,
replicationcontroller
.
BurstReplicas
,
4096
)
.
Run
(
3
,
wait
.
NeverStop
)
go
podInformer
.
Run
(
wait
.
NeverStop
)
nodeController
:=
nodecontroller
.
NewNodeController
(
nil
,
clientset
,
5
*
time
.
Minute
,
flowcontrol
.
NewFakeAlwaysRateLimiter
(),
flowcontrol
.
NewFakeAlwaysRateLimiter
(),
40
*
time
.
Second
,
60
*
time
.
Second
,
5
*
time
.
Second
,
nil
,
false
)
nodeController
.
Run
(
5
*
time
.
Second
)
...
...
cmd/kube-controller-manager/app/controllermanager.go
View file @
f0c33d65
...
...
@@ -30,6 +30,7 @@ import (
"net/http"
"net/http/pprof"
"os"
"reflect"
"strconv"
"time"
...
...
@@ -48,6 +49,8 @@ import (
"k8s.io/kubernetes/pkg/controller/daemon"
"k8s.io/kubernetes/pkg/controller/deployment"
endpointcontroller
"k8s.io/kubernetes/pkg/controller/endpoint"
"k8s.io/kubernetes/pkg/controller/framework"
"k8s.io/kubernetes/pkg/controller/framework/informers"
"k8s.io/kubernetes/pkg/controller/gc"
"k8s.io/kubernetes/pkg/controller/job"
namespacecontroller
"k8s.io/kubernetes/pkg/controller/namespace"
...
...
@@ -189,11 +192,16 @@ func Run(s *options.CMServer) error {
}
func
StartControllers
(
s
*
options
.
CMServer
,
kubeClient
*
client
.
Client
,
kubeconfig
*
restclient
.
Config
,
stop
<-
chan
struct
{})
error
{
go
endpointcontroller
.
NewEndpointController
(
clientset
.
NewForConfigOrDie
(
restclient
.
AddUserAgent
(
kubeconfig
,
"endpoint-controller"
)),
ResyncPeriod
(
s
))
.
podInformer
:=
informers
.
CreateSharedPodInformer
(
clientset
.
NewForConfigOrDie
(
restclient
.
AddUserAgent
(
kubeconfig
,
"pod-informer"
)),
ResyncPeriod
(
s
)())
informers
:=
map
[
reflect
.
Type
]
framework
.
SharedInformer
{}
informers
[
reflect
.
TypeOf
(
&
api
.
Pod
{})]
=
podInformer
go
endpointcontroller
.
NewEndpointController
(
podInformer
,
clientset
.
NewForConfigOrDie
(
restclient
.
AddUserAgent
(
kubeconfig
,
"endpoint-controller"
)))
.
Run
(
s
.
ConcurrentEndpointSyncs
,
wait
.
NeverStop
)
time
.
Sleep
(
wait
.
Jitter
(
s
.
ControllerStartInterval
.
Duration
,
ControllerStartJitter
))
go
replicationcontroller
.
NewReplicationManager
(
podInformer
,
clientset
.
NewForConfigOrDie
(
restclient
.
AddUserAgent
(
kubeconfig
,
"replication-controller"
)),
ResyncPeriod
(
s
),
replicationcontroller
.
BurstReplicas
,
...
...
@@ -410,6 +418,11 @@ func StartControllers(s *options.CMServer, kubeClient *client.Client, kubeconfig
)
.
Run
()
time
.
Sleep
(
wait
.
Jitter
(
s
.
ControllerStartInterval
.
Duration
,
ControllerStartJitter
))
// run the shared informers
for
_
,
informer
:=
range
informers
{
go
informer
.
Run
(
wait
.
NeverStop
)
}
select
{}
}
...
...
contrib/mesos/pkg/controllermanager/controllermanager.go
View file @
f0c33d65
...
...
@@ -136,7 +136,7 @@ func (s *CMServer) Run(_ []string) error {
endpoints
:=
s
.
createEndpointController
(
clientset
.
NewForConfigOrDie
(
restclient
.
AddUserAgent
(
kubeconfig
,
"endpoint-controller"
)))
go
endpoints
.
Run
(
s
.
ConcurrentEndpointSyncs
,
wait
.
NeverStop
)
go
replicationcontroller
.
NewReplicationManager
(
clientset
.
NewForConfigOrDie
(
restclient
.
AddUserAgent
(
kubeconfig
,
"replication-controller"
)),
s
.
resyncPeriod
,
replicationcontroller
.
BurstReplicas
,
s
.
LookupCacheSizeForRC
)
.
go
replicationcontroller
.
NewReplicationManager
FromClient
(
clientset
.
NewForConfigOrDie
(
restclient
.
AddUserAgent
(
kubeconfig
,
"replication-controller"
)),
s
.
resyncPeriod
,
replicationcontroller
.
BurstReplicas
,
s
.
LookupCacheSizeForRC
)
.
Run
(
s
.
ConcurrentRCSyncs
,
wait
.
NeverStop
)
if
s
.
TerminatedPodGCThreshold
>
0
{
...
...
@@ -346,7 +346,7 @@ func (s *CMServer) createEndpointController(client *clientset.Clientset) kmendpo
return
kmendpoint
.
NewEndpointController
(
client
)
}
glog
.
V
(
2
)
.
Infof
(
"Creating podIP:containerPort endpoint controller"
)
stockEndpointController
:=
endpointcontroller
.
NewEndpointController
(
client
,
s
.
resyncPeriod
)
stockEndpointController
:=
endpointcontroller
.
NewEndpointController
FromClient
(
client
,
s
.
resyncPeriod
)
return
stockEndpointController
}
...
...
pkg/controller/endpoint/endpoints_controller.go
View file @
f0c33d65
...
...
@@ -33,6 +33,7 @@ import (
clientset
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/controller/framework"
"k8s.io/kubernetes/pkg/controller/framework/informers"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/runtime"
utilruntime
"k8s.io/kubernetes/pkg/util/runtime"
...
...
@@ -58,7 +59,7 @@ var (
)
// NewEndpointController returns a new *EndpointController.
func
NewEndpointController
(
client
*
clientset
.
Clientset
,
resyncPeriod
controller
.
ResyncPeriodFunc
)
*
EndpointController
{
func
NewEndpointController
(
podInformer
framework
.
SharedInformer
,
client
*
clientset
.
Clientset
)
*
EndpointController
{
e
:=
&
EndpointController
{
client
:
client
,
queue
:
workqueue
.
New
(),
...
...
@@ -85,24 +86,23 @@ func NewEndpointController(client *clientset.Clientset, resyncPeriod controller.
},
)
e
.
podStore
.
Store
,
e
.
podController
=
framework
.
NewInformer
(
&
cache
.
ListWatch
{
ListFunc
:
func
(
options
api
.
ListOptions
)
(
runtime
.
Object
,
error
)
{
return
e
.
client
.
Core
()
.
Pods
(
api
.
NamespaceAll
)
.
List
(
options
)
},
WatchFunc
:
func
(
options
api
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
return
e
.
client
.
Core
()
.
Pods
(
api
.
NamespaceAll
)
.
Watch
(
options
)
},
},
&
api
.
Pod
{},
resyncPeriod
(),
framework
.
ResourceEventHandlerFuncs
{
AddFunc
:
e
.
addPod
,
UpdateFunc
:
e
.
updatePod
,
DeleteFunc
:
e
.
deletePod
,
},
)
e
.
podStoreSynced
=
e
.
podController
.
HasSynced
podInformer
.
AddEventHandler
(
framework
.
ResourceEventHandlerFuncs
{
AddFunc
:
e
.
addPod
,
UpdateFunc
:
e
.
updatePod
,
DeleteFunc
:
e
.
deletePod
,
})
e
.
podStore
.
Store
=
podInformer
.
GetStore
()
e
.
podController
=
podInformer
.
GetController
()
e
.
podStoreSynced
=
podInformer
.
HasSynced
return
e
}
// NewEndpointControllerFromClient returns a new *EndpointController that runs its own informer.
func
NewEndpointControllerFromClient
(
client
*
clientset
.
Clientset
,
resyncPeriod
controller
.
ResyncPeriodFunc
)
*
EndpointController
{
podInformer
:=
informers
.
CreateSharedPodInformer
(
client
,
resyncPeriod
())
e
:=
NewEndpointController
(
podInformer
,
client
)
e
.
internalPodInformer
=
podInformer
return
e
}
...
...
@@ -114,6 +114,13 @@ type EndpointController struct {
serviceStore
cache
.
StoreToServiceLister
podStore
cache
.
StoreToPodLister
// internalPodInformer is used to hold a personal informer. If we're using
// a normal shared informer, then the informer will be started for us. If
// we have a personal informer, we must start it ourselves. If you start
// the controller using NewEndpointController(passing SharedInformer), this
// will be null
internalPodInformer
framework
.
SharedInformer
// Services that need to be updated. A channel is inappropriate here,
// because it allows services with lots of pods to be serviced much
// more often than services with few pods; it also would cause a
...
...
@@ -124,7 +131,7 @@ type EndpointController struct {
// Since we join two objects, we'll watch both of them with
// controllers.
serviceController
*
framework
.
Controller
podController
*
framework
.
Controller
podController
framework
.
ControllerInterface
// podStoreSynced returns true if the pod store has been synced at least once.
// Added as a member to the struct to allow injection for testing.
podStoreSynced
func
()
bool
...
...
@@ -144,6 +151,11 @@ func (e *EndpointController) Run(workers int, stopCh <-chan struct{}) {
time
.
Sleep
(
5
*
time
.
Minute
)
// give time for our cache to fill
e
.
checkLeftoverEndpoints
()
}()
if
e
.
internalPodInformer
!=
nil
{
go
e
.
internalPodInformer
.
Run
(
stopCh
)
}
<-
stopCh
e
.
queue
.
ShutDown
()
}
...
...
pkg/controller/endpoint/endpoints_controller_test.go
View file @
f0c33d65
...
...
@@ -108,7 +108,7 @@ func TestSyncEndpointsItemsPreserveNoSelector(t *testing.T) {
// TODO: Uncomment when fix #19254
// defer testServer.Close()
client
:=
clientset
.
NewForConfigOrDie
(
&
restclient
.
Config
{
Host
:
testServer
.
URL
,
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
testapi
.
Default
.
GroupVersion
()}})
endpoints
:=
NewEndpointController
(
client
,
controller
.
NoResyncPeriodFunc
)
endpoints
:=
NewEndpointController
FromClient
(
client
,
controller
.
NoResyncPeriodFunc
)
endpoints
.
podStoreSynced
=
alwaysReady
endpoints
.
serviceStore
.
Store
.
Add
(
&
api
.
Service
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
Namespace
:
ns
},
...
...
@@ -142,7 +142,7 @@ func TestCheckLeftoverEndpoints(t *testing.T) {
// TODO: Uncomment when fix #19254
// defer testServer.Close()
client
:=
clientset
.
NewForConfigOrDie
(
&
restclient
.
Config
{
Host
:
testServer
.
URL
,
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
testapi
.
Default
.
GroupVersion
()}})
endpoints
:=
NewEndpointController
(
client
,
controller
.
NoResyncPeriodFunc
)
endpoints
:=
NewEndpointController
FromClient
(
client
,
controller
.
NoResyncPeriodFunc
)
endpoints
.
podStoreSynced
=
alwaysReady
endpoints
.
checkLeftoverEndpoints
()
...
...
@@ -172,7 +172,7 @@ func TestSyncEndpointsProtocolTCP(t *testing.T) {
// TODO: Uncomment when fix #19254
// defer testServer.Close()
client
:=
clientset
.
NewForConfigOrDie
(
&
restclient
.
Config
{
Host
:
testServer
.
URL
,
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
testapi
.
Default
.
GroupVersion
()}})
endpoints
:=
NewEndpointController
(
client
,
controller
.
NoResyncPeriodFunc
)
endpoints
:=
NewEndpointController
FromClient
(
client
,
controller
.
NoResyncPeriodFunc
)
endpoints
.
podStoreSynced
=
alwaysReady
addPods
(
endpoints
.
podStore
.
Store
,
ns
,
1
,
1
,
0
)
...
...
@@ -216,7 +216,7 @@ func TestSyncEndpointsProtocolUDP(t *testing.T) {
// TODO: Uncomment when fix #19254
// defer testServer.Close()
client
:=
clientset
.
NewForConfigOrDie
(
&
restclient
.
Config
{
Host
:
testServer
.
URL
,
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
testapi
.
Default
.
GroupVersion
()}})
endpoints
:=
NewEndpointController
(
client
,
controller
.
NoResyncPeriodFunc
)
endpoints
:=
NewEndpointController
FromClient
(
client
,
controller
.
NoResyncPeriodFunc
)
endpoints
.
podStoreSynced
=
alwaysReady
addPods
(
endpoints
.
podStore
.
Store
,
ns
,
1
,
1
,
0
)
endpoints
.
serviceStore
.
Store
.
Add
(
&
api
.
Service
{
...
...
@@ -256,7 +256,7 @@ func TestSyncEndpointsItemsEmptySelectorSelectsAll(t *testing.T) {
// TODO: Uncomment when fix #19254
// defer testServer.Close()
client
:=
clientset
.
NewForConfigOrDie
(
&
restclient
.
Config
{
Host
:
testServer
.
URL
,
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
testapi
.
Default
.
GroupVersion
()}})
endpoints
:=
NewEndpointController
(
client
,
controller
.
NoResyncPeriodFunc
)
endpoints
:=
NewEndpointController
FromClient
(
client
,
controller
.
NoResyncPeriodFunc
)
endpoints
.
podStoreSynced
=
alwaysReady
addPods
(
endpoints
.
podStore
.
Store
,
ns
,
1
,
1
,
0
)
endpoints
.
serviceStore
.
Store
.
Add
(
&
api
.
Service
{
...
...
@@ -295,7 +295,7 @@ func TestSyncEndpointsItemsEmptySelectorSelectsAllNotReady(t *testing.T) {
// TODO: Uncomment when fix #19254
// defer testServer.Close()
client
:=
clientset
.
NewForConfigOrDie
(
&
restclient
.
Config
{
Host
:
testServer
.
URL
,
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
testapi
.
Default
.
GroupVersion
()}})
endpoints
:=
NewEndpointController
(
client
,
controller
.
NoResyncPeriodFunc
)
endpoints
:=
NewEndpointController
FromClient
(
client
,
controller
.
NoResyncPeriodFunc
)
endpoints
.
podStoreSynced
=
alwaysReady
addPods
(
endpoints
.
podStore
.
Store
,
ns
,
0
,
1
,
1
)
endpoints
.
serviceStore
.
Store
.
Add
(
&
api
.
Service
{
...
...
@@ -334,7 +334,7 @@ func TestSyncEndpointsItemsEmptySelectorSelectsAllMixed(t *testing.T) {
// TODO: Uncomment when fix #19254
// defer testServer.Close()
client
:=
clientset
.
NewForConfigOrDie
(
&
restclient
.
Config
{
Host
:
testServer
.
URL
,
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
testapi
.
Default
.
GroupVersion
()}})
endpoints
:=
NewEndpointController
(
client
,
controller
.
NoResyncPeriodFunc
)
endpoints
:=
NewEndpointController
FromClient
(
client
,
controller
.
NoResyncPeriodFunc
)
endpoints
.
podStoreSynced
=
alwaysReady
addPods
(
endpoints
.
podStore
.
Store
,
ns
,
1
,
1
,
1
)
endpoints
.
serviceStore
.
Store
.
Add
(
&
api
.
Service
{
...
...
@@ -377,7 +377,7 @@ func TestSyncEndpointsItemsPreexisting(t *testing.T) {
// TODO: Uncomment when fix #19254
// defer testServer.Close()
client
:=
clientset
.
NewForConfigOrDie
(
&
restclient
.
Config
{
Host
:
testServer
.
URL
,
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
testapi
.
Default
.
GroupVersion
()}})
endpoints
:=
NewEndpointController
(
client
,
controller
.
NoResyncPeriodFunc
)
endpoints
:=
NewEndpointController
FromClient
(
client
,
controller
.
NoResyncPeriodFunc
)
endpoints
.
podStoreSynced
=
alwaysReady
addPods
(
endpoints
.
podStore
.
Store
,
ns
,
1
,
1
,
0
)
endpoints
.
serviceStore
.
Store
.
Add
(
&
api
.
Service
{
...
...
@@ -419,7 +419,7 @@ func TestSyncEndpointsItemsPreexistingIdentical(t *testing.T) {
// TODO: Uncomment when fix #19254
// defer testServer.Close()
client
:=
clientset
.
NewForConfigOrDie
(
&
restclient
.
Config
{
Host
:
testServer
.
URL
,
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
testapi
.
Default
.
GroupVersion
()}})
endpoints
:=
NewEndpointController
(
client
,
controller
.
NoResyncPeriodFunc
)
endpoints
:=
NewEndpointController
FromClient
(
client
,
controller
.
NoResyncPeriodFunc
)
endpoints
.
podStoreSynced
=
alwaysReady
addPods
(
endpoints
.
podStore
.
Store
,
api
.
NamespaceDefault
,
1
,
1
,
0
)
endpoints
.
serviceStore
.
Store
.
Add
(
&
api
.
Service
{
...
...
@@ -440,7 +440,7 @@ func TestSyncEndpointsItems(t *testing.T) {
// TODO: Uncomment when fix #19254
// defer testServer.Close()
client
:=
clientset
.
NewForConfigOrDie
(
&
restclient
.
Config
{
Host
:
testServer
.
URL
,
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
testapi
.
Default
.
GroupVersion
()}})
endpoints
:=
NewEndpointController
(
client
,
controller
.
NoResyncPeriodFunc
)
endpoints
:=
NewEndpointController
FromClient
(
client
,
controller
.
NoResyncPeriodFunc
)
endpoints
.
podStoreSynced
=
alwaysReady
addPods
(
endpoints
.
podStore
.
Store
,
ns
,
3
,
2
,
0
)
addPods
(
endpoints
.
podStore
.
Store
,
"blah"
,
5
,
2
,
0
)
// make sure these aren't found!
...
...
@@ -484,7 +484,7 @@ func TestSyncEndpointsItemsWithLabels(t *testing.T) {
// TODO: Uncomment when fix #19254
// defer testServer.Close()
client
:=
clientset
.
NewForConfigOrDie
(
&
restclient
.
Config
{
Host
:
testServer
.
URL
,
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
testapi
.
Default
.
GroupVersion
()}})
endpoints
:=
NewEndpointController
(
client
,
controller
.
NoResyncPeriodFunc
)
endpoints
:=
NewEndpointController
FromClient
(
client
,
controller
.
NoResyncPeriodFunc
)
endpoints
.
podStoreSynced
=
alwaysReady
addPods
(
endpoints
.
podStore
.
Store
,
ns
,
3
,
2
,
0
)
serviceLabels
:=
map
[
string
]
string
{
"foo"
:
"bar"
}
...
...
@@ -546,7 +546,7 @@ func TestSyncEndpointsItemsPreexistingLabelsChange(t *testing.T) {
// TODO: Uncomment when fix #19254
// defer testServer.Close()
client
:=
clientset
.
NewForConfigOrDie
(
&
restclient
.
Config
{
Host
:
testServer
.
URL
,
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
testapi
.
Default
.
GroupVersion
()}})
endpoints
:=
NewEndpointController
(
client
,
controller
.
NoResyncPeriodFunc
)
endpoints
:=
NewEndpointController
FromClient
(
client
,
controller
.
NoResyncPeriodFunc
)
endpoints
.
podStoreSynced
=
alwaysReady
addPods
(
endpoints
.
podStore
.
Store
,
ns
,
1
,
1
,
0
)
serviceLabels
:=
map
[
string
]
string
{
"baz"
:
"blah"
}
...
...
pkg/controller/framework/informers/factory.go
0 → 100644
View file @
f0c33d65
/*
Copyright 2015 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
informers
import
(
"time"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/client/cache"
clientset
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"k8s.io/kubernetes/pkg/controller/framework"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/watch"
)
// CreateSharedPodInformer returns a SharedInformer that lists and watches all pods
func
CreateSharedPodInformer
(
client
clientset
.
Interface
,
resyncPeriod
time
.
Duration
)
framework
.
SharedInformer
{
sharedInformer
:=
framework
.
NewSharedInformer
(
&
cache
.
ListWatch
{
ListFunc
:
func
(
options
api
.
ListOptions
)
(
runtime
.
Object
,
error
)
{
return
client
.
Core
()
.
Pods
(
api
.
NamespaceAll
)
.
List
(
options
)
},
WatchFunc
:
func
(
options
api
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
return
client
.
Core
()
.
Pods
(
api
.
NamespaceAll
)
.
Watch
(
options
)
},
},
&
api
.
Pod
{},
resyncPeriod
)
return
sharedInformer
}
pkg/controller/replication/replication_controller.go
View file @
f0c33d65
...
...
@@ -32,6 +32,7 @@ import (
"k8s.io/kubernetes/pkg/client/record"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/controller/framework"
"k8s.io/kubernetes/pkg/controller/framework/informers"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/runtime"
utilruntime
"k8s.io/kubernetes/pkg/util/runtime"
...
...
@@ -66,6 +67,13 @@ type ReplicationManager struct {
kubeClient
clientset
.
Interface
podControl
controller
.
PodControlInterface
// internalPodInformer is used to hold a personal informer. If we're using
// a normal shared informer, then the informer will be started for us. If
// we have a personal informer, we must start it ourselves. If you start
// the controller using NewReplicationManager(passing SharedInformer), this
// will be null
internalPodInformer
framework
.
SharedInformer
// An rc is temporarily suspended after creating/deleting these many replicas.
// It resumes normal action after observing the watch events for them.
burstReplicas
int
...
...
@@ -82,7 +90,7 @@ type ReplicationManager struct {
// A store of pods, populated by the podController
podStore
cache
.
StoreToPodLister
// Watches changes to all pods
podController
*
framework
.
Controller
podController
framework
.
ControllerInterface
// podStoreSynced returns true if the pod store has been synced at least once.
// Added as a member to the struct to allow injection for testing.
podStoreSynced
func
()
bool
...
...
@@ -93,8 +101,7 @@ type ReplicationManager struct {
queue
*
workqueue
.
Type
}
// NewReplicationManager creates a new ReplicationManager.
func
NewReplicationManager
(
kubeClient
clientset
.
Interface
,
resyncPeriod
controller
.
ResyncPeriodFunc
,
burstReplicas
int
,
lookupCacheSize
int
)
*
ReplicationManager
{
func
NewReplicationManager
(
podInformer
framework
.
SharedInformer
,
kubeClient
clientset
.
Interface
,
resyncPeriod
controller
.
ResyncPeriodFunc
,
burstReplicas
int
,
lookupCacheSize
int
)
*
ReplicationManager
{
eventBroadcaster
:=
record
.
NewBroadcaster
()
eventBroadcaster
.
StartLogging
(
glog
.
Infof
)
eventBroadcaster
.
StartRecordingToSink
(
&
unversionedcore
.
EventSinkImpl
{
Interface
:
kubeClient
.
Core
()
.
Events
(
""
)})
...
...
@@ -167,31 +174,31 @@ func NewReplicationManager(kubeClient clientset.Interface, resyncPeriod controll
},
)
rm
.
podStore
.
Store
,
rm
.
podController
=
framework
.
NewInformer
(
&
cache
.
ListWatch
{
ListFunc
:
func
(
options
api
.
ListOptions
)
(
runtime
.
Object
,
error
)
{
return
rm
.
kubeClient
.
Core
()
.
Pods
(
api
.
NamespaceAll
)
.
List
(
options
)
},
WatchFunc
:
func
(
options
api
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
return
rm
.
kubeClient
.
Core
()
.
Pods
(
api
.
NamespaceAll
)
.
Watch
(
options
)
},
},
&
api
.
Pod
{},
resyncPeriod
(),
framework
.
ResourceEventHandlerFuncs
{
AddFunc
:
rm
.
addPod
,
// This invokes the rc for every pod change, eg: host assignment. Though this might seem like overkill
// the most frequent pod update is status, and the associated rc will only list from local storage, so
// it should be ok.
UpdateFunc
:
rm
.
updatePod
,
DeleteFunc
:
rm
.
deletePod
,
},
)
podInformer
.
AddEventHandler
(
framework
.
ResourceEventHandlerFuncs
{
AddFunc
:
rm
.
addPod
,
// This invokes the rc for every pod change, eg: host assignment. Though this might seem like overkill
// the most frequent pod update is status, and the associated rc will only list from local storage, so
// it should be ok.
UpdateFunc
:
rm
.
updatePod
,
DeleteFunc
:
rm
.
deletePod
,
})
rm
.
podStore
.
Store
=
podInformer
.
GetStore
()
rm
.
podController
=
podInformer
.
GetController
()
rm
.
syncHandler
=
rm
.
syncReplicationController
rm
.
podStoreSynced
=
rm
.
podController
.
HasSynced
rm
.
lookupCache
=
controller
.
NewMatchingCache
(
lookupCacheSize
)
return
rm
}
// NewReplicationManagerFromClient creates a new ReplicationManager that runs its own informer.
func
NewReplicationManagerFromClient
(
kubeClient
clientset
.
Interface
,
resyncPeriod
controller
.
ResyncPeriodFunc
,
burstReplicas
int
,
lookupCacheSize
int
)
*
ReplicationManager
{
podInformer
:=
informers
.
CreateSharedPodInformer
(
kubeClient
,
resyncPeriod
())
rm
:=
NewReplicationManager
(
podInformer
,
kubeClient
,
resyncPeriod
,
burstReplicas
,
lookupCacheSize
)
rm
.
internalPodInformer
=
podInformer
return
rm
}
// SetEventRecorder replaces the event recorder used by the replication manager
...
...
@@ -211,6 +218,11 @@ func (rm *ReplicationManager) Run(workers int, stopCh <-chan struct{}) {
for
i
:=
0
;
i
<
workers
;
i
++
{
go
wait
.
Until
(
rm
.
worker
,
time
.
Second
,
stopCh
)
}
if
rm
.
internalPodInformer
!=
nil
{
go
rm
.
internalPodInformer
.
Run
(
stopCh
)
}
<-
stopCh
glog
.
Infof
(
"Shutting down RC Manager"
)
rm
.
queue
.
ShutDown
()
...
...
@@ -478,7 +490,7 @@ func (rm *ReplicationManager) manageReplicas(filteredPods []*api.Pod, rc *api.Re
if
err
:=
rm
.
podControl
.
DeletePod
(
rc
.
Namespace
,
filteredPods
[
ix
]
.
Name
,
rc
);
err
!=
nil
{
// Decrement the expected number of deletes because the informer won't observe this deletion
podKey
:=
controller
.
PodKey
(
filteredPods
[
ix
])
glog
.
V
(
2
)
.
Infof
(
"Failed to delete %v
, decrementing expectations for controller %q/%q"
,
podKey
,
rc
.
Namespace
,
rc
.
Name
)
glog
.
V
(
2
)
.
Infof
(
"Failed to delete %v
due to %v, decrementing expectations for controller %q/%q"
,
podKey
,
err
,
rc
.
Namespace
,
rc
.
Name
)
rm
.
expectations
.
DeletionObserved
(
rcKey
,
podKey
)
utilruntime
.
HandleError
(
err
)
}
...
...
pkg/controller/replication/replication_controller_test.go
View file @
f0c33d65
This diff is collapsed.
Click to expand it.
test/integration/framework/master_utils.go
View file @
f0c33d65
...
...
@@ -108,7 +108,7 @@ func NewMasterComponents(c *Config) *MasterComponents {
restClient
:=
client
.
NewOrDie
(
&
restclient
.
Config
{
Host
:
s
.
URL
,
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
testapi
.
Default
.
GroupVersion
()},
QPS
:
c
.
QPS
,
Burst
:
c
.
Burst
})
clientset
:=
clientset
.
NewForConfigOrDie
(
&
restclient
.
Config
{
Host
:
s
.
URL
,
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
testapi
.
Default
.
GroupVersion
()},
QPS
:
c
.
QPS
,
Burst
:
c
.
Burst
})
rcStopCh
:=
make
(
chan
struct
{})
controllerManager
:=
replicationcontroller
.
NewReplicationManager
(
clientset
,
controller
.
NoResyncPeriodFunc
,
c
.
Burst
,
4096
)
controllerManager
:=
replicationcontroller
.
NewReplicationManager
FromClient
(
clientset
,
controller
.
NoResyncPeriodFunc
,
c
.
Burst
,
4096
)
// TODO: Support events once we can cleanly shutdown an event recorder.
controllerManager
.
SetEventRecorder
(
&
record
.
FakeRecorder
{})
...
...
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