From 25e0f402d8381215e4ec6f0332cbabd95d96be4a 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 | 18 +++++ ...karmada.io_clusterpropagationpolicies.yaml | 60 ++++++++++++++ ...policy.karmada.io_propagationpolicies.yaml | 60 ++++++++++++++ pkg/apis/policy/v1alpha1/propagation_types.go | 80 +++++++++++++++++++ .../policy/v1alpha1/zz_generated.deepcopy.go | 21 +++++ pkg/generated/openapi/zz_generated.openapi.go | 36 ++++++++- 6 files changed, 274 insertions(+), 1 deletion(-) diff --git a/api/openapi-spec/swagger.json b/api/openapi-spec/swagger.json index eaa111806f85..0c32cb3b851e 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\nValid options for PriorityClassSource are: - KubePriorityClass (default): Uses Kubernetes PriorityClass (scheduling.k8s.io/v1) - PodPriorityClass: Uses PriorityClassName from PodTemplate (PodSpec.PriorityClassName) - FederatedPriorityClass: Uses Karmada FederatedPriorityClass (not yet implemented)\n\nPriorityClassName behavior:\n\nFor KubePriorityClass: - If specified: Uses the named Kubernetes PriorityClass - If empty: Uses cluster's global default PriorityClass - If neither exists: Sets priority=0 and preemptionPolicy=Never\n\nFor PodPriorityClass: - Uses PriorityClassName from PodTemplate - Falls back to global default if not found - If no valid PriorityClass found: Sets priority=0 and preemptionPolicy=Never\n\nFor FederatedPriorityClass: - Reserved for future use - Current behavior undefined", + "$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,20 @@ } } }, + "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", + "properties": { + "priorityClassName": { + "description": "PriorityClassName specifies which PriorityClass to use. Its behavior depends on PriorityClassSource:\n\nPriorityClassName behavior:\n\nFor KubePriorityClass: - If specified: Uses the named Kubernetes PriorityClass - If empty: Uses cluster's global default PriorityClass - If neither exists: Sets priority=0 and preemptionPolicy=Never\n\nFor PodPriorityClass: - Uses PriorityClassName from PodTemplate - Falls back to global default if not found - If no valid PriorityClass found: Sets priority=0 and preemptionPolicy=Never\n\nFor FederatedPriorityClass: - Reserved for future use - Current behavior undefined", + "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) - 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..1ad86329a544 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,66 @@ spec: type: object minItems: 1 type: array + schedulePriority: + description: |- + SchedulePriority defines how Karmada should resolve the priority and preemption policy + for workload scheduling. + + Valid options for PriorityClassSource are: + - KubePriorityClass (default): Uses Kubernetes PriorityClass (scheduling.k8s.io/v1) + - PodPriorityClass: Uses PriorityClassName from PodTemplate (PodSpec.PriorityClassName) + - FederatedPriorityClass: Uses Karmada FederatedPriorityClass (not yet implemented) + + PriorityClassName behavior: + + For KubePriorityClass: + - If specified: Uses the named Kubernetes PriorityClass + - If empty: Uses cluster's global default PriorityClass + - If neither exists: Sets priority=0 and preemptionPolicy=Never + + For PodPriorityClass: + - Uses PriorityClassName from PodTemplate + - Falls back to global default if not found + - If no valid PriorityClass found: Sets priority=0 and preemptionPolicy=Never + + For FederatedPriorityClass: + - Reserved for future use + - Current behavior undefined + properties: + priorityClassName: + description: |- + PriorityClassName specifies which PriorityClass to use. Its behavior depends on PriorityClassSource: + + PriorityClassName behavior: + + For KubePriorityClass: + - If specified: Uses the named Kubernetes PriorityClass + - If empty: Uses cluster's global default PriorityClass + - If neither exists: Sets priority=0 and preemptionPolicy=Never + + For PodPriorityClass: + - Uses PriorityClassName from PodTemplate + - Falls back to global default if not found + - If no valid PriorityClass found: Sets priority=0 and preemptionPolicy=Never + + For FederatedPriorityClass: + - Reserved for future use + - Current behavior undefined + 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) + - FederatedPriorityClass: Uses Karmada FederatedPriorityClass (not yet implemented) + enum: + - FederatedPriorityClass + - KubePriorityClass + - PodPriorityClass + type: string + 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..ef63899cdeec 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,66 @@ spec: type: object minItems: 1 type: array + schedulePriority: + description: |- + SchedulePriority defines how Karmada should resolve the priority and preemption policy + for workload scheduling. + + Valid options for PriorityClassSource are: + - KubePriorityClass (default): Uses Kubernetes PriorityClass (scheduling.k8s.io/v1) + - PodPriorityClass: Uses PriorityClassName from PodTemplate (PodSpec.PriorityClassName) + - FederatedPriorityClass: Uses Karmada FederatedPriorityClass (not yet implemented) + + PriorityClassName behavior: + + For KubePriorityClass: + - If specified: Uses the named Kubernetes PriorityClass + - If empty: Uses cluster's global default PriorityClass + - If neither exists: Sets priority=0 and preemptionPolicy=Never + + For PodPriorityClass: + - Uses PriorityClassName from PodTemplate + - Falls back to global default if not found + - If no valid PriorityClass found: Sets priority=0 and preemptionPolicy=Never + + For FederatedPriorityClass: + - Reserved for future use + - Current behavior undefined + properties: + priorityClassName: + description: |- + PriorityClassName specifies which PriorityClass to use. Its behavior depends on PriorityClassSource: + + PriorityClassName behavior: + + For KubePriorityClass: + - If specified: Uses the named Kubernetes PriorityClass + - If empty: Uses cluster's global default PriorityClass + - If neither exists: Sets priority=0 and preemptionPolicy=Never + + For PodPriorityClass: + - Uses PriorityClassName from PodTemplate + - Falls back to global default if not found + - If no valid PriorityClass found: Sets priority=0 and preemptionPolicy=Never + + For FederatedPriorityClass: + - Reserved for future use + - Current behavior undefined + 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) + - FederatedPriorityClass: Uses Karmada FederatedPriorityClass (not yet implemented) + enum: + - FederatedPriorityClass + - KubePriorityClass + - PodPriorityClass + type: string + 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..70a3dd144258 100644 --- a/pkg/apis/policy/v1alpha1/propagation_types.go +++ b/pkg/apis/policy/v1alpha1/propagation_types.go @@ -200,6 +200,33 @@ type PropagationSpec struct { // // +optional PreserveResourcesOnDeletion *bool `json:"preserveResourcesOnDeletion,omitempty"` + + // SchedulePriority defines how Karmada should resolve the priority and preemption policy + // for workload scheduling. + // + // Valid options for PriorityClassSource are: + // - KubePriorityClass (default): Uses Kubernetes PriorityClass (scheduling.k8s.io/v1) + // - PodPriorityClass: Uses PriorityClassName from PodTemplate (PodSpec.PriorityClassName) + // - FederatedPriorityClass: Uses Karmada FederatedPriorityClass (not yet implemented) + // + // PriorityClassName behavior: + // + // For KubePriorityClass: + // - If specified: Uses the named Kubernetes PriorityClass + // - If empty: Uses cluster's global default PriorityClass + // - If neither exists: Sets priority=0 and preemptionPolicy=Never + // + // For PodPriorityClass: + // - Uses PriorityClassName from PodTemplate + // - Falls back to global default if not found + // - If no valid PriorityClass found: Sets priority=0 and preemptionPolicy=Never + // + // For FederatedPriorityClass: + // - Reserved for future use + // - Current behavior undefined + // + // +optional + SchedulePriority *SchedulePriority `json:"schedulePriority,omitempty"` } // ResourceSelector the resources will be selected. @@ -660,6 +687,59 @@ 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) + // - FederatedPriorityClass: Uses Karmada FederatedPriorityClass (not yet implemented) + // + // +kubebuilder:default="KubePriorityClass" + // +kubebuilder:validation:Enum=FederatedPriorityClass;KubePriorityClass;PodPriorityClass + // +optional + PriorityClassSource PriorityClassSource `json:"priorityClassSource,omitempty"` + + // PriorityClassName specifies which PriorityClass to use. Its behavior depends on PriorityClassSource: + // + // PriorityClassName behavior: + // + // For KubePriorityClass: + // - If specified: Uses the named Kubernetes PriorityClass + // - If empty: Uses cluster's global default PriorityClass + // - If neither exists: Sets priority=0 and preemptionPolicy=Never + // + // For PodPriorityClass: + // - Uses PriorityClassName from PodTemplate + // - Falls back to global default if not found + // - If no valid PriorityClass found: Sets priority=0 and preemptionPolicy=Never + // + // For FederatedPriorityClass: + // - Reserved for future use + // - Current behavior undefined + // + // +optional + 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 8eac67ea5805..7cead45588eb 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\nValid options for PriorityClassSource are: - KubePriorityClass (default): Uses Kubernetes PriorityClass (scheduling.k8s.io/v1) - PodPriorityClass: Uses PriorityClassName from PodTemplate (PodSpec.PriorityClassName) - FederatedPriorityClass: Uses Karmada FederatedPriorityClass (not yet implemented)\n\nPriorityClassName behavior:\n\nFor KubePriorityClass: - If specified: Uses the named Kubernetes PriorityClass - If empty: Uses cluster's global default PriorityClass - If neither exists: Sets priority=0 and preemptionPolicy=Never\n\nFor PodPriorityClass: - Uses PriorityClassName from PodTemplate - Falls back to global default if not found - If no valid PriorityClass found: Sets priority=0 and preemptionPolicy=Never\n\nFor FederatedPriorityClass: - Reserved for future use - Current behavior undefined", + 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,33 @@ 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) - 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\nPriorityClassName behavior:\n\nFor KubePriorityClass: - If specified: Uses the named Kubernetes PriorityClass - If empty: Uses cluster's global default PriorityClass - If neither exists: Sets priority=0 and preemptionPolicy=Never\n\nFor PodPriorityClass: - Uses PriorityClassName from PodTemplate - Falls back to global default if not found - If no valid PriorityClass found: Sets priority=0 and preemptionPolicy=Never\n\nFor FederatedPriorityClass: - Reserved for future use - Current behavior undefined", + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + } +} + func schema_pkg_apis_policy_v1alpha1_SpreadConstraint(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{