Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

koord-descheduler: fix descheduler object limiter with multiple profiles #2200

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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