@@ -14,28 +14,82 @@ import (
14
14
"k8s.io/client-go/kubernetes"
15
15
"k8s.io/client-go/tools/cache"
16
16
"strings"
17
+ "time"
17
18
)
18
19
19
20
const (
20
21
ConfigMapsNamespace = "nkl"
21
22
ResyncPeriod = 0
22
23
)
23
24
25
+ type WorkQueueSettings struct {
26
+ Name string
27
+ RateLimiterBase time.Duration
28
+ RateLimiterMax time.Duration
29
+ }
30
+
31
+ type HandlerSettings struct {
32
+ RetryCount int
33
+ Threads int
34
+ WorkQueueSettings WorkQueueSettings
35
+ }
36
+
37
+ type WatcherSettings struct {
38
+ NginxIngressNamespace string
39
+ ResyncPeriod time.Duration
40
+ }
41
+
42
+ type SynchronizerSettings struct {
43
+ MaxMillisecondsJitter int
44
+ MinMillisecondsJitter int
45
+ RetryCount int
46
+ Threads int
47
+ WorkQueueSettings WorkQueueSettings
48
+ }
49
+
24
50
type Settings struct {
25
- ctx context.Context
51
+ Context context.Context
26
52
NginxPlusHosts []string
27
- k8sClient * kubernetes.Clientset
53
+ K8sClient * kubernetes.Clientset
28
54
informer cache.SharedInformer
29
55
eventHandlerRegistration cache.ResourceEventHandlerRegistration
56
+
57
+ Handler HandlerSettings
58
+ Synchronizer SynchronizerSettings
59
+ Watcher WatcherSettings
30
60
}
31
61
32
62
func NewSettings (ctx context.Context , k8sClient * kubernetes.Clientset ) (* Settings , error ) {
33
- config := new (Settings )
34
-
35
- config .k8sClient = k8sClient
36
- config .ctx = ctx
63
+ settings := & Settings {
64
+ Context : ctx ,
65
+ K8sClient : k8sClient ,
66
+ Handler : HandlerSettings {
67
+ RetryCount : 5 ,
68
+ Threads : 1 ,
69
+ WorkQueueSettings : WorkQueueSettings {
70
+ RateLimiterBase : time .Second * 2 ,
71
+ RateLimiterMax : time .Second * 60 ,
72
+ Name : "nkl-handler" ,
73
+ },
74
+ },
75
+ Synchronizer : SynchronizerSettings {
76
+ MaxMillisecondsJitter : 750 ,
77
+ MinMillisecondsJitter : 250 ,
78
+ RetryCount : 5 ,
79
+ Threads : 1 ,
80
+ WorkQueueSettings : WorkQueueSettings {
81
+ RateLimiterBase : time .Second * 2 ,
82
+ RateLimiterMax : time .Second * 60 ,
83
+ Name : "nkl-synchronizer" ,
84
+ },
85
+ },
86
+ Watcher : WatcherSettings {
87
+ NginxIngressNamespace : "nginx-ingress" ,
88
+ ResyncPeriod : 0 ,
89
+ },
90
+ }
37
91
38
- return config , nil
92
+ return settings , nil
39
93
}
40
94
41
95
func (s * Settings ) Initialize () error {
@@ -63,14 +117,14 @@ func (s *Settings) Run() {
63
117
64
118
defer utilruntime .HandleCrash ()
65
119
66
- go s .informer .Run (s .ctx .Done ())
120
+ go s .informer .Run (s .Context .Done ())
67
121
68
- <- s .ctx .Done ()
122
+ <- s .Context .Done ()
69
123
}
70
124
71
125
func (s * Settings ) buildInformer () (cache.SharedInformer , error ) {
72
126
options := informers .WithNamespace (ConfigMapsNamespace )
73
- factory := informers .NewSharedInformerFactoryWithOptions (s .k8sClient , ResyncPeriod , options )
127
+ factory := informers .NewSharedInformerFactoryWithOptions (s .K8sClient , ResyncPeriod , options )
74
128
informer := factory .Core ().V1 ().ConfigMaps ().Informer ()
75
129
76
130
return informer , nil
0 commit comments