Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Clutch
Commits
b2b4a2ea
Commit
b2b4a2ea
authored
4 years ago
by
Mike Cutalo
Browse files
Options
Download
Email Patches
Plain Diff
cachelessinfromer
parent
49559167
k8s-cachelessinformer
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
backend/service/k8s/cache.go
+7
-37
backend/service/k8s/cache.go
backend/service/k8s/cachelessinformer.go
+41
-0
backend/service/k8s/cachelessinformer.go
with
48 additions
and
37 deletions
+48
-37
backend/service/k8s/cache.go
+
7
-
37
View file @
b2b4a2ea
...
...
@@ -52,67 +52,37 @@ func (s *svc) StartTopologyCaching(ctx context.Context) (<-chan *topologyv1.Upda
}
func
(
s
*
svc
)
startInformers
(
ctx
context
.
Context
,
cs
ContextClientset
)
{
// factory := informers.NewSharedInformerFactoryWithOptions(cs, informerResyncTime)
stop
:=
make
(
chan
struct
{})
// podInformer := factory.Core().V1().Pods().Informer()
// deploymentInformer := factory.Apps().V1().Deployments().Informer()
// hpaInformer := factory.Autoscaling().V1().HorizontalPodAutoscalers().Informer()
informerHandlers
:=
cache
.
ResourceEventHandlerFuncs
{
AddFunc
:
s
.
informerAddHandler
,
UpdateFunc
:
s
.
informerUpdateHandler
,
DeleteFunc
:
s
.
informerDeleteHandler
,
}
// podInformer.AddEventHandler(informerHandlers)
// deploymentInformer.AddEventHandler(informerHandlers)
// hpaInformer.AddEventHandler(informerHandlers)
// _, podInformer := cache.NewInformer(
// cache.NewListWatchFromClient(cs.CoreV1().RESTClient(), "pods", v1.NamespaceAll, fields.Everything()),
// &v1.Pod{},
// informerResyncTime,
// informerHandlers,
// )
// _, deploymentInformer := cache.NewInformer(
// cache.NewListWatchFromClient(cs.AppsV1().RESTClient(), "deployments", v1.NamespaceAll, fields.Everything()),
// &appsv1.Deployment{},
// informerResyncTime,
// informerHandlers,
// )
// _, hpaInformer := cache.NewInformer(
// cache.NewListWatchFromClient(cs.AutoscalingV1().RESTClient(), "horizontalpodautoscalers", v1.NamespaceAll, fields.Everything()),
// &autoscalingv1.HorizontalPodAutoscaler{},
// informerResyncTime,
// informerHandlers,
// )
_
,
podInformer
:=
cache
.
NewIndexerInformer
(
podInformer
:=
NewCachelessInformer
(
cs
,
cache
.
NewListWatchFromClient
(
cs
.
CoreV1
()
.
RESTClient
(),
"pods"
,
v1
.
NamespaceAll
,
fields
.
Everything
()),
&
v1
.
Pod
{},
informerResyncTime
,
informerHandlers
,
cache
.
Indexers
{},
)
_
,
deploymentInformer
:=
cache
.
NewIndexerInformer
(
deploymentInformer
:=
NewCachelessInformer
(
cs
,
cache
.
NewListWatchFromClient
(
cs
.
AppsV1
()
.
RESTClient
(),
"deployments"
,
v1
.
NamespaceAll
,
fields
.
Everything
()),
&
appsv1
.
Deployment
{},
informerResyncTime
,
informerHandlers
,
cache
.
Indexers
{},
)
_
,
hpaInformer
:=
cache
.
NewIndexerInformer
(
hpaInformer
:=
NewCachelessInformer
(
cs
,
cache
.
NewListWatchFromClient
(
cs
.
AutoscalingV1
()
.
RESTClient
(),
"horizontalpodautoscalers"
,
v1
.
NamespaceAll
,
fields
.
Everything
()),
&
autoscalingv1
.
HorizontalPodAutoscaler
{},
informerResyncTime
,
informerHandlers
,
cache
.
Indexers
{},
)
stop
:=
make
(
chan
struct
{})
go
podInformer
.
Run
(
stop
)
go
deploymentInformer
.
Run
(
stop
)
go
hpaInformer
.
Run
(
stop
)
...
...
This diff is collapsed.
Click to expand it.
backend/service/k8s/cachelessinformer.go
0 → 100644
+
41
-
0
View file @
b2b4a2ea
package
k8s
import
(
"time"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/cache"
)
func
NewCachelessInformer
(
cs
ContextClientset
,
lw
cache
.
ListerWatcher
,
objType
runtime
.
Object
,
resync
time
.
Duration
,
h
cache
.
ResourceEventHandler
,
)
cache
.
Controller
{
fifo
:=
cache
.
NewDeltaFIFOWithOptions
(
cache
.
DeltaFIFOOptions
{
// just to satisify the interface were not going to use this
KnownObjects
:
cache
.
NewIndexer
(
cache
.
DeletionHandlingMetaNamespaceKeyFunc
,
cache
.
Indexers
{}),
EmitDeltaTypeReplaced
:
true
,
})
return
cache
.
New
(
&
cache
.
Config
{
Queue
:
fifo
,
ListerWatcher
:
lw
,
ObjectType
:
objType
,
FullResyncPeriod
:
resync
,
RetryOnError
:
false
,
Process
:
func
(
obj
interface
{})
error
{
for
_
,
d
:=
range
obj
.
(
cache
.
Deltas
)
{
switch
d
.
Type
{
case
cache
.
Sync
,
cache
.
Replaced
,
cache
.
Added
,
cache
.
Updated
:
h
.
OnAdd
(
d
.
Object
)
case
cache
.
Deleted
:
h
.
OnDelete
(
d
.
Object
)
}
}
return
nil
},
})
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
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
Menu
Projects
Groups
Snippets
Help