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

[YUNIKORN-421] Define app gang scheduling info in API package. #200

Merged
merged 17 commits into from
Oct 27, 2020
Merged
37 changes: 22 additions & 15 deletions pkg/apis/yunikorn.apache.org/v1alpha1/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package v1alpha1

import (
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand All @@ -37,29 +38,35 @@ type Application struct {
// Spec part

type ApplicationSpec struct {
Policy SchedulePolicy `json:"schedulingPolicy"`
Queue string `json:"queue"`
TaskGroup []Task `json:"taskGroups"`
Queue string `json:"queue"`
TaskGroups TaskGroups `json:"taskGroups"`
}

type SchedulePolicy struct {
Policy SchedulingPolicy `json:"name"`
Parameters map[string]string `json:"parameters,omitempty"`
type SchedulingPolicy struct {
Type SchedulingPolicyType `json:"type"`
Parameters map[string]string `json:"parameters,omitempty"`
}

type SchedulingPolicy string
type SchedulingPolicyType string

const (
TryOnce SchedulingPolicy = "TryOnce"
MaxRetry SchedulingPolicy = "MaxRetry"
TryReserve SchedulingPolicy = "TryReserve"
TryPreempt SchedulingPolicy = "TryPreempt"
TryOnce SchedulingPolicyType = "TryOnce"
MaxRetry SchedulingPolicyType = "MaxRetry"
TryReserve SchedulingPolicyType = "TryReserve"
TryPreempt SchedulingPolicyType = "TryPreempt"
)

type Task struct {
GroupName string `json:"groupName"`
MinMember int32 `json:"minMember"`
MinResource map[string]resource.Quantity `json:"minResource"`
type TaskGroups struct {
SchedulingPolicy SchedulingPolicy `json:"schedulingPolicy"`
Groups []TaskGroup `json:"groups"`
}

type TaskGroup struct {
Name string `json:"name"`
MinMember int32 `json:"minMember"`
MinResource map[string]resource.Quantity `json:"minResource"`
NodeSelector metav1.LabelSelector `json:"nodeSelector,omitempty"`
Tolerations []v1.Toleration `json:"tolerations,omitempty"`
}

// Status part
Expand Down
58 changes: 42 additions & 16 deletions pkg/apis/yunikorn.apache.org/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 12 additions & 7 deletions pkg/controller/application/app_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,19 @@ func createApp(name string, namespace string, queue string) appv1.Application {
UID: "UID-APP-00001",
},
Spec: appv1.ApplicationSpec{
Policy: appv1.SchedulePolicy{
Policy: "TryOnce",
},
Queue: queue,
TaskGroup: []appv1.Task{
{
GroupName: "test-task-001",
MinMember: 0,
TaskGroups: appv1.TaskGroups{
SchedulingPolicy: appv1.SchedulingPolicy{
Type: "TryReserve",
Parameters: map[string]string{
"timeout": "2h",
},
},
Groups: []appv1.TaskGroup{
{
Name: "test-task-001",
MinMember: 0,
},
},
},
},
Expand Down
12 changes: 6 additions & 6 deletions test/e2e/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ var _ = ginkgo.Describe("App", func() {
gomega.Ω(appCRD.Spec.Queue).To(gomega.Equal("root.default"))
gomega.Ω(appCRD.ObjectMeta.Name).To(gomega.Equal("example"))
gomega.Ω(appCRD.ObjectMeta.Namespace).To(gomega.Equal(dev))
policy := appCRD.Spec.Policy.Policy
gomega.Ω(string(policy)).To(gomega.Equal("TryOnce"))
gomega.Ω(appCRD.Spec.TaskGroup[0].GroupName).To(gomega.Equal("test-task-0001"))
gomega.Ω(appCRD.Spec.TaskGroup[0].MinMember).To(gomega.Equal(int32(1)))
policy := appCRD.Spec.TaskGroups.SchedulingPolicy
gomega.Ω(policy.Type).To(gomega.Equal("TryReserve"))
yangwwei marked this conversation as resolved.
Show resolved Hide resolved
gomega.Ω(appCRD.Spec.TaskGroups.Groups[0].Name).To(gomega.Equal("test-task-0001"))
gomega.Ω(appCRD.Spec.TaskGroups.Groups[0].MinMember).To(gomega.Equal(int32(1)))
anscpu := resource.MustParse("300m")
ansmem := resource.MustParse("128Mi")
gomega.Ω(appCRD.Spec.TaskGroup[0].MinResource["cpu"]).To(gomega.Equal(anscpu))
gomega.Ω(appCRD.Spec.TaskGroup[0].MinResource["memory"]).To(gomega.Equal(ansmem))
gomega.Ω(appCRD.Spec.TaskGroups.Groups[0].MinResource["cpu"]).To(gomega.Equal(anscpu))
gomega.Ω(appCRD.Spec.TaskGroups.Groups[0].MinResource["memory"]).To(gomega.Equal(ansmem))
})

ginkgo.AfterSuite(func() {
Expand Down
12 changes: 7 additions & 5 deletions test/e2e/testdata/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ spec:
name: TryOnce
queue: root.default
taskGroups:
- groupName: "test-task-0001"
minMember: 1
minResource:
cpu: "300m"
memory: "128Mi"
- schedulingPolicy: "TryReserve"
- groups:
yangwwei marked this conversation as resolved.
Show resolved Hide resolved
- name: "test-task-0001"
minMember: 1
minResource:
cpu: "300m"
memory: "128Mi"

12 changes: 7 additions & 5 deletions test/e2e/testdata/application_error.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ spec:
schedulingPolicy:
name: errorName
taskGroups:
- groupName: 123
minMember: "string"
minResource:
cpu: "ABC"
memory: "ABC"
- schedulingPolicy: "TryReserve"
- groups:
- name: "test-task-0001"
minMember: 1
minResource:
cpu: "300m"
memory: "128Mi"