forked from kubeedge/kubeedge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
endpoint.go
34 lines (28 loc) · 1.08 KB
/
endpoint.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
package manager
import (
"github.com/kubeedge/kubeedge/cloud/pkg/controller/config"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/cache"
)
// EndpointsManager manage all events of endpoints by SharedInformer
type EndpointsManager struct {
events chan watch.Event
}
// Events return the channel save events from watch endpoints change
func (sm *EndpointsManager) Events() chan watch.Event {
return sm.events
}
// NewEndpointsManager create EndpointsManager by kube clientset and namespace
func NewEndpointsManager(kubeClient *kubernetes.Clientset, namespace string) (*EndpointsManager, error) {
lw := cache.NewListWatchFromClient(kubeClient.CoreV1().RESTClient(), "endpoints", namespace, fields.Everything())
events := make(chan watch.Event, config.EndpointsEventBuffer)
rh := NewCommonResourceEventHandler(events)
si := cache.NewSharedInformer(lw, &v1.Endpoints{}, 0)
si.AddEventHandler(rh)
stopNever := make(chan struct{})
go si.Run(stopNever)
return &EndpointsManager{events: events}, nil
}