Skip to content

Commit

Permalink
feat(queue): fix bug that volcano queue namespace is empty (PaddlePad…
Browse files Browse the repository at this point in the history
…dle#1347)

* feat(queue): fix bug that volcano queue namespace is empty

* add ut
  • Loading branch information
D0m021ng committed Jun 25, 2024
1 parent 17e33ba commit cc22063
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
1 change: 0 additions & 1 deletion pkg/common/schema/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package schema
const (
StatusQueueCreating = "creating"
StatusQueueOpen = "open"
StatusQueueUpdating = "updating"
StatusQueueClosing = "closing"
StatusQueueClosed = "closed"
StatusQueueUnavailable = "unavailable"
Expand Down
21 changes: 20 additions & 1 deletion pkg/job/runtime_v2/queue/vcqueue/kube_vc_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ func (vcq *KubeVCQueue) Create(ctx context.Context, q *api.QueueInfo) error {
vcQueue := &v1beta1.Queue{
ObjectMeta: metav1.ObjectMeta{
Name: q.Name,
Annotations: map[string]string{
pfschema.QueueNamespaceAnnotation: q.Namespace,
},
},
Spec: v1beta1.QueueSpec{
Capability: k8s.NewResourceList(q.MaxResources),
Expand Down Expand Up @@ -107,7 +110,7 @@ func (vcq *KubeVCQueue) Update(ctx context.Context, q *api.QueueInfo) error {
return err
}
vcQueue.Spec.Capability = k8s.NewResourceList(q.MaxResources)
vcQueue.Status.State = v1beta1.QueueState(q.Status)
vcQueue.Status.State = statusToVCQueueState(q.Status)
if vcQueue.Spec.Weight < 1 {
vcQueue.Spec.Weight = 1
}
Expand Down Expand Up @@ -225,6 +228,22 @@ func getVCQueueStatus(state v1beta1.QueueState) string {
return status
}

// statusToVCQueueState converts vc queue status to volcano queue state
func statusToVCQueueState(status string) v1beta1.QueueState {
state := v1beta1.QueueStateOpen
switch status {
case pfschema.StatusQueueOpen:
state = v1beta1.QueueStateOpen
case pfschema.StatusQueueClosing:
state = v1beta1.QueueStateClosing
case pfschema.StatusQueueClosed:
state = v1beta1.QueueStateClosed
case pfschema.StatusQueueUnavailable:
state = v1beta1.QueueStateUnknown
}
return state
}

func (vcq *KubeVCQueue) delete(obj interface{}) {
kuberuntime.QueueDeleteFunc(obj, vcq.workQueue)
}
38 changes: 38 additions & 0 deletions pkg/job/runtime_v2/queue/vcqueue/kube_vc_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"volcano.sh/apis/pkg/apis/scheduling/v1beta1"

"github.com/PaddlePaddle/PaddleFlow/pkg/common/k8s"
"github.com/PaddlePaddle/PaddleFlow/pkg/common/resources"
Expand Down Expand Up @@ -66,3 +67,40 @@ func TestKubeRuntimeVCQueue(t *testing.T) {
err = vcQueue.Delete(context.TODO(), queueInfo)
assert.Equal(t, nil, err)
}

// TestStatusToVcQueueStatus test statusToVCQueueState
func TestStatusToVcQueueStatus(t *testing.T) {
testCases := []struct {
name string
status string
vcState v1beta1.QueueState
}{
{
name: "status open",
status: schema.StatusQueueOpen,
vcState: v1beta1.QueueStateOpen,
},
{
name: "status closing",
status: schema.StatusQueueClosing,
vcState: v1beta1.QueueStateClosing,
},
{
name: "status closed",
status: schema.StatusQueueClosed,
vcState: v1beta1.QueueStateClosed,
},
{
name: "status unhkonw",
status: schema.StatusQueueUnavailable,
vcState: v1beta1.QueueStateUnknown,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
state := statusToVCQueueState(tc.status)
assert.Equal(t, state, tc.vcState)
})
}
}

0 comments on commit cc22063

Please sign in to comment.