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
c10f43a2
Commit
c10f43a2
authored
May 02, 2016
by
mqliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement AddIndexers for SharedIndexInformer
parent
9011207f
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
107 additions
and
61 deletions
+107
-61
integration.go
cmd/integration/integration.go
+1
-2
controllermanager.go
cmd/kube-controller-manager/app/controllermanager.go
+1
-2
index.go
pkg/client/cache/index.go
+2
-0
listers.go
pkg/client/cache/listers.go
+16
-1
store.go
pkg/client/cache/store.go
+5
-0
thread_safe_store.go
pkg/client/cache/thread_safe_store.go
+5
-0
controller.go
pkg/controller/daemon/controller.go
+1
-1
endpoints_controller.go
pkg/controller/endpoint/endpoints_controller.go
+1
-1
factory.go
pkg/controller/framework/informers/factory.go
+13
-7
shared_informer.go
pkg/controller/framework/shared_informer.go
+48
-35
gc_controller.go
pkg/controller/gc/gc_controller.go
+4
-2
controller.go
pkg/controller/job/controller.go
+1
-1
nodecontroller.go
pkg/controller/node/nodecontroller.go
+4
-2
pet_set.go
pkg/controller/petset/pet_set.go
+2
-2
pet_set_test.go
pkg/controller/petset/pet_set_test.go
+1
-1
replication_controller.go
pkg/controller/replication/replication_controller.go
+1
-1
replication_controller_test.go
pkg/controller/replication/replication_controller_test.go
+1
-3
No files found.
cmd/integration/integration.go
View file @
c10f43a2
...
@@ -38,7 +38,6 @@ import (
...
@@ -38,7 +38,6 @@ import (
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/client/cache"
clientset
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
clientset
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"k8s.io/kubernetes/pkg/client/record"
"k8s.io/kubernetes/pkg/client/record"
"k8s.io/kubernetes/pkg/client/restclient"
"k8s.io/kubernetes/pkg/client/restclient"
...
@@ -195,7 +194,7 @@ func startComponents(firstManifestURL, secondManifestURL string) (string, string
...
@@ -195,7 +194,7 @@ func startComponents(firstManifestURL, secondManifestURL string) (string, string
eventBroadcaster
.
StartRecordingToSink
(
cl
.
Events
(
""
))
eventBroadcaster
.
StartRecordingToSink
(
cl
.
Events
(
""
))
scheduler
.
New
(
schedulerConfig
)
.
Run
()
scheduler
.
New
(
schedulerConfig
)
.
Run
()
podInformer
:=
informers
.
CreateShared
IndexPodInformer
(
clientset
,
controller
.
NoResyncPeriodFunc
(),
cache
.
Indexers
{
cache
.
NamespaceIndex
:
cache
.
MetaNamespaceIndexFunc
}
)
podInformer
:=
informers
.
CreateShared
PodIndexInformer
(
clientset
,
controller
.
NoResyncPeriodFunc
()
)
// ensure the service endpoints are sync'd several times within the window that the integration tests wait
// ensure the service endpoints are sync'd several times within the window that the integration tests wait
go
endpointcontroller
.
NewEndpointController
(
podInformer
,
clientset
)
.
go
endpointcontroller
.
NewEndpointController
(
podInformer
,
clientset
)
.
...
...
cmd/kube-controller-manager/app/controllermanager.go
View file @
c10f43a2
...
@@ -37,7 +37,6 @@ import (
...
@@ -37,7 +37,6 @@ import (
"k8s.io/kubernetes/cmd/kube-controller-manager/app/options"
"k8s.io/kubernetes/cmd/kube-controller-manager/app/options"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/client/cache"
clientset
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
clientset
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"k8s.io/kubernetes/pkg/client/leaderelection"
"k8s.io/kubernetes/pkg/client/leaderelection"
"k8s.io/kubernetes/pkg/client/record"
"k8s.io/kubernetes/pkg/client/record"
...
@@ -195,7 +194,7 @@ func Run(s *options.CMServer) error {
...
@@ -195,7 +194,7 @@ func Run(s *options.CMServer) error {
}
}
func
StartControllers
(
s
*
options
.
CMServer
,
kubeClient
*
client
.
Client
,
kubeconfig
*
restclient
.
Config
,
stop
<-
chan
struct
{})
error
{
func
StartControllers
(
s
*
options
.
CMServer
,
kubeClient
*
client
.
Client
,
kubeconfig
*
restclient
.
Config
,
stop
<-
chan
struct
{})
error
{
podInformer
:=
informers
.
CreateShared
IndexPodInformer
(
clientset
.
NewForConfigOrDie
(
restclient
.
AddUserAgent
(
kubeconfig
,
"pod-informer"
)),
ResyncPeriod
(
s
)(),
cache
.
Indexers
{
cache
.
NamespaceIndex
:
cache
.
MetaNamespaceIndexFunc
}
)
podInformer
:=
informers
.
CreateShared
PodIndexInformer
(
clientset
.
NewForConfigOrDie
(
restclient
.
AddUserAgent
(
kubeconfig
,
"pod-informer"
)),
ResyncPeriod
(
s
)()
)
informers
:=
map
[
reflect
.
Type
]
framework
.
SharedIndexInformer
{}
informers
:=
map
[
reflect
.
Type
]
framework
.
SharedIndexInformer
{}
informers
[
reflect
.
TypeOf
(
&
api
.
Pod
{})]
=
podInformer
informers
[
reflect
.
TypeOf
(
&
api
.
Pod
{})]
=
podInformer
...
...
pkg/client/cache/index.go
View file @
c10f43a2
...
@@ -32,6 +32,8 @@ type Indexer interface {
...
@@ -32,6 +32,8 @@ type Indexer interface {
ListIndexFuncValues
(
indexName
string
)
[]
string
ListIndexFuncValues
(
indexName
string
)
[]
string
// ByIndex lists object that match on the named indexing function with the exact key
// ByIndex lists object that match on the named indexing function with the exact key
ByIndex
(
indexName
,
indexKey
string
)
([]
interface
{},
error
)
ByIndex
(
indexName
,
indexKey
string
)
([]
interface
{},
error
)
// GetIndexer return the indexers
GetIndexers
()
Indexers
}
}
// IndexFunc knows how to provide an indexed value for an object.
// IndexFunc knows how to provide an indexed value for an object.
...
...
pkg/client/cache/listers.go
View file @
c10f43a2
...
@@ -91,8 +91,16 @@ func (s storePodsNamespacer) List(selector labels.Selector) (pods api.PodList, e
...
@@ -91,8 +91,16 @@ func (s storePodsNamespacer) List(selector labels.Selector) (pods api.PodList, e
key
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
s
.
namespace
}}
key
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
s
.
namespace
}}
items
,
err
:=
s
.
indexer
.
Index
(
NamespaceIndex
,
key
)
items
,
err
:=
s
.
indexer
.
Index
(
NamespaceIndex
,
key
)
if
err
!=
nil
{
if
err
!=
nil
{
return
api
.
PodList
{},
err
glog
.
Warningf
(
"can not retrieve list of objects using index : %v"
,
err
)
for
_
,
m
:=
range
s
.
indexer
.
List
()
{
pod
:=
m
.
(
*
api
.
Pod
)
if
s
.
namespace
==
pod
.
Namespace
&&
selector
.
Matches
(
labels
.
Set
(
pod
.
Labels
))
{
list
.
Items
=
append
(
list
.
Items
,
*
pod
)
}
}
return
list
,
err
}
}
for
_
,
m
:=
range
items
{
for
_
,
m
:=
range
items
{
pod
:=
m
.
(
*
api
.
Pod
)
pod
:=
m
.
(
*
api
.
Pod
)
if
selector
.
Matches
(
labels
.
Set
(
pod
.
Labels
))
{
if
selector
.
Matches
(
labels
.
Set
(
pod
.
Labels
))
{
...
@@ -200,6 +208,13 @@ func (s storeReplicationControllersNamespacer) List(selector labels.Selector) (c
...
@@ -200,6 +208,13 @@ func (s storeReplicationControllersNamespacer) List(selector labels.Selector) (c
key
:=
&
api
.
ReplicationController
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
s
.
namespace
}}
key
:=
&
api
.
ReplicationController
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
s
.
namespace
}}
items
,
err
:=
s
.
indexer
.
Index
(
NamespaceIndex
,
key
)
items
,
err
:=
s
.
indexer
.
Index
(
NamespaceIndex
,
key
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Warningf
(
"can not retrieve list of objects using index : %v"
,
err
)
for
_
,
m
:=
range
s
.
indexer
.
List
()
{
rc
:=
*
(
m
.
(
*
api
.
ReplicationController
))
if
s
.
namespace
==
rc
.
Namespace
&&
selector
.
Matches
(
labels
.
Set
(
rc
.
Labels
))
{
controllers
=
append
(
controllers
,
rc
)
}
}
return
return
}
}
for
_
,
m
:=
range
items
{
for
_
,
m
:=
range
items
{
...
...
pkg/client/cache/store.go
View file @
c10f43a2
...
@@ -160,6 +160,11 @@ func (c *cache) ListKeys() []string {
...
@@ -160,6 +160,11 @@ func (c *cache) ListKeys() []string {
return
c
.
cacheStorage
.
ListKeys
()
return
c
.
cacheStorage
.
ListKeys
()
}
}
// GetIndexers returns the indexers of cache
func
(
c
*
cache
)
GetIndexers
()
Indexers
{
return
c
.
cacheStorage
.
GetIndexers
()
}
// Index returns a list of items that match on the index function
// Index returns a list of items that match on the index function
// Index is thread-safe so long as you treat all items as immutable
// Index is thread-safe so long as you treat all items as immutable
func
(
c
*
cache
)
Index
(
indexName
string
,
obj
interface
{})
([]
interface
{},
error
)
{
func
(
c
*
cache
)
Index
(
indexName
string
,
obj
interface
{})
([]
interface
{},
error
)
{
...
...
pkg/client/cache/thread_safe_store.go
View file @
c10f43a2
...
@@ -45,6 +45,7 @@ type ThreadSafeStore interface {
...
@@ -45,6 +45,7 @@ type ThreadSafeStore interface {
Index
(
indexName
string
,
obj
interface
{})
([]
interface
{},
error
)
Index
(
indexName
string
,
obj
interface
{})
([]
interface
{},
error
)
ListIndexFuncValues
(
name
string
)
[]
string
ListIndexFuncValues
(
name
string
)
[]
string
ByIndex
(
indexName
,
indexKey
string
)
([]
interface
{},
error
)
ByIndex
(
indexName
,
indexKey
string
)
([]
interface
{},
error
)
GetIndexers
()
Indexers
}
}
// threadSafeMap implements ThreadSafeStore
// threadSafeMap implements ThreadSafeStore
...
@@ -187,6 +188,10 @@ func (c *threadSafeMap) ListIndexFuncValues(indexName string) []string {
...
@@ -187,6 +188,10 @@ func (c *threadSafeMap) ListIndexFuncValues(indexName string) []string {
return
names
return
names
}
}
func
(
c
*
threadSafeMap
)
GetIndexers
()
Indexers
{
return
c
.
indexers
}
// updateIndices modifies the objects location in the managed indexes, if this is an update, you must provide an oldObj
// updateIndices modifies the objects location in the managed indexes, if this is an update, you must provide an oldObj
// updateIndices must be called from a function that already has a lock on the cache
// updateIndices must be called from a function that already has a lock on the cache
func
(
c
*
threadSafeMap
)
updateIndices
(
oldObj
interface
{},
newObj
interface
{},
key
string
)
error
{
func
(
c
*
threadSafeMap
)
updateIndices
(
oldObj
interface
{},
newObj
interface
{},
key
string
)
error
{
...
...
pkg/controller/daemon/controller.go
View file @
c10f43a2
...
@@ -210,7 +210,7 @@ func NewDaemonSetsController(podInformer framework.SharedIndexInformer, kubeClie
...
@@ -210,7 +210,7 @@ func NewDaemonSetsController(podInformer framework.SharedIndexInformer, kubeClie
}
}
func
NewDaemonSetsControllerFromClient
(
kubeClient
clientset
.
Interface
,
resyncPeriod
controller
.
ResyncPeriodFunc
,
lookupCacheSize
int
)
*
DaemonSetsController
{
func
NewDaemonSetsControllerFromClient
(
kubeClient
clientset
.
Interface
,
resyncPeriod
controller
.
ResyncPeriodFunc
,
lookupCacheSize
int
)
*
DaemonSetsController
{
podInformer
:=
informers
.
CreateShared
IndexPodInformer
(
kubeClient
,
resyncPeriod
(),
cache
.
Indexers
{
cache
.
NamespaceIndex
:
cache
.
MetaNamespaceIndexFunc
}
)
podInformer
:=
informers
.
CreateShared
PodIndexInformer
(
kubeClient
,
resyncPeriod
()
)
dsc
:=
NewDaemonSetsController
(
podInformer
,
kubeClient
,
resyncPeriod
,
lookupCacheSize
)
dsc
:=
NewDaemonSetsController
(
podInformer
,
kubeClient
,
resyncPeriod
,
lookupCacheSize
)
dsc
.
internalPodInformer
=
podInformer
dsc
.
internalPodInformer
=
podInformer
...
...
pkg/controller/endpoint/endpoints_controller.go
View file @
c10f43a2
...
@@ -104,7 +104,7 @@ func NewEndpointController(podInformer framework.SharedIndexInformer, client *cl
...
@@ -104,7 +104,7 @@ func NewEndpointController(podInformer framework.SharedIndexInformer, client *cl
// NewEndpointControllerFromClient returns a new *EndpointController that runs its own informer.
// NewEndpointControllerFromClient returns a new *EndpointController that runs its own informer.
func
NewEndpointControllerFromClient
(
client
*
clientset
.
Clientset
,
resyncPeriod
controller
.
ResyncPeriodFunc
)
*
EndpointController
{
func
NewEndpointControllerFromClient
(
client
*
clientset
.
Clientset
,
resyncPeriod
controller
.
ResyncPeriodFunc
)
*
EndpointController
{
podInformer
:=
informers
.
CreateShared
IndexPodInformer
(
client
,
resyncPeriod
(),
cache
.
Indexers
{
cache
.
NamespaceIndex
:
cache
.
MetaNamespaceIndexFunc
}
)
podInformer
:=
informers
.
CreateShared
PodIndexInformer
(
client
,
resyncPeriod
()
)
e
:=
NewEndpointController
(
podInformer
,
client
)
e
:=
NewEndpointController
(
podInformer
,
client
)
e
.
internalPodInformer
=
podInformer
e
.
internalPodInformer
=
podInformer
...
...
pkg/controller/framework/informers/factory.go
View file @
c10f43a2
...
@@ -27,9 +27,9 @@ import (
...
@@ -27,9 +27,9 @@ import (
"k8s.io/kubernetes/pkg/watch"
"k8s.io/kubernetes/pkg/watch"
)
)
// CreateSharedPodInformer returns a SharedInformer that lists and watches all pods
// CreateSharedPodInformer returns a SharedIn
dexIn
former that lists and watches all pods
func
CreateSharedPodInformer
(
client
clientset
.
Interface
,
resyncPeriod
time
.
Duration
)
framework
.
SharedInformer
{
func
CreateSharedPodInformer
(
client
clientset
.
Interface
,
resyncPeriod
time
.
Duration
)
framework
.
SharedIn
dexIn
former
{
sharedInformer
:=
framework
.
NewSharedInformer
(
sharedInformer
:=
framework
.
NewSharedIn
dexIn
former
(
&
cache
.
ListWatch
{
&
cache
.
ListWatch
{
ListFunc
:
func
(
options
api
.
ListOptions
)
(
runtime
.
Object
,
error
)
{
ListFunc
:
func
(
options
api
.
ListOptions
)
(
runtime
.
Object
,
error
)
{
return
client
.
Core
()
.
Pods
(
api
.
NamespaceAll
)
.
List
(
options
)
return
client
.
Core
()
.
Pods
(
api
.
NamespaceAll
)
.
List
(
options
)
...
@@ -38,13 +38,16 @@ func CreateSharedPodInformer(client clientset.Interface, resyncPeriod time.Durat
...
@@ -38,13 +38,16 @@ func CreateSharedPodInformer(client clientset.Interface, resyncPeriod time.Durat
return
client
.
Core
()
.
Pods
(
api
.
NamespaceAll
)
.
Watch
(
options
)
return
client
.
Core
()
.
Pods
(
api
.
NamespaceAll
)
.
Watch
(
options
)
},
},
},
},
&
api
.
Pod
{},
resyncPeriod
)
&
api
.
Pod
{},
resyncPeriod
,
cache
.
Indexers
{},
)
return
sharedInformer
return
sharedInformer
}
}
// CreateShared
IndexPod
Informer returns a SharedIndexInformer that lists and watches all pods
// CreateShared
PodIndex
Informer returns a SharedIndexInformer that lists and watches all pods
func
CreateShared
IndexPodInformer
(
client
clientset
.
Interface
,
resyncPeriod
time
.
Duration
,
indexers
cache
.
Indexers
)
framework
.
SharedIndexInformer
{
func
CreateShared
PodIndexInformer
(
client
clientset
.
Interface
,
resyncPeriod
time
.
Duration
)
framework
.
SharedIndexInformer
{
sharedIndexInformer
:=
framework
.
NewSharedIndexInformer
(
sharedIndexInformer
:=
framework
.
NewSharedIndexInformer
(
&
cache
.
ListWatch
{
&
cache
.
ListWatch
{
ListFunc
:
func
(
options
api
.
ListOptions
)
(
runtime
.
Object
,
error
)
{
ListFunc
:
func
(
options
api
.
ListOptions
)
(
runtime
.
Object
,
error
)
{
...
@@ -54,7 +57,10 @@ func CreateSharedIndexPodInformer(client clientset.Interface, resyncPeriod time.
...
@@ -54,7 +57,10 @@ func CreateSharedIndexPodInformer(client clientset.Interface, resyncPeriod time.
return
client
.
Core
()
.
Pods
(
api
.
NamespaceAll
)
.
Watch
(
options
)
return
client
.
Core
()
.
Pods
(
api
.
NamespaceAll
)
.
Watch
(
options
)
},
},
},
},
&
api
.
Pod
{},
resyncPeriod
,
indexers
)
&
api
.
Pod
{},
resyncPeriod
,
cache
.
Indexers
{
cache
.
NamespaceIndex
:
cache
.
MetaNamespaceIndexFunc
},
)
return
sharedIndexInformer
return
sharedIndexInformer
}
}
pkg/controller/framework/shared_informer.go
View file @
c10f43a2
...
@@ -48,6 +48,7 @@ type SharedInformer interface {
...
@@ -48,6 +48,7 @@ type SharedInformer interface {
type
SharedIndexInformer
interface
{
type
SharedIndexInformer
interface
{
SharedInformer
SharedInformer
// AddIndexers add indexers to the informer before it starts.
AddIndexers
(
indexers
cache
.
Indexers
)
error
AddIndexers
(
indexers
cache
.
Indexers
)
error
GetIndexer
()
cache
.
Indexer
GetIndexer
()
cache
.
Indexer
}
}
...
@@ -57,48 +58,26 @@ type SharedIndexInformer interface {
...
@@ -57,48 +58,26 @@ type SharedIndexInformer interface {
// be shared amongst all consumers.
// be shared amongst all consumers.
func
NewSharedInformer
(
lw
cache
.
ListerWatcher
,
objType
runtime
.
Object
,
resyncPeriod
time
.
Duration
)
SharedInformer
{
func
NewSharedInformer
(
lw
cache
.
ListerWatcher
,
objType
runtime
.
Object
,
resyncPeriod
time
.
Duration
)
SharedInformer
{
sharedInformer
:=
&
sharedIndexInformer
{
sharedInformer
:=
&
sharedIndexInformer
{
processor
:
&
sharedProcessor
{},
processor
:
&
sharedProcessor
{},
indexer
:
cache
.
NewIndexer
(
DeletionHandlingMetaNamespaceKeyFunc
,
cache
.
Indexers
{}),
indexer
:
cache
.
NewIndexer
(
DeletionHandlingMetaNamespaceKeyFunc
,
cache
.
Indexers
{}),
listerWatcher
:
lw
,
objectType
:
objType
,
fullResyncPeriod
:
resyncPeriod
,
}
}
fifo
:=
cache
.
NewDeltaFIFO
(
cache
.
MetaNamespaceKeyFunc
,
nil
,
sharedInformer
.
indexer
)
cfg
:=
&
Config
{
Queue
:
fifo
,
ListerWatcher
:
lw
,
ObjectType
:
objType
,
FullResyncPeriod
:
resyncPeriod
,
RetryOnError
:
false
,
Process
:
sharedInformer
.
HandleDeltas
,
}
sharedInformer
.
controller
=
New
(
cfg
)
return
sharedInformer
return
sharedInformer
}
}
//
/
NewSharedIndexInformer creates a new instance for the listwatcher.
// NewSharedIndexInformer creates a new instance for the listwatcher.
// TODO: create a cache/factory of these at a higher level for the list all, watch all of a given resource that can
// TODO: create a cache/factory of these at a higher level for the list all, watch all of a given resource that can
// be shared amongst all consumers.
// be shared amongst all consumers.
func
NewSharedIndexInformer
(
lw
cache
.
ListerWatcher
,
objType
runtime
.
Object
,
resyncPeriod
time
.
Duration
,
indexers
cache
.
Indexers
)
SharedIndexInformer
{
func
NewSharedIndexInformer
(
lw
cache
.
ListerWatcher
,
objType
runtime
.
Object
,
resyncPeriod
time
.
Duration
,
indexers
cache
.
Indexers
)
SharedIndexInformer
{
sharedIndexInformer
:=
&
sharedIndexInformer
{
sharedIndexInformer
:=
&
sharedIndexInformer
{
processor
:
&
sharedProcessor
{},
processor
:
&
sharedProcessor
{},
indexer
:
cache
.
NewIndexer
(
DeletionHandlingMetaNamespaceKeyFunc
,
indexers
),
indexer
:
cache
.
NewIndexer
(
DeletionHandlingMetaNamespaceKeyFunc
,
indexers
),
}
listerWatcher
:
lw
,
objectType
:
objType
,
fifo
:=
cache
.
NewDeltaFIFO
(
cache
.
MetaNamespaceKeyFunc
,
nil
,
sharedIndexInformer
.
indexer
)
fullResyncPeriod
:
resyncPeriod
,
cfg
:=
&
Config
{
Queue
:
fifo
,
ListerWatcher
:
lw
,
ObjectType
:
objType
,
FullResyncPeriod
:
resyncPeriod
,
RetryOnError
:
false
,
Process
:
sharedIndexInformer
.
HandleDeltas
,
}
}
sharedIndexInformer
.
controller
=
New
(
cfg
)
return
sharedIndexInformer
return
sharedIndexInformer
}
}
...
@@ -108,6 +87,11 @@ type sharedIndexInformer struct {
...
@@ -108,6 +87,11 @@ type sharedIndexInformer struct {
processor
*
sharedProcessor
processor
*
sharedProcessor
// This block is tracked to handle late initialization of the controller
listerWatcher
cache
.
ListerWatcher
objectType
runtime
.
Object
fullResyncPeriod
time
.
Duration
started
bool
started
bool
startedLock
sync
.
Mutex
startedLock
sync
.
Mutex
}
}
...
@@ -144,6 +128,19 @@ type deleteNotification struct {
...
@@ -144,6 +128,19 @@ type deleteNotification struct {
func
(
s
*
sharedIndexInformer
)
Run
(
stopCh
<-
chan
struct
{})
{
func
(
s
*
sharedIndexInformer
)
Run
(
stopCh
<-
chan
struct
{})
{
defer
utilruntime
.
HandleCrash
()
defer
utilruntime
.
HandleCrash
()
fifo
:=
cache
.
NewDeltaFIFO
(
cache
.
MetaNamespaceKeyFunc
,
nil
,
s
.
indexer
)
cfg
:=
&
Config
{
Queue
:
fifo
,
ListerWatcher
:
s
.
listerWatcher
,
ObjectType
:
s
.
objectType
,
FullResyncPeriod
:
s
.
fullResyncPeriod
,
RetryOnError
:
false
,
Process
:
s
.
HandleDeltas
,
}
s
.
controller
=
New
(
cfg
)
func
()
{
func
()
{
s
.
startedLock
.
Lock
()
s
.
startedLock
.
Lock
()
defer
s
.
startedLock
.
Unlock
()
defer
s
.
startedLock
.
Unlock
()
...
@@ -172,9 +169,25 @@ func (s *sharedIndexInformer) GetIndexer() cache.Indexer {
...
@@ -172,9 +169,25 @@ func (s *sharedIndexInformer) GetIndexer() cache.Indexer {
return
s
.
indexer
return
s
.
indexer
}
}
// TODO(mqliang): implement this
func
(
s
*
sharedIndexInformer
)
AddIndexers
(
indexers
cache
.
Indexers
)
error
{
func
(
s
*
sharedIndexInformer
)
AddIndexers
(
indexers
cache
.
Indexers
)
error
{
panic
(
"has not implemeted yet"
)
s
.
startedLock
.
Lock
()
defer
s
.
startedLock
.
Unlock
()
if
s
.
started
{
return
fmt
.
Errorf
(
"informer has already started"
)
}
oldIndexers
:=
s
.
indexer
.
GetIndexers
()
for
name
,
indexFunc
:=
range
oldIndexers
{
if
_
,
exist
:=
indexers
[
name
];
exist
{
return
fmt
.
Errorf
(
"there is an index named %s already exist"
,
name
)
}
indexers
[
name
]
=
indexFunc
}
s
.
indexer
=
cache
.
NewIndexer
(
DeletionHandlingMetaNamespaceKeyFunc
,
indexers
)
return
nil
}
}
func
(
s
*
sharedIndexInformer
)
GetController
()
ControllerInterface
{
func
(
s
*
sharedIndexInformer
)
GetController
()
ControllerInterface
{
...
...
pkg/controller/gc/gc_controller.go
View file @
c10f43a2
...
@@ -77,8 +77,10 @@ func New(kubeClient clientset.Interface, resyncPeriod controller.ResyncPeriodFun
...
@@ -77,8 +77,10 @@ func New(kubeClient clientset.Interface, resyncPeriod controller.ResyncPeriodFun
&
api
.
Pod
{},
&
api
.
Pod
{},
resyncPeriod
(),
resyncPeriod
(),
framework
.
ResourceEventHandlerFuncs
{},
framework
.
ResourceEventHandlerFuncs
{},
// We don't need to build a index for podStore here
// We don't need to build a index for podStore here actually, but build one for consistency.
cache
.
Indexers
{},
// It will ensure that if people start making use of the podStore in more specific ways,
// they'll get the benefits they expect. It will also reserve the name for future refactorings.
cache
.
Indexers
{
cache
.
NamespaceIndex
:
cache
.
MetaNamespaceIndexFunc
},
)
)
return
gcc
return
gcc
}
}
...
...
pkg/controller/job/controller.go
View file @
c10f43a2
...
@@ -135,7 +135,7 @@ func NewJobController(podInformer framework.SharedIndexInformer, kubeClient clie
...
@@ -135,7 +135,7 @@ func NewJobController(podInformer framework.SharedIndexInformer, kubeClient clie
}
}
func
NewJobControllerFromClient
(
kubeClient
clientset
.
Interface
,
resyncPeriod
controller
.
ResyncPeriodFunc
)
*
JobController
{
func
NewJobControllerFromClient
(
kubeClient
clientset
.
Interface
,
resyncPeriod
controller
.
ResyncPeriodFunc
)
*
JobController
{
podInformer
:=
informers
.
CreateShared
IndexPodInformer
(
kubeClient
,
resyncPeriod
(),
cache
.
Indexers
{
cache
.
NamespaceIndex
:
cache
.
MetaNamespaceIndexFunc
}
)
podInformer
:=
informers
.
CreateShared
PodIndexInformer
(
kubeClient
,
resyncPeriod
()
)
jm
:=
NewJobController
(
podInformer
,
kubeClient
)
jm
:=
NewJobController
(
podInformer
,
kubeClient
)
jm
.
internalPodInformer
=
podInformer
jm
.
internalPodInformer
=
podInformer
...
...
pkg/controller/node/nodecontroller.go
View file @
c10f43a2
...
@@ -193,8 +193,10 @@ func NewNodeController(
...
@@ -193,8 +193,10 @@ func NewNodeController(
AddFunc
:
nc
.
maybeDeleteTerminatingPod
,
AddFunc
:
nc
.
maybeDeleteTerminatingPod
,
UpdateFunc
:
func
(
_
,
obj
interface
{})
{
nc
.
maybeDeleteTerminatingPod
(
obj
)
},
UpdateFunc
:
func
(
_
,
obj
interface
{})
{
nc
.
maybeDeleteTerminatingPod
(
obj
)
},
},
},
// We don't need to build a index for podStore here
// We don't need to build a index for podStore here actually, but build one for consistency.
cache
.
Indexers
{},
// It will ensure that if people start making use of the podStore in more specific ways,
// they'll get the benefits they expect. It will also reserve the name for future refactorings.
cache
.
Indexers
{
cache
.
NamespaceIndex
:
cache
.
MetaNamespaceIndexFunc
},
)
)
nc
.
nodeStore
.
Store
,
nc
.
nodeController
=
framework
.
NewInformer
(
nc
.
nodeStore
.
Store
,
nc
.
nodeController
=
framework
.
NewInformer
(
&
cache
.
ListWatch
{
&
cache
.
ListWatch
{
...
...
pkg/controller/petset/pet_set.go
View file @
c10f43a2
...
@@ -81,7 +81,7 @@ type PetSetController struct {
...
@@ -81,7 +81,7 @@ type PetSetController struct {
}
}
// NewPetSetController creates a new petset controller.
// NewPetSetController creates a new petset controller.
func
NewPetSetController
(
podInformer
framework
.
SharedInformer
,
kubeClient
*
client
.
Client
,
resyncPeriod
time
.
Duration
)
*
PetSetController
{
func
NewPetSetController
(
podInformer
framework
.
SharedIn
dexIn
former
,
kubeClient
*
client
.
Client
,
resyncPeriod
time
.
Duration
)
*
PetSetController
{
eventBroadcaster
:=
record
.
NewBroadcaster
()
eventBroadcaster
:=
record
.
NewBroadcaster
()
eventBroadcaster
.
StartLogging
(
glog
.
Infof
)
eventBroadcaster
.
StartLogging
(
glog
.
Infof
)
eventBroadcaster
.
StartRecordingToSink
(
kubeClient
.
Events
(
""
))
eventBroadcaster
.
StartRecordingToSink
(
kubeClient
.
Events
(
""
))
...
@@ -105,7 +105,7 @@ func NewPetSetController(podInformer framework.SharedInformer, kubeClient *clien
...
@@ -105,7 +105,7 @@ func NewPetSetController(podInformer framework.SharedInformer, kubeClient *clien
// lookup petset accounting for deletion tombstones
// lookup petset accounting for deletion tombstones
DeleteFunc
:
psc
.
deletePod
,
DeleteFunc
:
psc
.
deletePod
,
})
})
psc
.
podStore
.
Store
=
podInformer
.
GetStore
()
psc
.
podStore
.
Indexer
=
podInformer
.
GetIndexer
()
psc
.
podController
=
podInformer
.
GetController
()
psc
.
podController
=
podInformer
.
GetController
()
psc
.
psStore
.
Store
,
psc
.
psController
=
framework
.
NewInformer
(
psc
.
psStore
.
Store
,
psc
.
psController
=
framework
.
NewInformer
(
...
...
pkg/controller/petset/pet_set_test.go
View file @
c10f43a2
...
@@ -35,7 +35,7 @@ func newFakePetSetController() (*PetSetController, *fakePetClient) {
...
@@ -35,7 +35,7 @@ func newFakePetSetController() (*PetSetController, *fakePetClient) {
blockingPetStore
:
newUnHealthyPetTracker
(
fpc
),
blockingPetStore
:
newUnHealthyPetTracker
(
fpc
),
podStoreSynced
:
func
()
bool
{
return
true
},
podStoreSynced
:
func
()
bool
{
return
true
},
psStore
:
cache
.
StoreToPetSetLister
{
Store
:
cache
.
NewStore
(
controller
.
KeyFunc
)},
psStore
:
cache
.
StoreToPetSetLister
{
Store
:
cache
.
NewStore
(
controller
.
KeyFunc
)},
podStore
:
cache
.
StoreToPodLister
{
Store
:
cache
.
NewStore
(
controller
.
KeyFunc
)},
podStore
:
cache
.
StoreToPodLister
{
Indexer
:
cache
.
NewIndexer
(
controller
.
KeyFunc
,
cache
.
Indexers
{}
)},
newSyncer
:
func
(
blockingPet
*
pcb
)
*
petSyncer
{
newSyncer
:
func
(
blockingPet
*
pcb
)
*
petSyncer
{
return
&
petSyncer
{
fpc
,
blockingPet
}
return
&
petSyncer
{
fpc
,
blockingPet
}
},
},
...
...
pkg/controller/replication/replication_controller.go
View file @
c10f43a2
...
@@ -200,7 +200,7 @@ func NewReplicationManager(podInformer framework.SharedIndexInformer, kubeClient
...
@@ -200,7 +200,7 @@ func NewReplicationManager(podInformer framework.SharedIndexInformer, kubeClient
// NewReplicationManagerFromClient creates a new ReplicationManager that runs its own informer.
// NewReplicationManagerFromClient creates a new ReplicationManager that runs its own informer.
func
NewReplicationManagerFromClient
(
kubeClient
clientset
.
Interface
,
resyncPeriod
controller
.
ResyncPeriodFunc
,
burstReplicas
int
,
lookupCacheSize
int
)
*
ReplicationManager
{
func
NewReplicationManagerFromClient
(
kubeClient
clientset
.
Interface
,
resyncPeriod
controller
.
ResyncPeriodFunc
,
burstReplicas
int
,
lookupCacheSize
int
)
*
ReplicationManager
{
podInformer
:=
informers
.
CreateShared
IndexPodInformer
(
kubeClient
,
resyncPeriod
(),
cache
.
Indexers
{
cache
.
NamespaceIndex
:
cache
.
MetaNamespaceIndexFunc
}
)
podInformer
:=
informers
.
CreateShared
PodIndexInformer
(
kubeClient
,
resyncPeriod
()
)
rm
:=
NewReplicationManager
(
podInformer
,
kubeClient
,
resyncPeriod
,
burstReplicas
,
lookupCacheSize
)
rm
:=
NewReplicationManager
(
podInformer
,
kubeClient
,
resyncPeriod
,
burstReplicas
,
lookupCacheSize
)
rm
.
internalPodInformer
=
podInformer
rm
.
internalPodInformer
=
podInformer
...
...
pkg/controller/replication/replication_controller_test.go
View file @
c10f43a2
...
@@ -231,7 +231,7 @@ func TestStatusUpdatesWithoutReplicasChange(t *testing.T) {
...
@@ -231,7 +231,7 @@ func TestStatusUpdatesWithoutReplicasChange(t *testing.T) {
activePods
:=
5
activePods
:=
5
rc
:=
newReplicationController
(
activePods
)
rc
:=
newReplicationController
(
activePods
)
manager
.
rcStore
.
Indexer
.
Add
(
rc
)
manager
.
rcStore
.
Indexer
.
Add
(
rc
)
rc
.
Status
=
api
.
ReplicationControllerStatus
{
Replicas
:
activePods
}
rc
.
Status
=
api
.
ReplicationControllerStatus
{
Replicas
:
int32
(
activePods
)
}
newPodList
(
manager
.
podStore
.
Indexer
,
activePods
,
api
.
PodRunning
,
rc
,
"pod"
)
newPodList
(
manager
.
podStore
.
Indexer
,
activePods
,
api
.
PodRunning
,
rc
,
"pod"
)
fakePodControl
:=
controller
.
FakePodControl
{}
fakePodControl
:=
controller
.
FakePodControl
{}
...
@@ -1015,7 +1015,6 @@ func TestDeletionTimestamp(t *testing.T) {
...
@@ -1015,7 +1015,6 @@ func TestDeletionTimestamp(t *testing.T) {
}
}
}
}
/*
func
BenchmarkGetPodControllerMultiNS
(
b
*
testing
.
B
)
{
func
BenchmarkGetPodControllerMultiNS
(
b
*
testing
.
B
)
{
client
:=
clientset
.
NewForConfigOrDie
(
&
restclient
.
Config
{
Host
:
""
,
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
testapi
.
Default
.
GroupVersion
()}})
client
:=
clientset
.
NewForConfigOrDie
(
&
restclient
.
Config
{
Host
:
""
,
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
testapi
.
Default
.
GroupVersion
()}})
manager
:=
NewReplicationManagerFromClient
(
client
,
controller
.
NoResyncPeriodFunc
,
BurstReplicas
,
0
)
manager
:=
NewReplicationManagerFromClient
(
client
,
controller
.
NoResyncPeriodFunc
,
BurstReplicas
,
0
)
...
@@ -1101,4 +1100,3 @@ func BenchmarkGetPodControllerSingleNS(b *testing.B) {
...
@@ -1101,4 +1100,3 @@ func BenchmarkGetPodControllerSingleNS(b *testing.B) {
}
}
}
}
}
}
*/
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