Skip to content

Commit f433fbb

Browse files
committed
remove evictionworker interface
Signed-off-by: whosefriendA <[email protected]>
1 parent 0e0806d commit f433fbb

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

pkg/controllers/cluster/eviction_worker.go

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,6 @@ import (
2929
"github.com/karmada-io/karmada/pkg/util/fedinformer/genericmanager"
3030
)
3131

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-
3932
// EvictionQueueOptions holds the options that control the behavior of the graceful eviction queue based on the overall health of the clusters.
4033
type EvictionQueueOptions struct {
4134
// ResourceEvictionRate is the number of resources to be evicted per second.
@@ -55,7 +48,7 @@ type EvictionQueueOptions struct {
5548
LargeClusterNumThreshold int
5649
}
5750

58-
type evictionWorker struct {
51+
type EvictionWorker struct {
5952
name string
6053
keyFunc util.KeyFunc
6154
reconcileFunc util.ReconcileFunc
@@ -95,7 +88,7 @@ func NewEvictionWorker(opts EvictionWorkerOptions) EvictionWorker {
9588
opts.RateLimiterOptions,
9689
)
9790

98-
return &evictionWorker{
91+
return EvictionWorker{
9992
name: opts.Name,
10093
keyFunc: opts.KeyFunc,
10194
reconcileFunc: opts.ReconcileFunc,
@@ -107,7 +100,7 @@ func NewEvictionWorker(opts EvictionWorkerOptions) EvictionWorker {
107100
}
108101

109102
// 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{}) {
111104
key, err := w.keyFunc(obj)
112105
if err != nil {
113106
klog.Errorf("Failed to generate key for obj: %+v, err: %v", obj, err)
@@ -122,7 +115,7 @@ func (w *evictionWorker) Enqueue(obj interface{}) {
122115
}
123116

124117
// Add puts an item into the queue and updates metrics.
125-
func (w *evictionWorker) Add(item interface{}) {
118+
func (w *EvictionWorker) Add(item interface{}) {
126119
if item == nil {
127120
klog.Warningf("Ignore nil item from queue")
128121
return
@@ -139,7 +132,7 @@ func (w *evictionWorker) Add(item interface{}) {
139132
}
140133

141134
// 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) {
143136
if item == nil {
144137
klog.Warningf("Ignore nil item from queue")
145138
return
@@ -156,14 +149,14 @@ func (w *evictionWorker) AddAfter(item interface{}, duration time.Duration) {
156149
}
157150

158151
// 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) {
160153
for w.processNextWorkItem(ctx) {
161154
}
162155
}
163156

164157
// processNextWorkItem handles a single item from the queue with metrics tracking.
165158
// 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 {
167160
key, quit := w.queue.Get()
168161
if quit {
169162
return false
@@ -201,7 +194,7 @@ func (w *evictionWorker) processNextWorkItem(_ context.Context) bool {
201194
}
202195

203196
// 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) {
205198
klog.Infof("Starting %d workers for eviction worker %s", workerNumber, w.name)
206199
for i := 0; i < workerNumber; i++ {
207200
go w.worker(ctx)

pkg/controllers/cluster/eviction_worker_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131

3232
func TestEvictionWorker_Add_Enqueue_AddAfter(t *testing.T) {
3333
var added atomic.Int32
34-
w := &evictionWorker{
34+
w := &EvictionWorker{
3535
name: "test-queue",
3636
keyFunc: util.KeyFunc(func(obj interface{}) (util.QueueKey, error) { return obj, nil }),
3737
reconcileFunc: util.ReconcileFunc(func(_ util.QueueKey) error { added.Add(1); return nil }),
@@ -65,7 +65,7 @@ func TestEvictionWorker_Add_Enqueue_AddAfter(t *testing.T) {
6565

6666
func TestEvictionWorker_Reconcile_Error_Requeues(t *testing.T) {
6767
var attempts atomic.Int32
68-
w := &evictionWorker{
68+
w := &EvictionWorker{
6969
name: "err-queue",
7070
keyFunc: util.KeyFunc(func(obj interface{}) (util.QueueKey, error) { return obj, nil }),
7171
reconcileFunc: util.ReconcileFunc(func(_ util.QueueKey) error {
@@ -98,7 +98,7 @@ func TestEvictionWorker_Reconcile_Error_Requeues(t *testing.T) {
9898

9999
func TestEvictionWorker_Run_Shutdown(t *testing.T) {
100100
t.Helper()
101-
w := &evictionWorker{
101+
w := &EvictionWorker{
102102
name: "shutdown-queue",
103103
keyFunc: util.KeyFunc(func(obj interface{}) (util.QueueKey, error) { return obj, nil }),
104104
reconcileFunc: util.ReconcileFunc(func(_ util.QueueKey) error { return nil }),

0 commit comments

Comments
 (0)