Merge pull request #3788 from RainbowMango/pr_pp_add_Preemption

Proposing PropagationPolicy Preemption API
This commit is contained in:
karmada-bot 2023-07-14 11:45:28 +08:00 committed by GitHub
commit ef87bd2264
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 87 additions and 22 deletions

View File

@ -15875,8 +15875,16 @@
"default": {}, "default": {},
"$ref": "#/definitions/com.github.karmada-io.karmada.pkg.apis.policy.v1alpha1.Placement" "$ref": "#/definitions/com.github.karmada-io.karmada.pkg.apis.policy.v1alpha1.Placement"
}, },
"preemption": {
"description": "Preemption declares the behaviors for preempting. Valid options are \"Always\" and \"Never\".\n\n\nPossible enum values:\n - `\"Always\"` means that preemption is allowed. If it is applied to a PropagationPolicy, it can preempt any resource as per Priority, regardless of whether it has been claimed by a PropagationPolicy or a ClusterPropagationPolicy, as long as it can match the rules defined in ResourceSelector. In addition, if a resource has already been claimed by a ClusterPropagationPolicy, the PropagationPolicy can still preempt it without considering Priority. If it is applied to a ClusterPropagationPolicy, it can only preempt from ClusterPropagationPolicy, and from PropagationPolicy is not allowed.\n - `\"Never\"` means that a PropagationPolicy(ClusterPropagationPolicy) never preempts resources.",
"type": "string",
"enum": [
"Always",
"Never"
]
},
"priority": { "priority": {
"description": "Priority indicates the importance of a policy(PropagationPolicy or ClusterPropagationPolicy). A policy will be applied for the matched resource templates if there is no other policies with higher priority at the point of the resource template be processed. Once a resource template has been claimed by a policy, by default it will not be preempted by following policies even with a higher priority.\n\nIn case of two policies have the same priority, the one with a more precise matching rules in ResourceSelectors wins: - matching by name(resourceSelector.name) has higher priority than\n by selector(resourceSelector.labelSelector)\n- matching by selector(resourceSelector.labelSelector) has higher priority\n than by APIVersion(resourceSelector.apiVersion) and Kind(resourceSelector.kind).\nIf there is still no winner at this point, the one with the lower alphabetic order wins, e.g. policy 'bar' has higher priority than 'foo'.\n\nThe higher the value, the higher the priority. Defaults to zero.", "description": "Priority indicates the importance of a policy(PropagationPolicy or ClusterPropagationPolicy). A policy will be applied for the matched resource templates if there is no other policies with higher priority at the point of the resource template be processed. Once a resource template has been claimed by a policy, by default it will not be preempted by following policies even with a higher priority. See Preemption for more details.\n\nIn case of two policies have the same priority, the one with a more precise matching rules in ResourceSelectors wins: - matching by name(resourceSelector.name) has higher priority than\n by selector(resourceSelector.labelSelector)\n- matching by selector(resourceSelector.labelSelector) has higher priority\n than by APIVersion(resourceSelector.apiVersion) and Kind(resourceSelector.kind).\nIf there is still no winner at this point, the one with the lower alphabetic order wins, e.g. policy 'bar' has higher priority than 'foo'.\n\nThe higher the value, the higher the priority. Defaults to zero.",
"type": "integer", "type": "integer",
"format": "int32" "format": "int32"
}, },

View File

@ -620,6 +620,14 @@ spec:
type: object type: object
type: array type: array
type: object type: object
preemption:
default: Never
description: Preemption declares the behaviors for preempting. Valid
options are "Always" and "Never".
enum:
- Always
- Never
type: string
priority: priority:
default: 0 default: 0
description: "Priority indicates the importance of a policy(PropagationPolicy description: "Priority indicates the importance of a policy(PropagationPolicy
@ -627,16 +635,16 @@ spec:
resource templates if there is no other policies with higher priority resource templates if there is no other policies with higher priority
at the point of the resource template be processed. Once a resource at the point of the resource template be processed. Once a resource
template has been claimed by a policy, by default it will not be template has been claimed by a policy, by default it will not be
preempted by following policies even with a higher priority. \n preempted by following policies even with a higher priority. See
In case of two policies have the same priority, the one with a more Preemption for more details. \n In case of two policies have the
precise matching rules in ResourceSelectors wins: - matching by same priority, the one with a more precise matching rules in ResourceSelectors
name(resourceSelector.name) has higher priority than by selector(resourceSelector.labelSelector) wins: - matching by name(resourceSelector.name) has higher priority
- matching by selector(resourceSelector.labelSelector) has higher than by selector(resourceSelector.labelSelector) - matching by selector(resourceSelector.labelSelector)
priority than by APIVersion(resourceSelector.apiVersion) and Kind(resourceSelector.kind). has higher priority than by APIVersion(resourceSelector.apiVersion)
If there is still no winner at this point, the one with the lower and Kind(resourceSelector.kind). If there is still no winner at
alphabetic order wins, e.g. policy 'bar' has higher priority than this point, the one with the lower alphabetic order wins, e.g. policy
'foo'. \n The higher the value, the higher the priority. Defaults 'bar' has higher priority than 'foo'. \n The higher the value, the
to zero." higher the priority. Defaults to zero."
format: int32 format: int32
type: integer type: integer
propagateDeps: propagateDeps:

View File

@ -616,6 +616,14 @@ spec:
type: object type: object
type: array type: array
type: object type: object
preemption:
default: Never
description: Preemption declares the behaviors for preempting. Valid
options are "Always" and "Never".
enum:
- Always
- Never
type: string
priority: priority:
default: 0 default: 0
description: "Priority indicates the importance of a policy(PropagationPolicy description: "Priority indicates the importance of a policy(PropagationPolicy
@ -623,16 +631,16 @@ spec:
resource templates if there is no other policies with higher priority resource templates if there is no other policies with higher priority
at the point of the resource template be processed. Once a resource at the point of the resource template be processed. Once a resource
template has been claimed by a policy, by default it will not be template has been claimed by a policy, by default it will not be
preempted by following policies even with a higher priority. \n preempted by following policies even with a higher priority. See
In case of two policies have the same priority, the one with a more Preemption for more details. \n In case of two policies have the
precise matching rules in ResourceSelectors wins: - matching by same priority, the one with a more precise matching rules in ResourceSelectors
name(resourceSelector.name) has higher priority than by selector(resourceSelector.labelSelector) wins: - matching by name(resourceSelector.name) has higher priority
- matching by selector(resourceSelector.labelSelector) has higher than by selector(resourceSelector.labelSelector) - matching by selector(resourceSelector.labelSelector)
priority than by APIVersion(resourceSelector.apiVersion) and Kind(resourceSelector.kind). has higher priority than by APIVersion(resourceSelector.apiVersion)
If there is still no winner at this point, the one with the lower and Kind(resourceSelector.kind). If there is still no winner at
alphabetic order wins, e.g. policy 'bar' has higher priority than this point, the one with the lower alphabetic order wins, e.g. policy
'foo'. \n The higher the value, the higher the priority. Defaults 'bar' has higher priority than 'foo'. \n The higher the value, the
to zero." higher the priority. Defaults to zero."
format: int32 format: int32
type: integer type: integer
propagateDeps: propagateDeps:

View File

@ -76,6 +76,7 @@ type PropagationSpec struct {
// template be processed. // template be processed.
// Once a resource template has been claimed by a policy, by default it will // Once a resource template has been claimed by a policy, by default it will
// not be preempted by following policies even with a higher priority. // not be preempted by following policies even with a higher priority.
// See Preemption for more details.
// //
// In case of two policies have the same priority, the one with a more precise // In case of two policies have the same priority, the one with a more precise
// matching rules in ResourceSelectors wins: // matching rules in ResourceSelectors wins:
@ -91,6 +92,14 @@ type PropagationSpec struct {
// +kubebuilder:default=0 // +kubebuilder:default=0
Priority *int32 `json:"priority,omitempty"` Priority *int32 `json:"priority,omitempty"`
// Preemption declares the behaviors for preempting.
// Valid options are "Always" and "Never".
//
// +kubebuilder:default="Never"
// +kubebuilder:validation:Enum=Always;Never
// +optional
Preemption PreemptionBehavior `json:"preemption,omitempty"`
// DependentOverrides represents the list of overrides(OverridePolicy) // DependentOverrides represents the list of overrides(OverridePolicy)
// which must present before the current PropagationPolicy takes effect. // which must present before the current PropagationPolicy takes effect.
// //
@ -443,6 +452,30 @@ const (
DynamicWeightByAvailableReplicas DynamicWeightFactor = "AvailableReplicas" DynamicWeightByAvailableReplicas DynamicWeightFactor = "AvailableReplicas"
) )
// PreemptionBehavior describes whether and how to preempt resources that are
// claimed by lower-priority PropagationPolicy(ClusterPropagationPolicy).
// +enum
type PreemptionBehavior string
const (
// PreemptAlways means that preemption is allowed.
//
// If it is applied to a PropagationPolicy, it can preempt any resource as
// per Priority, regardless of whether it has been claimed by a PropagationPolicy
// or a ClusterPropagationPolicy, as long as it can match the rules defined
// in ResourceSelector. In addition, if a resource has already been claimed
// by a ClusterPropagationPolicy, the PropagationPolicy can still preempt it
// without considering Priority.
//
// If it is applied to a ClusterPropagationPolicy, it can only preempt from
// ClusterPropagationPolicy, and from PropagationPolicy is not allowed.
PreemptAlways PreemptionBehavior = "Always"
// PreemptNever means that a PropagationPolicy(ClusterPropagationPolicy) never
// preempts resources.
PreemptNever PreemptionBehavior = "Never"
)
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// PropagationPolicyList contains a list of PropagationPolicy. // PropagationPolicyList contains a list of PropagationPolicy.

View File

@ -4282,11 +4282,19 @@ func schema_pkg_apis_policy_v1alpha1_PropagationSpec(ref common.ReferenceCallbac
}, },
"priority": { "priority": {
SchemaProps: spec.SchemaProps{ SchemaProps: spec.SchemaProps{
Description: "Priority indicates the importance of a policy(PropagationPolicy or ClusterPropagationPolicy). A policy will be applied for the matched resource templates if there is no other policies with higher priority at the point of the resource template be processed. Once a resource template has been claimed by a policy, by default it will not be preempted by following policies even with a higher priority.\n\nIn case of two policies have the same priority, the one with a more precise matching rules in ResourceSelectors wins: - matching by name(resourceSelector.name) has higher priority than\n by selector(resourceSelector.labelSelector)\n- matching by selector(resourceSelector.labelSelector) has higher priority\n than by APIVersion(resourceSelector.apiVersion) and Kind(resourceSelector.kind).\nIf there is still no winner at this point, the one with the lower alphabetic order wins, e.g. policy 'bar' has higher priority than 'foo'.\n\nThe higher the value, the higher the priority. Defaults to zero.", Description: "Priority indicates the importance of a policy(PropagationPolicy or ClusterPropagationPolicy). A policy will be applied for the matched resource templates if there is no other policies with higher priority at the point of the resource template be processed. Once a resource template has been claimed by a policy, by default it will not be preempted by following policies even with a higher priority. See Preemption for more details.\n\nIn case of two policies have the same priority, the one with a more precise matching rules in ResourceSelectors wins: - matching by name(resourceSelector.name) has higher priority than\n by selector(resourceSelector.labelSelector)\n- matching by selector(resourceSelector.labelSelector) has higher priority\n than by APIVersion(resourceSelector.apiVersion) and Kind(resourceSelector.kind).\nIf there is still no winner at this point, the one with the lower alphabetic order wins, e.g. policy 'bar' has higher priority than 'foo'.\n\nThe higher the value, the higher the priority. Defaults to zero.",
Type: []string{"integer"}, Type: []string{"integer"},
Format: "int32", Format: "int32",
}, },
}, },
"preemption": {
SchemaProps: spec.SchemaProps{
Description: "Preemption declares the behaviors for preempting. Valid options are \"Always\" and \"Never\".\n\n\nPossible enum values:\n - `\"Always\"` means that preemption is allowed. If it is applied to a PropagationPolicy, it can preempt any resource as per Priority, regardless of whether it has been claimed by a PropagationPolicy or a ClusterPropagationPolicy, as long as it can match the rules defined in ResourceSelector. In addition, if a resource has already been claimed by a ClusterPropagationPolicy, the PropagationPolicy can still preempt it without considering Priority. If it is applied to a ClusterPropagationPolicy, it can only preempt from ClusterPropagationPolicy, and from PropagationPolicy is not allowed.\n - `\"Never\"` means that a PropagationPolicy(ClusterPropagationPolicy) never preempts resources.",
Type: []string{"string"},
Format: "",
Enum: []interface{}{"Always", "Never"},
},
},
"dependentOverrides": { "dependentOverrides": {
SchemaProps: spec.SchemaProps{ SchemaProps: spec.SchemaProps{
Description: "DependentOverrides represents the list of overrides(OverridePolicy) which must present before the current PropagationPolicy takes effect.\n\nIt used to explicitly specify overrides which current PropagationPolicy rely on. A typical scenario is the users create OverridePolicy(ies) and resources at the same time, they want to ensure the new-created policies would be adopted.\n\nNote: For the overrides, OverridePolicy(ies) in current namespace and ClusterOverridePolicy(ies), which not present in this list will still be applied if they matches the resources.", Description: "DependentOverrides represents the list of overrides(OverridePolicy) which must present before the current PropagationPolicy takes effect.\n\nIt used to explicitly specify overrides which current PropagationPolicy rely on. A typical scenario is the users create OverridePolicy(ies) and resources at the same time, they want to ensure the new-created policies would be adopted.\n\nNote: For the overrides, OverridePolicy(ies) in current namespace and ClusterOverridePolicy(ies), which not present in this list will still be applied if they matches the resources.",