From 4bf165a63982e76b7171e23cdade9a9d153307b1 Mon Sep 17 00:00:00 2001 From: wei-chenglai Date: Wed, 18 Dec 2024 19:15:08 -0500 Subject: [PATCH] Add priorityClassName in PropagationPolicy & ClusterPropagationPolicy Signed-off-by: wei-chenglai --- api/openapi-spec/swagger.json | 21 ++++++ ...karmada.io_clusterpropagationpolicies.yaml | 51 +++++++++++++ ...policy.karmada.io_propagationpolicies.yaml | 51 +++++++++++++ pkg/apis/policy/v1alpha1/propagation_types.go | 71 +++++++++++++++++++ .../policy/v1alpha1/zz_generated.deepcopy.go | 21 ++++++ pkg/generated/openapi/zz_generated.openapi.go | 37 +++++++++- 6 files changed, 251 insertions(+), 1 deletion(-) diff --git a/api/openapi-spec/swagger.json b/api/openapi-spec/swagger.json index cc316ddb12d2..88961101695f 100644 --- a/api/openapi-spec/swagger.json +++ b/api/openapi-spec/swagger.json @@ -19211,6 +19211,10 @@ "$ref": "#/definitions/com.github.karmada-io.karmada.pkg.apis.policy.v1alpha1.ResourceSelector" } }, + "schedulePriority": { + "description": "SchedulePriority defines how Karmada should resolve the priority and preemption policy for workload scheduling.\n\nThis setting is useful for controlling the scheduling behavior of offline workloads. By setting a higher or lower priority, users can control which workloads are scheduled first. Additionally, it allows specifying a preemption policy where higher-priority workloads can preempt lower-priority ones in scenarios of resource contention.\n\nNote: This feature is currently in the alpha stage. The priority-based scheduling functionality is controlled by the PriorityBasedScheduling feature gate, and preemption is controlled by the PriorityBasedPreemptiveScheduling feature gate. Currently, only priority-based scheduling is supported. Preemption functionality is not yet available and will be introduced in future releases as the feature matures.", + "$ref": "#/definitions/com.github.karmada-io.karmada.pkg.apis.policy.v1alpha1.SchedulePriority" + }, "schedulerName": { "description": "SchedulerName represents which scheduler to proceed the scheduling. If specified, the policy will be dispatched by specified scheduler. If not specified, the policy will be dispatched by default scheduler.", "type": "string" @@ -19289,6 +19293,23 @@ } } }, + "com.github.karmada-io.karmada.pkg.apis.policy.v1alpha1.SchedulePriority": { + "description": "SchedulePriority defines how Karmada should resolve the priority and preemption policy for workload scheduling.", + "type": "object", + "required": [ + "priorityClassName" + ], + "properties": { + "priorityClassName": { + "description": "PriorityClassName specifies which PriorityClass to use. Its behavior depends on PriorityClassSource:\n\nBehavior of PriorityClassName:\n\nFor KubePriorityClass: - When specified: Uses the named Kubernetes PriorityClass. - When empty: Uses the cluster's default PriorityClass (i.e., the PriorityClass marked as the global default in the cluster). - If neither exists: Sets priority=0 and preemptionPolicy=Never.\n\nFor PodPriorityClass: - Uses PriorityClassName from the PodTemplate. - If the specified PriorityClass is not found, falls back to the cluster's default PriorityClass\n (i.e., the PriorityClass marked as the global default in the cluster).\n- If no valid PriorityClass is found: Sets priority=0 and preemptionPolicy=Never. - Not yet implemented.\n\nFor FederatedPriorityClass: - Not yet implemented.", + "type": "string" + }, + "priorityClassSource": { + "description": "PriorityClassSource specifies where Karmada should look for the PriorityClass definition. Available options: - KubePriorityClass (default): Uses Kubernetes PriorityClass (scheduling.k8s.io/v1) - PodPriorityClass: Uses PriorityClassName from PodTemplate: PodSpec.PriorityClassName (not yet implemented) - FederatedPriorityClass: Uses Karmada FederatedPriorityClass (not yet implemented)", + "type": "string" + } + } + }, "com.github.karmada-io.karmada.pkg.apis.policy.v1alpha1.SpreadConstraint": { "description": "SpreadConstraint represents the spread constraints on resources.", "type": "object", diff --git a/charts/karmada/_crds/bases/policy/policy.karmada.io_clusterpropagationpolicies.yaml b/charts/karmada/_crds/bases/policy/policy.karmada.io_clusterpropagationpolicies.yaml index 835dde895cb1..ae3f4419d10e 100644 --- a/charts/karmada/_crds/bases/policy/policy.karmada.io_clusterpropagationpolicies.yaml +++ b/charts/karmada/_crds/bases/policy/policy.karmada.io_clusterpropagationpolicies.yaml @@ -864,6 +864,57 @@ spec: type: object minItems: 1 type: array + schedulePriority: + description: |- + SchedulePriority defines how Karmada should resolve the priority and preemption policy + for workload scheduling. + + This setting is useful for controlling the scheduling behavior of offline workloads. + By setting a higher or lower priority, users can control which workloads are scheduled first. + Additionally, it allows specifying a preemption policy where higher-priority workloads can + preempt lower-priority ones in scenarios of resource contention. + + Note: This feature is currently in the alpha stage. The priority-based scheduling functionality is + controlled by the PriorityBasedScheduling feature gate, and preemption is controlled by the + PriorityBasedPreemptiveScheduling feature gate. Currently, only priority-based scheduling is + supported. Preemption functionality is not yet available and will be introduced in future + releases as the feature matures. + properties: + priorityClassName: + description: |- + PriorityClassName specifies which PriorityClass to use. Its behavior depends on PriorityClassSource: + + Behavior of PriorityClassName: + + For KubePriorityClass: + - When specified: Uses the named Kubernetes PriorityClass. + - When empty: Uses the cluster's default PriorityClass (i.e., the PriorityClass marked as the global default in the cluster). + - If neither exists: Sets priority=0 and preemptionPolicy=Never. + + For PodPriorityClass: + - Uses PriorityClassName from the PodTemplate. + - If the specified PriorityClass is not found, falls back to the cluster's default PriorityClass + (i.e., the PriorityClass marked as the global default in the cluster). + - If no valid PriorityClass is found: Sets priority=0 and preemptionPolicy=Never. + - Not yet implemented. + + For FederatedPriorityClass: + - Not yet implemented. + type: string + priorityClassSource: + default: KubePriorityClass + description: |- + PriorityClassSource specifies where Karmada should look for the PriorityClass definition. + Available options: + - KubePriorityClass (default): Uses Kubernetes PriorityClass (scheduling.k8s.io/v1) + - PodPriorityClass: Uses PriorityClassName from PodTemplate: PodSpec.PriorityClassName (not yet implemented) + - FederatedPriorityClass: Uses Karmada FederatedPriorityClass (not yet implemented) + enum: + - KubePriorityClass + type: string + required: + - priorityClassName + type: object schedulerName: default: default-scheduler description: |- diff --git a/charts/karmada/_crds/bases/policy/policy.karmada.io_propagationpolicies.yaml b/charts/karmada/_crds/bases/policy/policy.karmada.io_propagationpolicies.yaml index 7b488b40ea04..b1caaf73e62e 100644 --- a/charts/karmada/_crds/bases/policy/policy.karmada.io_propagationpolicies.yaml +++ b/charts/karmada/_crds/bases/policy/policy.karmada.io_propagationpolicies.yaml @@ -861,6 +861,57 @@ spec: type: object minItems: 1 type: array + schedulePriority: + description: |- + SchedulePriority defines how Karmada should resolve the priority and preemption policy + for workload scheduling. + + This setting is useful for controlling the scheduling behavior of offline workloads. + By setting a higher or lower priority, users can control which workloads are scheduled first. + Additionally, it allows specifying a preemption policy where higher-priority workloads can + preempt lower-priority ones in scenarios of resource contention. + + Note: This feature is currently in the alpha stage. The priority-based scheduling functionality is + controlled by the PriorityBasedScheduling feature gate, and preemption is controlled by the + PriorityBasedPreemptiveScheduling feature gate. Currently, only priority-based scheduling is + supported. Preemption functionality is not yet available and will be introduced in future + releases as the feature matures. + properties: + priorityClassName: + description: |- + PriorityClassName specifies which PriorityClass to use. Its behavior depends on PriorityClassSource: + + Behavior of PriorityClassName: + + For KubePriorityClass: + - When specified: Uses the named Kubernetes PriorityClass. + - When empty: Uses the cluster's default PriorityClass (i.e., the PriorityClass marked as the global default in the cluster). + - If neither exists: Sets priority=0 and preemptionPolicy=Never. + + For PodPriorityClass: + - Uses PriorityClassName from the PodTemplate. + - If the specified PriorityClass is not found, falls back to the cluster's default PriorityClass + (i.e., the PriorityClass marked as the global default in the cluster). + - If no valid PriorityClass is found: Sets priority=0 and preemptionPolicy=Never. + - Not yet implemented. + + For FederatedPriorityClass: + - Not yet implemented. + type: string + priorityClassSource: + default: KubePriorityClass + description: |- + PriorityClassSource specifies where Karmada should look for the PriorityClass definition. + Available options: + - KubePriorityClass (default): Uses Kubernetes PriorityClass (scheduling.k8s.io/v1) + - PodPriorityClass: Uses PriorityClassName from PodTemplate: PodSpec.PriorityClassName (not yet implemented) + - FederatedPriorityClass: Uses Karmada FederatedPriorityClass (not yet implemented) + enum: + - KubePriorityClass + type: string + required: + - priorityClassName + type: object schedulerName: default: default-scheduler description: |- diff --git a/pkg/apis/policy/v1alpha1/propagation_types.go b/pkg/apis/policy/v1alpha1/propagation_types.go index fe9316f72ca3..8280a9b922c9 100644 --- a/pkg/apis/policy/v1alpha1/propagation_types.go +++ b/pkg/apis/policy/v1alpha1/propagation_types.go @@ -200,6 +200,23 @@ type PropagationSpec struct { // // +optional PreserveResourcesOnDeletion *bool `json:"preserveResourcesOnDeletion,omitempty"` + + // SchedulePriority defines how Karmada should resolve the priority and preemption policy + // for workload scheduling. + // + // This setting is useful for controlling the scheduling behavior of offline workloads. + // By setting a higher or lower priority, users can control which workloads are scheduled first. + // Additionally, it allows specifying a preemption policy where higher-priority workloads can + // preempt lower-priority ones in scenarios of resource contention. + // + // Note: This feature is currently in the alpha stage. The priority-based scheduling functionality is + // controlled by the PriorityBasedScheduling feature gate, and preemption is controlled by the + // PriorityBasedPreemptiveScheduling feature gate. Currently, only priority-based scheduling is + // supported. Preemption functionality is not yet available and will be introduced in future + // releases as the feature matures. + // + // +optional + SchedulePriority *SchedulePriority `json:"schedulePriority,omitempty"` } // ResourceSelector the resources will be selected. @@ -660,6 +677,60 @@ const ( LazyActivation ActivationPreference = "Lazy" ) +// SchedulePriority defines how Karmada should resolve the priority and preemption policy +// for workload scheduling. +type SchedulePriority struct { + // PriorityClassSource specifies where Karmada should look for the PriorityClass definition. + // Available options: + // - KubePriorityClass (default): Uses Kubernetes PriorityClass (scheduling.k8s.io/v1) + // - PodPriorityClass: Uses PriorityClassName from PodTemplate: PodSpec.PriorityClassName (not yet implemented) + // - FederatedPriorityClass: Uses Karmada FederatedPriorityClass (not yet implemented) + // + // +kubebuilder:default="KubePriorityClass" + // +kubebuilder:validation:Enum=KubePriorityClass + // +optional + PriorityClassSource PriorityClassSource `json:"priorityClassSource,omitempty"` + + // PriorityClassName specifies which PriorityClass to use. Its behavior depends on PriorityClassSource: + // + // Behavior of PriorityClassName: + // + // For KubePriorityClass: + // - When specified: Uses the named Kubernetes PriorityClass. + // - When empty: Uses the cluster's default PriorityClass (i.e., the PriorityClass marked as the global default in the cluster). + // - If neither exists: Sets priority=0 and preemptionPolicy=Never. + // + // For PodPriorityClass: + // - Uses PriorityClassName from the PodTemplate. + // - If the specified PriorityClass is not found, falls back to the cluster's default PriorityClass + // (i.e., the PriorityClass marked as the global default in the cluster). + // - If no valid PriorityClass is found: Sets priority=0 and preemptionPolicy=Never. + // - Not yet implemented. + // + // For FederatedPriorityClass: + // - Not yet implemented. + // + // +required + PriorityClassName string `json:"priorityClassName,omitempty"` +} + +// PriorityClassSource defines the type for PriorityClassSource field. +type PriorityClassSource string + +const ( + // FederatedPriorityClass specifies to use Karmada FederatedPriorityClass for priority resolution. + // This feature is planned for future releases and is currently not implemented. + FederatedPriorityClass PriorityClassSource = "FederatedPriorityClass" + + // KubePriorityClass specifies to use Kubernetes native PriorityClass (scheduling.k8s.io/v1) + // for priority resolution. This is the default source. + KubePriorityClass PriorityClassSource = "KubePriorityClass" + + // PodPriorityClass specifies to use the PriorityClassName defined in the workload's + // PodTemplate for priority resolution. + PodPriorityClass PriorityClassSource = "PodPriorityClass" +) + // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // PropagationPolicyList contains a list of PropagationPolicy. diff --git a/pkg/apis/policy/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/policy/v1alpha1/zz_generated.deepcopy.go index 2f50916a1057..6d86fad3aabb 100644 --- a/pkg/apis/policy/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/policy/v1alpha1/zz_generated.deepcopy.go @@ -907,6 +907,11 @@ func (in *PropagationSpec) DeepCopyInto(out *PropagationSpec) { *out = new(bool) **out = **in } + if in.SchedulePriority != nil { + in, out := &in.SchedulePriority, &out.SchedulePriority + *out = new(SchedulePriority) + **out = **in + } return } @@ -984,6 +989,22 @@ func (in *RuleWithCluster) DeepCopy() *RuleWithCluster { 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 *SpreadConstraint) DeepCopyInto(out *SpreadConstraint) { *out = *in diff --git a/pkg/generated/openapi/zz_generated.openapi.go b/pkg/generated/openapi/zz_generated.openapi.go index 6ef14a7a9eb6..2715b8e6f5f1 100644 --- a/pkg/generated/openapi/zz_generated.openapi.go +++ b/pkg/generated/openapi/zz_generated.openapi.go @@ -128,6 +128,7 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1.ReplicaSchedulingStrategy": schema_pkg_apis_policy_v1alpha1_ReplicaSchedulingStrategy(ref), "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1.ResourceSelector": schema_pkg_apis_policy_v1alpha1_ResourceSelector(ref), "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1.RuleWithCluster": schema_pkg_apis_policy_v1alpha1_RuleWithCluster(ref), + "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1.SchedulePriority": schema_pkg_apis_policy_v1alpha1_SchedulePriority(ref), "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1.SpreadConstraint": schema_pkg_apis_policy_v1alpha1_SpreadConstraint(ref), "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1.StatePreservation": schema_pkg_apis_policy_v1alpha1_StatePreservation(ref), "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1.StatePreservationRule": schema_pkg_apis_policy_v1alpha1_StatePreservationRule(ref), @@ -5008,12 +5009,18 @@ func schema_pkg_apis_policy_v1alpha1_PropagationSpec(ref common.ReferenceCallbac Format: "", }, }, + "schedulePriority": { + SchemaProps: spec.SchemaProps{ + Description: "SchedulePriority defines how Karmada should resolve the priority and preemption policy for workload scheduling.\n\nThis setting is useful for controlling the scheduling behavior of offline workloads. By setting a higher or lower priority, users can control which workloads are scheduled first. Additionally, it allows specifying a preemption policy where higher-priority workloads can preempt lower-priority ones in scenarios of resource contention.\n\nNote: This feature is currently in the alpha stage. The priority-based scheduling functionality is controlled by the PriorityBasedScheduling feature gate, and preemption is controlled by the PriorityBasedPreemptiveScheduling feature gate. Currently, only priority-based scheduling is supported. Preemption functionality is not yet available and will be introduced in future releases as the feature matures.", + Ref: ref("github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1.SchedulePriority"), + }, + }, }, Required: []string{"resourceSelectors"}, }, }, 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/policy/v1alpha1.ResourceSelector", "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1.Suspension"}, + "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/policy/v1alpha1.ResourceSelector", "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1.SchedulePriority", "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1.Suspension"}, } } @@ -5133,6 +5140,34 @@ func schema_pkg_apis_policy_v1alpha1_RuleWithCluster(ref common.ReferenceCallbac } } +func schema_pkg_apis_policy_v1alpha1_SchedulePriority(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "SchedulePriority defines how Karmada should resolve the priority and preemption policy for workload scheduling.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "priorityClassSource": { + SchemaProps: spec.SchemaProps{ + Description: "PriorityClassSource specifies where Karmada should look for the PriorityClass definition. Available options: - KubePriorityClass (default): Uses Kubernetes PriorityClass (scheduling.k8s.io/v1) - PodPriorityClass: Uses PriorityClassName from PodTemplate: PodSpec.PriorityClassName (not yet implemented) - FederatedPriorityClass: Uses Karmada FederatedPriorityClass (not yet implemented)", + Type: []string{"string"}, + Format: "", + }, + }, + "priorityClassName": { + SchemaProps: spec.SchemaProps{ + Description: "PriorityClassName specifies which PriorityClass to use. Its behavior depends on PriorityClassSource:\n\nBehavior of PriorityClassName:\n\nFor KubePriorityClass: - When specified: Uses the named Kubernetes PriorityClass. - When empty: Uses the cluster's default PriorityClass (i.e., the PriorityClass marked as the global default in the cluster). - If neither exists: Sets priority=0 and preemptionPolicy=Never.\n\nFor PodPriorityClass: - Uses PriorityClassName from the PodTemplate. - If the specified PriorityClass is not found, falls back to the cluster's default PriorityClass\n (i.e., the PriorityClass marked as the global default in the cluster).\n- If no valid PriorityClass is found: Sets priority=0 and preemptionPolicy=Never. - Not yet implemented.\n\nFor FederatedPriorityClass: - Not yet implemented.", + Type: []string{"string"}, + Format: "", + }, + }, + }, + Required: []string{"priorityClassName"}, + }, + }, + } +} + func schema_pkg_apis_policy_v1alpha1_SpreadConstraint(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{