@@ -38,6 +38,13 @@ type ReconcileWorker interface {
38
38
SetDelay (retryDelay , clusterSyncDelay time.Duration )
39
39
}
40
40
41
+ type WorkerOptions struct {
42
+ WorkerTiming
43
+
44
+ // MaxConcurrentReconciles is the maximum number of concurrent Reconciles which can be run. Defaults to 1.
45
+ MaxConcurrentReconciles int
46
+ }
47
+
41
48
type WorkerTiming struct {
42
49
Interval time.Duration
43
50
RetryDelay time.Duration
@@ -53,6 +60,8 @@ type asyncWorker struct {
53
60
54
61
timing WorkerTiming
55
62
63
+ maxConcurrentReconciles int
64
+
56
65
// For triggering reconciliation of a single resource. This is
57
66
// used when there is an add/update/delete operation on a resource
58
67
// in either the API of the cluster hosting KubeFed or in the API
@@ -66,26 +75,30 @@ type asyncWorker struct {
66
75
backoff * flowcontrol.Backoff
67
76
}
68
77
69
- func NewReconcileWorker (name string , reconcile ReconcileFunc , timing WorkerTiming ) ReconcileWorker {
70
- if timing .Interval == 0 {
71
- timing .Interval = time .Second * 1
78
+ func NewReconcileWorker (name string , reconcile ReconcileFunc , options WorkerOptions ) ReconcileWorker {
79
+ if options .Interval == 0 {
80
+ options .Interval = time .Second * 1
72
81
}
73
- if timing .RetryDelay == 0 {
74
- timing .RetryDelay = time .Second * 10
82
+ if options .RetryDelay == 0 {
83
+ options .RetryDelay = time .Second * 10
75
84
}
76
- if timing .InitialBackoff == 0 {
77
- timing .InitialBackoff = time .Second * 5
85
+ if options .InitialBackoff == 0 {
86
+ options .InitialBackoff = time .Second * 5
78
87
}
79
- if timing .MaxBackoff == 0 {
80
- timing .MaxBackoff = time .Minute
88
+ if options .MaxBackoff == 0 {
89
+ options .MaxBackoff = time .Minute
90
+ }
91
+ if options .MaxConcurrentReconciles == 0 {
92
+ options .MaxConcurrentReconciles = 1
81
93
}
82
94
return & asyncWorker {
83
- name : name ,
84
- reconcile : reconcile ,
85
- timing : timing ,
86
- deliverer : NewDelayingDeliverer (),
87
- queue : workqueue .NewNamed (name ),
88
- backoff : flowcontrol .NewBackOff (timing .InitialBackoff , timing .MaxBackoff ),
95
+ name : name ,
96
+ reconcile : reconcile ,
97
+ timing : options .WorkerTiming ,
98
+ maxConcurrentReconciles : options .MaxConcurrentReconciles ,
99
+ deliverer : NewDelayingDeliverer (),
100
+ queue : workqueue .NewNamed (name ),
101
+ backoff : flowcontrol .NewBackOff (options .InitialBackoff , options .MaxBackoff ),
89
102
}
90
103
}
91
104
@@ -122,7 +135,10 @@ func (w *asyncWorker) Run(stopChan <-chan struct{}) {
122
135
w .queue .Add (* qualifiedName )
123
136
}
124
137
})
125
- go wait .Until (w .worker , w .timing .Interval , stopChan )
138
+
139
+ for i := 0 ; i < w .maxConcurrentReconciles ; i ++ {
140
+ go wait .Until (w .worker , w .timing .Interval , stopChan )
141
+ }
126
142
127
143
// Ensure all goroutines are cleaned up when the stop channel closes
128
144
go func () {
0 commit comments