-
Notifications
You must be signed in to change notification settings - Fork 5
/
endpoints.go
77 lines (63 loc) · 2.01 KB
/
endpoints.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"reflect"
"github.com/golang/glog"
"k8s.io/client-go/pkg/api"
"k8s.io/client-go/pkg/api/unversioned"
v1 "k8s.io/client-go/pkg/api/v1"
"k8s.io/client-go/pkg/fields"
"k8s.io/client-go/tools/cache"
)
var (
epAPIResource = unversioned.APIResource{Name: "endpoints", Namespaced: true, Kind: "endpoint"}
)
func newEndpointsListWatchController() *lwController {
return &lwController{
stopCh: make(chan struct{}),
}
}
func newEndpointsListWatchControllerForClientset(lbex *lbExController) *lwController {
lwc := newEndpointsListWatchController()
//Setup an informer to call functions when the ListWatch changes
listWatch := cache.NewListWatchFromClient(
lbex.clientset.Core().RESTClient(), "endpoints", api.NamespaceAll, fields.Everything())
eventHandler := cache.ResourceEventHandlerFuncs{
AddFunc: endpointCreatedFunc(lbex),
DeleteFunc: endpointDeletedFunc(lbex),
UpdateFunc: endpointUpdatedFunc(lbex),
}
lbex.endpointStore, lwc.controller = cache.NewInformer(listWatch, &v1.Endpoints{}, resyncPeriod, eventHandler)
return lwc
}
func endpointCreatedFunc(lbex *lbExController) func(obj interface{}) {
return func(obj interface{}) {
if filterObject(obj) {
glog.V(5).Infof("AddFunc: filtering endpoint object")
return
}
glog.V(5).Infof("AddFunc: enqueuing endpoint object")
lbex.endpointsQueue.Enqueue(obj)
}
}
func endpointDeletedFunc(lbex *lbExController) func(obj interface{}) {
return func(obj interface{}) {
if filterObject(obj) {
glog.V(5).Infof("DeleteFunc: filtering endpoint object")
return
}
glog.V(5).Infof("DeleteFunc: enqueuing endpoint object")
lbex.endpointsQueue.Enqueue(obj)
}
}
func endpointUpdatedFunc(lbex *lbExController) func(obj, newObj interface{}) {
return func(obj, newObj interface{}) {
if filterObject(obj) {
glog.V(5).Infof("UpdateFunc: filtering endpoint object")
return
}
if !reflect.DeepEqual(obj, newObj) {
glog.V(5).Infof("UpdateFunc: enqueuing unequal endpoint object")
lbex.endpointsQueue.Enqueue(newObj)
}
}
}