forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
factory.go
74 lines (61 loc) · 2.49 KB
/
factory.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
package factory
import (
"time"
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
kclient "github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/cache"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
osclient "github.com/openshift/origin/pkg/client"
oscache "github.com/openshift/origin/pkg/client/cache"
routeapi "github.com/openshift/origin/pkg/route/api"
"github.com/openshift/origin/pkg/router"
"github.com/openshift/origin/pkg/router/controller"
)
type RouterControllerFactory struct {
KClient kclient.Interface
OSClient osclient.Interface
}
func (factory *RouterControllerFactory) Create(plugin router.Plugin) *controller.RouterController {
routeEventQueue := oscache.NewEventQueue(cache.MetaNamespaceKeyFunc)
cache.NewReflector(&routeLW{factory.OSClient}, &routeapi.Route{}, routeEventQueue, 2*time.Minute).Run()
endpointsEventQueue := oscache.NewEventQueue(cache.MetaNamespaceKeyFunc)
cache.NewReflector(&endpointsLW{factory.KClient}, &kapi.Endpoints{}, endpointsEventQueue, 2*time.Minute).Run()
return &controller.RouterController{
Plugin: plugin,
NextEndpoints: func() (watch.EventType, *kapi.Endpoints, error) {
eventType, obj, err := endpointsEventQueue.Pop()
if err != nil {
return watch.Error, nil, err
}
return eventType, obj.(*kapi.Endpoints), nil
},
NextRoute: func() (watch.EventType, *routeapi.Route, error) {
eventType, obj, err := routeEventQueue.Pop()
if err != nil {
return watch.Error, nil, err
}
return eventType, obj.(*routeapi.Route), nil
},
}
}
type routeLW struct {
client osclient.Interface
}
func (lw *routeLW) List() (runtime.Object, error) {
return lw.client.Routes(kapi.NamespaceAll).List(labels.Everything(), fields.Everything())
}
func (lw *routeLW) Watch(resourceVersion string) (watch.Interface, error) {
return lw.client.Routes(kapi.NamespaceAll).Watch(labels.Everything(), fields.Everything(), resourceVersion)
}
type endpointsLW struct {
client kclient.Interface
}
func (lw *endpointsLW) List() (runtime.Object, error) {
return lw.client.Endpoints(kapi.NamespaceAll).List(labels.Everything())
}
func (lw *endpointsLW) Watch(resourceVersion string) (watch.Interface, error) {
return lw.client.Endpoints(kapi.NamespaceAll).Watch(labels.Everything(), fields.Everything(), resourceVersion)
}