From 508ea8febf9c621b7de76eb688888ca0e9c06bed Mon Sep 17 00:00:00 2001 From: Zhang Jinghui Date: Thu, 26 Dec 2019 09:34:43 +0800 Subject: [PATCH 1/2] add reclaimable parameter for queue --- pkg/apis/scheduling/types.go | 2 ++ pkg/apis/scheduling/v1alpha2/types.go | 2 ++ pkg/scheduler/actions/reclaim/reclaim.go | 4 ++++ pkg/scheduler/api/queue_info.go | 17 +++++++++++++++++ 4 files changed, 25 insertions(+) diff --git a/pkg/apis/scheduling/types.go b/pkg/apis/scheduling/types.go index 8437d97e76..b6b1e296d1 100644 --- a/pkg/apis/scheduling/types.go +++ b/pkg/apis/scheduling/types.go @@ -261,6 +261,8 @@ type QueueSpec struct { Capability v1.ResourceList // State controller the status of queue State QueueState + // Reclaimable indicate whether the queue can be reclaimed by other queue + Reclaimable *bool } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object diff --git a/pkg/apis/scheduling/v1alpha2/types.go b/pkg/apis/scheduling/v1alpha2/types.go index bff1da67cf..947c59e8ea 100644 --- a/pkg/apis/scheduling/v1alpha2/types.go +++ b/pkg/apis/scheduling/v1alpha2/types.go @@ -262,6 +262,8 @@ type QueueSpec struct { Capability v1.ResourceList `json:"capability,omitempty" protobuf:"bytes,2,opt,name=capability"` // State controller the status of queue State QueueState `json:"state,omitempty" protobuf:"bytes,3,opt,name=state"` + // Reclaimable indicate whether the queue can be reclaimed by other queue + Reclaimable *bool `json:"reclaimable,omitempty" protobuf:"bytes,4,opt,name=reclaimable"` } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object diff --git a/pkg/scheduler/actions/reclaim/reclaim.go b/pkg/scheduler/actions/reclaim/reclaim.go index 963397fa5a..178d38024b 100644 --- a/pkg/scheduler/actions/reclaim/reclaim.go +++ b/pkg/scheduler/actions/reclaim/reclaim.go @@ -142,6 +142,10 @@ func (alloc *reclaimAction) Execute(ssn *framework.Session) { if j, found := ssn.Jobs[task.Job]; !found { continue } else if j.Queue != job.Queue { + q := ssn.Queues[j.Queue] + if !q.Reclaimable() { + continue + } // Clone task to avoid modify Task's status on node. reclaimees = append(reclaimees, task.Clone()) } diff --git a/pkg/scheduler/api/queue_info.go b/pkg/scheduler/api/queue_info.go index 3694adbffe..a969c57afe 100644 --- a/pkg/scheduler/api/queue_info.go +++ b/pkg/scheduler/api/queue_info.go @@ -56,3 +56,20 @@ func (q *QueueInfo) Clone() *QueueInfo { Queue: q.Queue, } } + +// Reclaimable return whether queue is reclaimable +func (q *QueueInfo) Reclaimable() bool { + if q == nil { + return false + } + + if q.Queue == nil { + return false + } + + if q.Queue.Spec.Reclaimable == nil { + return true + } + + return *q.Queue.Spec.Reclaimable +} From 4208c42caff849c31d4b44a4ea0b2578c2edd27d Mon Sep 17 00:00:00 2001 From: Zhang Jinghui Date: Thu, 2 Jan 2020 10:35:00 +0800 Subject: [PATCH 2/2] add generated code for reclaimable parameter --- pkg/apis/scheduling/v1alpha1/zz_generated.conversion.go | 1 + pkg/apis/scheduling/v1alpha2/zz_generated.conversion.go | 2 ++ pkg/apis/scheduling/v1alpha2/zz_generated.deepcopy.go | 5 +++++ pkg/apis/scheduling/zz_generated.deepcopy.go | 5 +++++ 4 files changed, 13 insertions(+) diff --git a/pkg/apis/scheduling/v1alpha1/zz_generated.conversion.go b/pkg/apis/scheduling/v1alpha1/zz_generated.conversion.go index 7574a9d10c..4d36895e29 100644 --- a/pkg/apis/scheduling/v1alpha1/zz_generated.conversion.go +++ b/pkg/apis/scheduling/v1alpha1/zz_generated.conversion.go @@ -366,6 +366,7 @@ func autoConvert_scheduling_QueueSpec_To_v1alpha1_QueueSpec(in *scheduling.Queue out.Weight = in.Weight out.Capability = *(*v1.ResourceList)(unsafe.Pointer(&in.Capability)) // WARNING: in.State requires manual conversion: does not exist in peer-type + // WARNING: in.Reclaimable requires manual conversion: does not exist in peer-type return nil } diff --git a/pkg/apis/scheduling/v1alpha2/zz_generated.conversion.go b/pkg/apis/scheduling/v1alpha2/zz_generated.conversion.go index 468d5a6cc8..bdec3df7a7 100644 --- a/pkg/apis/scheduling/v1alpha2/zz_generated.conversion.go +++ b/pkg/apis/scheduling/v1alpha2/zz_generated.conversion.go @@ -359,6 +359,7 @@ func autoConvert_v1alpha2_QueueSpec_To_scheduling_QueueSpec(in *QueueSpec, out * out.Weight = in.Weight out.Capability = *(*v1.ResourceList)(unsafe.Pointer(&in.Capability)) out.State = scheduling.QueueState(in.State) + out.Reclaimable = (*bool)(unsafe.Pointer(in.Reclaimable)) return nil } @@ -371,6 +372,7 @@ func autoConvert_scheduling_QueueSpec_To_v1alpha2_QueueSpec(in *scheduling.Queue out.Weight = in.Weight out.Capability = *(*v1.ResourceList)(unsafe.Pointer(&in.Capability)) out.State = QueueState(in.State) + out.Reclaimable = (*bool)(unsafe.Pointer(in.Reclaimable)) return nil } diff --git a/pkg/apis/scheduling/v1alpha2/zz_generated.deepcopy.go b/pkg/apis/scheduling/v1alpha2/zz_generated.deepcopy.go index 7ae3636210..e0d85eed20 100644 --- a/pkg/apis/scheduling/v1alpha2/zz_generated.deepcopy.go +++ b/pkg/apis/scheduling/v1alpha2/zz_generated.deepcopy.go @@ -241,6 +241,11 @@ func (in *QueueSpec) DeepCopyInto(out *QueueSpec) { (*out)[key] = val.DeepCopy() } } + if in.Reclaimable != nil { + in, out := &in.Reclaimable, &out.Reclaimable + *out = new(bool) + **out = **in + } return } diff --git a/pkg/apis/scheduling/zz_generated.deepcopy.go b/pkg/apis/scheduling/zz_generated.deepcopy.go index 55f65dd2cb..ac0178f792 100644 --- a/pkg/apis/scheduling/zz_generated.deepcopy.go +++ b/pkg/apis/scheduling/zz_generated.deepcopy.go @@ -241,6 +241,11 @@ func (in *QueueSpec) DeepCopyInto(out *QueueSpec) { (*out)[key] = val.DeepCopy() } } + if in.Reclaimable != nil { + in, out := &in.Reclaimable, &out.Reclaimable + *out = new(bool) + **out = **in + } return }