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
fba3c54b
Unverified
Commit
fba3c54b
authored
Feb 22, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
Feb 22, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #70803 from Adirio/controller-cleanup
Remove duplicate code in client-go/tools/cache/controller.go
parents
780192ac
b09c1ce5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
40 deletions
+26
-40
controller.go
staging/src/k8s.io/client-go/tools/cache/controller.go
+26
-40
No files found.
staging/src/k8s.io/client-go/tools/cache/controller.go
View file @
fba3c54b
...
...
@@ -285,45 +285,7 @@ func NewInformer(
// This will hold the client state, as we know it.
clientState
:=
NewStore
(
DeletionHandlingMetaNamespaceKeyFunc
)
// This will hold incoming changes. Note how we pass clientState in as a
// KeyLister, that way resync operations will result in the correct set
// of update/delete deltas.
fifo
:=
NewDeltaFIFO
(
MetaNamespaceKeyFunc
,
clientState
)
cfg
:=
&
Config
{
Queue
:
fifo
,
ListerWatcher
:
lw
,
ObjectType
:
objType
,
FullResyncPeriod
:
resyncPeriod
,
RetryOnError
:
false
,
Process
:
func
(
obj
interface
{})
error
{
// from oldest to newest
for
_
,
d
:=
range
obj
.
(
Deltas
)
{
switch
d
.
Type
{
case
Sync
,
Added
,
Updated
:
if
old
,
exists
,
err
:=
clientState
.
Get
(
d
.
Object
);
err
==
nil
&&
exists
{
if
err
:=
clientState
.
Update
(
d
.
Object
);
err
!=
nil
{
return
err
}
h
.
OnUpdate
(
old
,
d
.
Object
)
}
else
{
if
err
:=
clientState
.
Add
(
d
.
Object
);
err
!=
nil
{
return
err
}
h
.
OnAdd
(
d
.
Object
)
}
case
Deleted
:
if
err
:=
clientState
.
Delete
(
d
.
Object
);
err
!=
nil
{
return
err
}
h
.
OnDelete
(
d
.
Object
)
}
}
return
nil
},
}
return
clientState
,
New
(
cfg
)
return
clientState
,
newInformer
(
lw
,
objType
,
resyncPeriod
,
h
,
clientState
)
}
// NewIndexerInformer returns a Indexer and a controller for populating the index
...
...
@@ -352,6 +314,30 @@ func NewIndexerInformer(
// This will hold the client state, as we know it.
clientState
:=
NewIndexer
(
DeletionHandlingMetaNamespaceKeyFunc
,
indexers
)
return
clientState
,
newInformer
(
lw
,
objType
,
resyncPeriod
,
h
,
clientState
)
}
// newInformer returns a controller for populating the store while also
// providing event notifications.
//
// Parameters
// * lw is list and watch functions for the source of the resource you want to
// be informed of.
// * objType is an object of the type that you expect to receive.
// * resyncPeriod: if non-zero, will re-list this often (you will get OnUpdate
// calls, even if nothing changed). Otherwise, re-list will be delayed as
// long as possible (until the upstream source closes the watch or times out,
// or you stop the controller).
// * h is the object you want notifications sent to.
// * clientState is the store you want to populate
//
func
newInformer
(
lw
ListerWatcher
,
objType
runtime
.
Object
,
resyncPeriod
time
.
Duration
,
h
ResourceEventHandler
,
clientState
Store
,
)
Controller
{
// This will hold incoming changes. Note how we pass clientState in as a
// KeyLister, that way resync operations will result in the correct set
// of update/delete deltas.
...
...
@@ -390,5 +376,5 @@ func NewIndexerInformer(
return
nil
},
}
return
clientState
,
New
(
cfg
)
return
New
(
cfg
)
}
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