From 787679a0123c693b08ac027abdd082eccf6c0c44 Mon Sep 17 00:00:00 2001 From: wei-chenglai Date: Wed, 18 Dec 2024 21:41:09 -0500 Subject: [PATCH] Add Priority and PreemptionPolicy fields in ResourceBinding Signed-off-by: wei-chenglai --- api/openapi-spec/swagger.json | 19 ++++++++++ ...rk.karmada.io_clusterresourcebindings.yaml | 24 +++++++++++++ .../work.karmada.io_resourcebindings.yaml | 24 +++++++++++++ pkg/apis/work/v1alpha2/binding_types.go | 33 +++++++++++++++++ .../work/v1alpha2/zz_generated.deepcopy.go | 21 +++++++++++ pkg/generated/openapi/zz_generated.openapi.go | 36 ++++++++++++++++++- 6 files changed, 156 insertions(+), 1 deletion(-) diff --git a/api/openapi-spec/swagger.json b/api/openapi-spec/swagger.json index eaa111806f85..a853c1c1efb9 100644 --- a/api/openapi-spec/swagger.json +++ b/api/openapi-spec/swagger.json @@ -20389,6 +20389,10 @@ "default": {}, "$ref": "#/definitions/com.github.karmada-io.karmada.pkg.apis.work.v1alpha2.ObjectReference" }, + "schedulePriority": { + "description": "SchedulePriority represents the scheduling priority and preemption policy of workloads.", + "$ref": "#/definitions/com.github.karmada-io.karmada.pkg.apis.work.v1alpha2.SchedulePriority" + }, "schedulerName": { "description": "SchedulerName represents which scheduler to proceed the scheduling. It inherits directly from the associated PropagationPolicy(or ClusterPropagationPolicy).", "type": "string" @@ -20434,6 +20438,21 @@ } } }, + "com.github.karmada-io.karmada.pkg.apis.work.v1alpha2.SchedulePriority": { + "description": "SchedulePriority represents the scheduling priority and preemption policy of workloads.", + "type": "object", + "properties": { + "preemptionPolicy": { + "description": "PreemptionPolicy controls the preemption policy of this binding. Valid values are: - Never: (default) prevents the binding from preempting other bindings - PreemptLowerPriority: allows the binding to preempt lower-priority bindings", + "type": "string" + }, + "priority": { + "description": "Priority represents the scheduling priority of the binding. Higher values indicate higher priority. If not specified, the priority value is set to 0.", + "type": "integer", + "format": "int32" + } + } + }, "com.github.karmada-io.karmada.pkg.apis.work.v1alpha2.Suspension": { "description": "Suspension defines the policy for suspending dispatching and scheduling.", "type": "object", diff --git a/charts/karmada/_crds/bases/work/work.karmada.io_clusterresourcebindings.yaml b/charts/karmada/_crds/bases/work/work.karmada.io_clusterresourcebindings.yaml index 515d3fe52b2d..b735b1089d04 100644 --- a/charts/karmada/_crds/bases/work/work.karmada.io_clusterresourcebindings.yaml +++ b/charts/karmada/_crds/bases/work/work.karmada.io_clusterresourcebindings.yaml @@ -1252,6 +1252,30 @@ spec: - kind - name type: object + schedulePriority: + description: SchedulePriority represents the scheduling priority and + preemption policy of workloads. + properties: + preemptionPolicy: + default: Never + description: |- + PreemptionPolicy controls the preemption policy of this binding. + Valid values are: + - Never: (default) prevents the binding from preempting other bindings + - PreemptLowerPriority: allows the binding to preempt lower-priority bindings + enum: + - Never + - PreemptLowerPriority + type: string + priority: + default: 0 + description: |- + Priority represents the scheduling priority of the binding. + Higher values indicate higher priority. + If not specified, the priority value is set to 0. + format: int32 + type: integer + type: object schedulerName: description: |- SchedulerName represents which scheduler to proceed the scheduling. diff --git a/charts/karmada/_crds/bases/work/work.karmada.io_resourcebindings.yaml b/charts/karmada/_crds/bases/work/work.karmada.io_resourcebindings.yaml index 9d6b1884d087..66821ec69aac 100644 --- a/charts/karmada/_crds/bases/work/work.karmada.io_resourcebindings.yaml +++ b/charts/karmada/_crds/bases/work/work.karmada.io_resourcebindings.yaml @@ -1252,6 +1252,30 @@ spec: - kind - name type: object + schedulePriority: + description: SchedulePriority represents the scheduling priority and + preemption policy of workloads. + properties: + preemptionPolicy: + default: Never + description: |- + PreemptionPolicy controls the preemption policy of this binding. + Valid values are: + - Never: (default) prevents the binding from preempting other bindings + - PreemptLowerPriority: allows the binding to preempt lower-priority bindings + enum: + - Never + - PreemptLowerPriority + type: string + priority: + default: 0 + description: |- + Priority represents the scheduling priority of the binding. + Higher values indicate higher priority. + If not specified, the priority value is set to 0. + format: int32 + type: integer + type: object schedulerName: description: |- SchedulerName represents which scheduler to proceed the scheduling. diff --git a/pkg/apis/work/v1alpha2/binding_types.go b/pkg/apis/work/v1alpha2/binding_types.go index 4f75a5d68682..cd6a24aa150f 100644 --- a/pkg/apis/work/v1alpha2/binding_types.go +++ b/pkg/apis/work/v1alpha2/binding_types.go @@ -159,6 +159,10 @@ type ResourceBindingSpec struct { // This setting applies to all Work objects created under this binding object. // +optional PreserveResourcesOnDeletion *bool `json:"preserveResourcesOnDeletion,omitempty"` + + // SchedulePriority represents the scheduling priority and preemption policy of workloads. + // +optional + SchedulePriority *SchedulePriority `json:"schedulePriority,omitempty"` } // ObjectReference contains enough information to locate the referenced object inside current cluster. @@ -337,6 +341,35 @@ type Suspension struct { Scheduling *bool `json:"scheduling,omitempty"` } +// SchedulePriority represents the scheduling priority and preemption policy of workloads. +type SchedulePriority struct { + // Priority represents the scheduling priority of the binding. + // Higher values indicate higher priority. + // If not specified, the priority value is set to 0. + // +kubebuilder:default=0 + // +optional + Priority int32 `json:"priority,omitempty"` + + // PreemptionPolicy controls the preemption policy of this binding. + // Valid values are: + // - Never: (default) prevents the binding from preempting other bindings + // - PreemptLowerPriority: allows the binding to preempt lower-priority bindings + // +kubebuilder:default=Never + // +kubebuilder:validation:Enum=Never;PreemptLowerPriority + // +optional + PreemptionPolicy PreemptionPolicy `json:"preemptionPolicy,omitempty"` +} + +// PreemptionPolicy defines the preemption behavior for bindings +type PreemptionPolicy string + +const ( + // PreemptLowerPriority indicates that binding can preempt lower priority bindings + PreemptLowerPriority PreemptionPolicy = "PreemptLowerPriority" + // PreemptNever indicates that binding will never preempt other bindings + PreemptNever PreemptionPolicy = "Never" +) + // ResourceBindingStatus represents the overall status of the strategy as well as the referenced resources. type ResourceBindingStatus struct { // SchedulerObservedGeneration is the generation(.metadata.generation) observed by the scheduler. diff --git a/pkg/apis/work/v1alpha2/zz_generated.deepcopy.go b/pkg/apis/work/v1alpha2/zz_generated.deepcopy.go index 44ce04650198..2aeeeefb58a9 100644 --- a/pkg/apis/work/v1alpha2/zz_generated.deepcopy.go +++ b/pkg/apis/work/v1alpha2/zz_generated.deepcopy.go @@ -370,6 +370,11 @@ func (in *ResourceBindingSpec) DeepCopyInto(out *ResourceBindingSpec) { *out = new(bool) **out = **in } + if in.SchedulePriority != nil { + in, out := &in.SchedulePriority, &out.SchedulePriority + *out = new(SchedulePriority) + **out = **in + } return } @@ -417,6 +422,22 @@ func (in *ResourceBindingStatus) DeepCopy() *ResourceBindingStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SchedulePriority) DeepCopyInto(out *SchedulePriority) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SchedulePriority. +func (in *SchedulePriority) DeepCopy() *SchedulePriority { + if in == nil { + return nil + } + out := new(SchedulePriority) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Suspension) DeepCopyInto(out *Suspension) { *out = *in diff --git a/pkg/generated/openapi/zz_generated.openapi.go b/pkg/generated/openapi/zz_generated.openapi.go index 8eac67ea5805..e2c71bc01e4a 100644 --- a/pkg/generated/openapi/zz_generated.openapi.go +++ b/pkg/generated/openapi/zz_generated.openapi.go @@ -180,6 +180,7 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.ResourceBindingList": schema_pkg_apis_work_v1alpha2_ResourceBindingList(ref), "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.ResourceBindingSpec": schema_pkg_apis_work_v1alpha2_ResourceBindingSpec(ref), "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.ResourceBindingStatus": schema_pkg_apis_work_v1alpha2_ResourceBindingStatus(ref), + "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.SchedulePriority": schema_pkg_apis_work_v1alpha2_SchedulePriority(ref), "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.Suspension": schema_pkg_apis_work_v1alpha2_Suspension(ref), "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.TargetCluster": schema_pkg_apis_work_v1alpha2_TargetCluster(ref), "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.TaskOptions": schema_pkg_apis_work_v1alpha2_TaskOptions(ref), @@ -7385,12 +7386,18 @@ func schema_pkg_apis_work_v1alpha2_ResourceBindingSpec(ref common.ReferenceCallb Format: "", }, }, + "schedulePriority": { + SchemaProps: spec.SchemaProps{ + Description: "SchedulePriority represents the scheduling priority and preemption policy of workloads.", + Ref: ref("github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.SchedulePriority"), + }, + }, }, Required: []string{"resource"}, }, }, Dependencies: []string{ - "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1.FailoverBehavior", "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1.Placement", "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.BindingSnapshot", "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.GracefulEvictionTask", "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.ObjectReference", "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.ReplicaRequirements", "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.Suspension", "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.TargetCluster", "k8s.io/apimachinery/pkg/apis/meta/v1.Time"}, + "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1.FailoverBehavior", "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1.Placement", "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.BindingSnapshot", "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.GracefulEvictionTask", "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.ObjectReference", "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.ReplicaRequirements", "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.SchedulePriority", "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.Suspension", "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.TargetCluster", "k8s.io/apimachinery/pkg/apis/meta/v1.Time"}, } } @@ -7457,6 +7464,33 @@ func schema_pkg_apis_work_v1alpha2_ResourceBindingStatus(ref common.ReferenceCal } } +func schema_pkg_apis_work_v1alpha2_SchedulePriority(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "SchedulePriority represents the scheduling priority and preemption policy of workloads.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "priority": { + SchemaProps: spec.SchemaProps{ + Description: "Priority represents the scheduling priority of the binding. Higher values indicate higher priority. If not specified, the priority value is set to 0.", + Type: []string{"integer"}, + Format: "int32", + }, + }, + "preemptionPolicy": { + SchemaProps: spec.SchemaProps{ + Description: "PreemptionPolicy controls the preemption policy of this binding. Valid values are: - Never: (default) prevents the binding from preempting other bindings - PreemptLowerPriority: allows the binding to preempt lower-priority bindings", + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + } +} + func schema_pkg_apis_work_v1alpha2_Suspension(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{