Skip to content

Commit

Permalink
fix descheduler object limiter with multiple profiles
Browse files Browse the repository at this point in the history
Signed-off-by: songtao98 <songtao2603060@gmail.com>
  • Loading branch information
songtao98 committed Sep 5, 2024
1 parent 36cb609 commit 8a0c4bb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
13 changes: 13 additions & 0 deletions pkg/descheduler/controllers/migration/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ type Reconciler struct {
limiterMap map[deschedulerconfig.MigrationLimitObjectType]map[string]*rate.Limiter
limiterCacheMap map[deschedulerconfig.MigrationLimitObjectType]*gocache.Cache
limiterLock sync.Mutex

reconcilerUID types.UID
}

func New(args runtime.Object, handle framework.Handle) (framework.Plugin, error) {
Expand Down Expand Up @@ -136,6 +138,7 @@ func New(args runtime.Object, handle framework.Handle) (framework.Plugin, error)
if err = c.Watch(source.Kind(options.Manager.GetCache(), r.reservationInterpreter.GetReservationType()), &handler.Funcs{}); err != nil {
return nil, err
}
r.reconcilerUID = UUIDGenerateFn()
return r, nil
}

Expand Down Expand Up @@ -242,6 +245,16 @@ func (r *Reconciler) Reconcile(ctx context.Context, request reconcile.Request) (
return reconcile.Result{}, nil
}

// handle the case that the job is created by other reconciler
// NOTE:
// 1. only the PMJs created by MigrationController have annotation AnnotationJobCreatedBy, if a PMJ was created
// manually by users, we should handle it anyway.
// 2. if a PMJ was indeed created by MigrationController but koord-descheduler has restarted(new UUID generated),
// we just ignore it.
if jobUID, ok := job.Annotations[AnnotationJobCreatedBy]; ok && jobUID != string(r.reconcilerUID) {
return reconcile.Result{}, nil
}

result, err := r.doMigrate(ctx, job)
if err != nil {
klog.Errorf("Failed to reconcile MigrationJob %v, err: %v", request.NamespacedName, err)
Expand Down
10 changes: 8 additions & 2 deletions pkg/descheduler/controllers/migration/evict.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand All @@ -30,6 +31,10 @@ import (
"github.com/koordinator-sh/koordinator/pkg/descheduler/framework"
)

const (
AnnotationJobCreatedBy = "koordinator.sh/job-created-by"
)

// Evict evicts a pod
func (r *Reconciler) Evict(ctx context.Context, pod *corev1.Pod, evictOptions framework.EvictOptions) bool {
framework.FillEvictOptionsFromContext(ctx, &evictOptions)
Expand All @@ -49,11 +54,11 @@ func (r *Reconciler) Evict(ctx context.Context, pod *corev1.Pod, evictOptions fr
return false
}

err := CreatePodMigrationJob(ctx, pod, evictOptions, r.Client, r.args)
err := CreatePodMigrationJob(ctx, pod, evictOptions, r.Client, r.args, r.reconcilerUID)
return err == nil
}

func CreatePodMigrationJob(ctx context.Context, pod *corev1.Pod, evictOptions framework.EvictOptions, client client.Client, args *deschedulerconfig.MigrationControllerArgs) error {
func CreatePodMigrationJob(ctx context.Context, pod *corev1.Pod, evictOptions framework.EvictOptions, client client.Client, args *deschedulerconfig.MigrationControllerArgs, reconcilerUID types.UID) error {
if evictOptions.DeleteOptions == nil {
evictOptions.DeleteOptions = args.DefaultDeleteOptions
}
Expand All @@ -63,6 +68,7 @@ func CreatePodMigrationJob(ctx context.Context, pod *corev1.Pod, evictOptions fr
Annotations: map[string]string{
evictor.AnnotationEvictReason: evictOptions.Reason,
evictor.AnnotationEvictTrigger: evictOptions.PluginName,
AnnotationJobCreatedBy: string(reconcilerUID),
},
},
Spec: sev1alpha1.PodMigrationJobSpec{
Expand Down

0 comments on commit 8a0c4bb

Please sign in to comment.