-
Notifications
You must be signed in to change notification settings - Fork 0
/
factory.go
66 lines (59 loc) · 1.94 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
package controller
import (
"time"
kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/client/cache"
kclient "k8s.io/kubernetes/pkg/client/unversioned"
clientadapter "k8s.io/kubernetes/pkg/client/unversioned/adapters/internalclientset"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util/flowcontrol"
utilruntime "k8s.io/kubernetes/pkg/util/runtime"
"k8s.io/kubernetes/pkg/watch"
osclient "github.com/openshift/origin/pkg/client"
controller "github.com/openshift/origin/pkg/controller"
)
type NamespaceControllerFactory struct {
// Client is an OpenShift client.
Client osclient.Interface
// KubeClient is a Kubernetes client.
KubeClient *kclient.Client
}
// Create creates a NamespaceController.
func (factory *NamespaceControllerFactory) Create() controller.RunnableController {
namespaceLW := &cache.ListWatch{
ListFunc: func(options kapi.ListOptions) (runtime.Object, error) {
return factory.KubeClient.Namespaces().List(options)
},
WatchFunc: func(options kapi.ListOptions) (watch.Interface, error) {
return factory.KubeClient.Namespaces().Watch(options)
},
}
queue := cache.NewResyncableFIFO(cache.MetaNamespaceKeyFunc)
cache.NewReflector(namespaceLW, &kapi.Namespace{}, queue, 1*time.Minute).Run()
namespaceController := &NamespaceController{
Client: factory.Client,
KubeClient: clientadapter.FromUnversionedClient(factory.KubeClient),
}
return &controller.RetryController{
Queue: queue,
RetryManager: controller.NewQueueRetryManager(
queue,
cache.MetaNamespaceKeyFunc,
func(obj interface{}, err error, retries controller.Retry) bool {
utilruntime.HandleError(err)
if _, isFatal := err.(fatalError); isFatal {
return false
}
if retries.Count > 0 {
return false
}
return true
},
flowcontrol.NewTokenBucketRateLimiter(1, 10),
),
Handle: func(obj interface{}) error {
namespace := obj.(*kapi.Namespace)
return namespaceController.Handle(namespace)
},
}
}