From 6a67d82dc58344ffff0fa6ae8e3ef79282255e74 Mon Sep 17 00:00:00 2001 From: Thandayuthapani Date: Sat, 8 Feb 2020 11:03:23 +0530 Subject: [PATCH 1/2] Remove State from QueueSpec in v1beta1 --- .../templates/scheduling_v1beta1_queue.yaml | 2 -- installer/volcano-development.yaml | 2 -- pkg/apis/scheduling/v1beta1/types.go | 3 --- .../scheduling/v1beta1/zz_generated.conversion.go | 3 +-- pkg/cli/queue/create.go | 4 +++- pkg/controllers/queue/queue_controller_action.go | 8 ++++---- pkg/controllers/queue/state/closed.go | 2 +- pkg/controllers/queue/state/closing.go | 2 +- pkg/controllers/queue/state/open.go | 2 +- pkg/controllers/queue/state/unknown.go | 2 +- pkg/webhooks/admission/jobs/validate/admit_job.go | 2 +- .../admission/queues/mutate/mutate_queue_test.go | 4 +++- .../admission/queues/validate/validate_queue.go | 2 +- .../queues/validate/validate_queue_test.go | 14 +++++++++----- 14 files changed, 26 insertions(+), 26 deletions(-) diff --git a/installer/helm/chart/volcano/templates/scheduling_v1beta1_queue.yaml b/installer/helm/chart/volcano/templates/scheduling_v1beta1_queue.yaml index c11e2e89bf..71f82b57a3 100644 --- a/installer/helm/chart/volcano/templates/scheduling_v1beta1_queue.yaml +++ b/installer/helm/chart/volcano/templates/scheduling_v1beta1_queue.yaml @@ -27,8 +27,6 @@ spec: type: integer capability: type: object - state: - type: string type: object status: properties: diff --git a/installer/volcano-development.yaml b/installer/volcano-development.yaml index 521b4db370..6fcfee394a 100644 --- a/installer/volcano-development.yaml +++ b/installer/volcano-development.yaml @@ -699,8 +699,6 @@ spec: type: integer capability: type: object - state: - type: string type: object status: properties: diff --git a/pkg/apis/scheduling/v1beta1/types.go b/pkg/apis/scheduling/v1beta1/types.go index 67e12e5a6e..9cb0def4df 100644 --- a/pkg/apis/scheduling/v1beta1/types.go +++ b/pkg/apis/scheduling/v1beta1/types.go @@ -262,9 +262,6 @@ type QueueSpec struct { Weight int32 `json:"weight,omitempty" protobuf:"bytes,1,opt,name=weight"` 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,3,opt,name=reclaimable"` } diff --git a/pkg/apis/scheduling/v1beta1/zz_generated.conversion.go b/pkg/apis/scheduling/v1beta1/zz_generated.conversion.go index 9f5c29b2fd..caa68bea17 100644 --- a/pkg/apis/scheduling/v1beta1/zz_generated.conversion.go +++ b/pkg/apis/scheduling/v1beta1/zz_generated.conversion.go @@ -349,7 +349,6 @@ func Convert_scheduling_QueueList_To_v1beta1_QueueList(in *scheduling.QueueList, func autoConvert_v1beta1_QueueSpec_To_scheduling_QueueSpec(in *QueueSpec, out *scheduling.QueueSpec, s conversion.Scope) error { 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 } @@ -362,7 +361,7 @@ func Convert_v1beta1_QueueSpec_To_scheduling_QueueSpec(in *QueueSpec, out *sched func autoConvert_scheduling_QueueSpec_To_v1beta1_QueueSpec(in *scheduling.QueueSpec, out *QueueSpec, s conversion.Scope) error { out.Weight = in.Weight out.Capability = *(*v1.ResourceList)(unsafe.Pointer(&in.Capability)) - out.State = QueueState(in.State) + // WARNING: in.State requires manual conversion: does not exist in peer-type out.Reclaimable = (*bool)(unsafe.Pointer(in.Reclaimable)) return nil } diff --git a/pkg/cli/queue/create.go b/pkg/cli/queue/create.go index cea436fd1b..2ff74a17c3 100644 --- a/pkg/cli/queue/create.go +++ b/pkg/cli/queue/create.go @@ -59,7 +59,9 @@ func CreateQueue() error { }, Spec: schedulingv1beta1.QueueSpec{ Weight: int32(createQueueFlags.Weight), - State: schedulingv1beta1.QueueState(createQueueFlags.State), + }, + Status: schedulingv1beta1.QueueStatus{ + State: schedulingv1beta1.QueueState(createQueueFlags.State), }, } diff --git a/pkg/controllers/queue/queue_controller_action.go b/pkg/controllers/queue/queue_controller_action.go index 664294cc7d..7cae18a30d 100644 --- a/pkg/controllers/queue/queue_controller_action.go +++ b/pkg/controllers/queue/queue_controller_action.go @@ -83,9 +83,9 @@ func (c *Controller) openQueue(queue *schedulingv1beta1.Queue, updateStateFn sta klog.V(4).Infof("Begin to open queue %s.", queue.Name) newQueue := queue.DeepCopy() - newQueue.Spec.State = schedulingv1beta1.QueueStateOpen + newQueue.Status.State = schedulingv1beta1.QueueStateOpen - if queue.Spec.State != newQueue.Spec.State { + if queue.Status.State != newQueue.Status.State { if _, err := c.vcClient.SchedulingV1beta1().Queues().Update(newQueue); err != nil { c.recorder.Event(newQueue, v1.EventTypeWarning, string(v1alpha1.OpenQueueAction), fmt.Sprintf("Open queue failed for %v", err)) @@ -126,9 +126,9 @@ func (c *Controller) closeQueue(queue *schedulingv1beta1.Queue, updateStateFn st klog.V(4).Infof("Begin to close queue %s.", queue.Name) newQueue := queue.DeepCopy() - newQueue.Spec.State = schedulingv1beta1.QueueStateClosed + newQueue.Status.State = schedulingv1beta1.QueueStateClosed - if queue.Spec.State != newQueue.Spec.State { + if queue.Status.State != newQueue.Status.State { if _, err := c.vcClient.SchedulingV1beta1().Queues().Update(newQueue); err != nil { c.recorder.Event(newQueue, v1.EventTypeWarning, string(v1alpha1.CloseQueueAction), fmt.Sprintf("Close queue failed for %v", err)) diff --git a/pkg/controllers/queue/state/closed.go b/pkg/controllers/queue/state/closed.go index 9bfecc4a84..76e5490f8d 100644 --- a/pkg/controllers/queue/state/closed.go +++ b/pkg/controllers/queue/state/closed.go @@ -39,7 +39,7 @@ func (cs *closedState) Execute(action v1alpha1.Action) error { }) default: return SyncQueue(cs.queue, func(status *v1beta1.QueueStatus, podGroupList []string) { - specState := cs.queue.Spec.State + specState := cs.queue.Status.State if specState == v1beta1.QueueStateOpen { status.State = v1beta1.QueueStateOpen return diff --git a/pkg/controllers/queue/state/closing.go b/pkg/controllers/queue/state/closing.go index 0faa5b623f..fba06d6819 100644 --- a/pkg/controllers/queue/state/closing.go +++ b/pkg/controllers/queue/state/closing.go @@ -44,7 +44,7 @@ func (cs *closingState) Execute(action v1alpha1.Action) error { }) default: return SyncQueue(cs.queue, func(status *v1beta1.QueueStatus, podGroupList []string) { - specState := cs.queue.Spec.State + specState := cs.queue.Status.State if specState == v1beta1.QueueStateOpen { status.State = v1beta1.QueueStateOpen return diff --git a/pkg/controllers/queue/state/open.go b/pkg/controllers/queue/state/open.go index 0defe1d744..22d54c760c 100644 --- a/pkg/controllers/queue/state/open.go +++ b/pkg/controllers/queue/state/open.go @@ -44,7 +44,7 @@ func (os *openState) Execute(action v1alpha1.Action) error { }) default: return SyncQueue(os.queue, func(status *v1beta1.QueueStatus, podGroupList []string) { - specState := os.queue.Spec.State + specState := os.queue.Status.State if len(specState) == 0 || specState == v1beta1.QueueStateOpen { status.State = v1beta1.QueueStateOpen return diff --git a/pkg/controllers/queue/state/unknown.go b/pkg/controllers/queue/state/unknown.go index e176fd84c6..467fda0b62 100644 --- a/pkg/controllers/queue/state/unknown.go +++ b/pkg/controllers/queue/state/unknown.go @@ -44,7 +44,7 @@ func (us *unknownState) Execute(action v1alpha1.Action) error { }) default: return SyncQueue(us.queue, func(status *v1beta1.QueueStatus, podGroupList []string) { - specState := us.queue.Spec.State + specState := us.queue.Status.State if specState == v1beta1.QueueStateOpen { status.State = v1beta1.QueueStateOpen return diff --git a/pkg/webhooks/admission/jobs/validate/admit_job.go b/pkg/webhooks/admission/jobs/validate/admit_job.go index b9f38baa2a..533789fddc 100644 --- a/pkg/webhooks/admission/jobs/validate/admit_job.go +++ b/pkg/webhooks/admission/jobs/validate/admit_job.go @@ -187,7 +187,7 @@ func validateJob(job *v1alpha1.Job, reviewResponse *v1beta1.AdmissionResponse) s } else { if queue.Status.State != schedulingv1beta1.QueueStateOpen { msg = msg + fmt.Sprintf("can only submit job to queue with state `Open`, "+ - "queue `%s` status is `%s`", queue.Name, queue.Spec.State) + "queue `%s` status is `%s`", queue.Name, queue.Status.State) } } diff --git a/pkg/webhooks/admission/queues/mutate/mutate_queue_test.go b/pkg/webhooks/admission/queues/mutate/mutate_queue_test.go index 42ba8cb82d..741fdd87fe 100644 --- a/pkg/webhooks/admission/queues/mutate/mutate_queue_test.go +++ b/pkg/webhooks/admission/queues/mutate/mutate_queue_test.go @@ -52,9 +52,11 @@ func TestMutateQueues(t *testing.T) { }, Spec: schedulingv1beta1.QueueSpec{ Weight: 1, - State: schedulingv1beta1.QueueStateOpen, Reclaimable: &trueValue, }, + Status: schedulingv1beta1.QueueStatus{ + State: schedulingv1beta1.QueueStateOpen, + }, } openStateJSON, err := json.Marshal(openStateReclaimableSet) diff --git a/pkg/webhooks/admission/queues/validate/validate_queue.go b/pkg/webhooks/admission/queues/validate/validate_queue.go index d775377dc8..56d1aca130 100644 --- a/pkg/webhooks/admission/queues/validate/validate_queue.go +++ b/pkg/webhooks/admission/queues/validate/validate_queue.go @@ -99,7 +99,7 @@ func validateQueue(queue *schedulingv1beta1.Queue) error { errs := field.ErrorList{} resourcePath := field.NewPath("requestBody") - errs = append(errs, validateStateOfQueue(queue.Spec.State, resourcePath.Child("spec").Child("state"))...) + errs = append(errs, validateStateOfQueue(queue.Status.State, resourcePath.Child("spec").Child("state"))...) if len(errs) > 0 { return errs.ToAggregate() diff --git a/pkg/webhooks/admission/queues/validate/validate_queue_test.go b/pkg/webhooks/admission/queues/validate/validate_queue_test.go index 3d0eaad445..3e03da99be 100644 --- a/pkg/webhooks/admission/queues/validate/validate_queue_test.go +++ b/pkg/webhooks/admission/queues/validate/validate_queue_test.go @@ -54,7 +54,9 @@ func TestAdmitQueues(t *testing.T) { }, Spec: schedulingv1beta1.QueueSpec{ Weight: 1, - State: schedulingv1beta1.QueueStateOpen, + }, + Status: schedulingv1beta1.QueueStatus{ + State: schedulingv1beta1.QueueStateOpen, }, } @@ -69,7 +71,9 @@ func TestAdmitQueues(t *testing.T) { }, Spec: schedulingv1beta1.QueueSpec{ Weight: 1, - State: schedulingv1beta1.QueueStateClosed, + }, + Status: schedulingv1beta1.QueueStatus{ + State: schedulingv1beta1.QueueStateClosed, }, } @@ -84,7 +88,9 @@ func TestAdmitQueues(t *testing.T) { }, Spec: schedulingv1beta1.QueueSpec{ Weight: 1, - State: "wrong", + }, + Status: schedulingv1beta1.QueueStatus{ + State: "wrong", }, } @@ -99,7 +105,6 @@ func TestAdmitQueues(t *testing.T) { }, Spec: schedulingv1beta1.QueueSpec{ Weight: 1, - State: schedulingv1beta1.QueueStateOpen, }, Status: schedulingv1beta1.QueueStatus{ State: schedulingv1beta1.QueueStateOpen, @@ -117,7 +122,6 @@ func TestAdmitQueues(t *testing.T) { }, Spec: schedulingv1beta1.QueueSpec{ Weight: 1, - State: schedulingv1beta1.QueueStateClosed, }, Status: schedulingv1beta1.QueueStatus{ State: schedulingv1beta1.QueueStateClosed, From a1fad61025ab2d425062c75a8b4192a6abdff306 Mon Sep 17 00:00:00 2001 From: Thandayuthapani Date: Mon, 10 Feb 2020 14:28:13 +0530 Subject: [PATCH 2/2] Fix E2E Test --- test/e2e/util.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/e2e/util.go b/test/e2e/util.go index ab1f7e816e..39eb19117d 100644 --- a/test/e2e/util.go +++ b/test/e2e/util.go @@ -229,8 +229,10 @@ func deleteQueues(cxt *context) { foreground := metav1.DeletePropagationForeground for _, q := range cxt.queues { - patchBytes := []byte(fmt.Sprintf(`{"spec":{"state":"%s"}}`, schedulingv1beta1.QueueStateClosed)) - _, err := cxt.vcclient.SchedulingV1beta1().Queues().Patch(q, types.MergePatchType, patchBytes) + queue, err := cxt.vcclient.SchedulingV1beta1().Queues().Get(q, metav1.GetOptions{}) + Expect(err).NotTo(HaveOccurred()) + queue.Status.State = schedulingv1beta1.QueueStateClosed + _, err = cxt.vcclient.SchedulingV1beta1().Queues().UpdateStatus(queue) Expect(err).NotTo(HaveOccurred()) err = wait.Poll(100*time.Millisecond, oneMinute, queueClosed(cxt, q)) Expect(err).NotTo(HaveOccurred())