@@ -29,13 +29,6 @@ import (
29
29
"github.com/karmada-io/karmada/pkg/util/fedinformer/genericmanager"
30
30
)
31
31
32
- // EvictionWorker enhances AsyncWorker with dynamic rate limiting and metrics
33
- // for eviction operations. It provides a queue that adjusts its processing rate
34
- // based on cluster health status.
35
- type EvictionWorker interface {
36
- util.AsyncWorker
37
- }
38
-
39
32
// EvictionQueueOptions holds the options that control the behavior of the graceful eviction queue based on the overall health of the clusters.
40
33
type EvictionQueueOptions struct {
41
34
// ResourceEvictionRate is the number of resources to be evicted per second.
@@ -55,7 +48,7 @@ type EvictionQueueOptions struct {
55
48
LargeClusterNumThreshold int
56
49
}
57
50
58
- type evictionWorker struct {
51
+ type EvictionWorker struct {
59
52
name string
60
53
keyFunc util.KeyFunc
61
54
reconcileFunc util.ReconcileFunc
@@ -95,7 +88,7 @@ func NewEvictionWorker(opts EvictionWorkerOptions) EvictionWorker {
95
88
opts .RateLimiterOptions ,
96
89
)
97
90
98
- return & evictionWorker {
91
+ return EvictionWorker {
99
92
name : opts .Name ,
100
93
keyFunc : opts .KeyFunc ,
101
94
reconcileFunc : opts .ReconcileFunc ,
@@ -107,7 +100,7 @@ func NewEvictionWorker(opts EvictionWorkerOptions) EvictionWorker {
107
100
}
108
101
109
102
// Enqueue converts an object to a key and adds it to the queue.
110
- func (w * evictionWorker ) Enqueue (obj interface {}) {
103
+ func (w * EvictionWorker ) Enqueue (obj interface {}) {
111
104
key , err := w .keyFunc (obj )
112
105
if err != nil {
113
106
klog .Errorf ("Failed to generate key for obj: %+v, err: %v" , obj , err )
@@ -122,7 +115,7 @@ func (w *evictionWorker) Enqueue(obj interface{}) {
122
115
}
123
116
124
117
// Add puts an item into the queue and updates metrics.
125
- func (w * evictionWorker ) Add (item interface {}) {
118
+ func (w * EvictionWorker ) Add (item interface {}) {
126
119
if item == nil {
127
120
klog .Warningf ("Ignore nil item from queue" )
128
121
return
@@ -139,7 +132,7 @@ func (w *evictionWorker) Add(item interface{}) {
139
132
}
140
133
141
134
// AddAfter adds an item to the queue after a delay and updates metrics.
142
- func (w * evictionWorker ) AddAfter (item interface {}, duration time.Duration ) {
135
+ func (w * EvictionWorker ) AddAfter (item interface {}, duration time.Duration ) {
143
136
if item == nil {
144
137
klog .Warningf ("Ignore nil item from queue" )
145
138
return
@@ -156,14 +149,14 @@ func (w *evictionWorker) AddAfter(item interface{}, duration time.Duration) {
156
149
}
157
150
158
151
// worker processes items from the queue until the context is canceled.
159
- func (w * evictionWorker ) worker (ctx context.Context ) {
152
+ func (w * EvictionWorker ) worker (ctx context.Context ) {
160
153
for w .processNextWorkItem (ctx ) {
161
154
}
162
155
}
163
156
164
157
// processNextWorkItem handles a single item from the queue with metrics tracking.
165
158
// Returns false when the queue is shutting down, true otherwise.
166
- func (w * evictionWorker ) processNextWorkItem (_ context.Context ) bool {
159
+ func (w * EvictionWorker ) processNextWorkItem (_ context.Context ) bool {
167
160
key , quit := w .queue .Get ()
168
161
if quit {
169
162
return false
@@ -201,7 +194,7 @@ func (w *evictionWorker) processNextWorkItem(_ context.Context) bool {
201
194
}
202
195
203
196
// Run starts worker goroutines and ensures cleanup when context is canceled.
204
- func (w * evictionWorker ) Run (ctx context.Context , workerNumber int ) {
197
+ func (w * EvictionWorker ) Run (ctx context.Context , workerNumber int ) {
205
198
klog .Infof ("Starting %d workers for eviction worker %s" , workerNumber , w .name )
206
199
for i := 0 ; i < workerNumber ; i ++ {
207
200
go w .worker (ctx )
0 commit comments