Skip to content

Commit

Permalink
Merge pull request #3788 from RainbowMango/pr_pp_add_Preemption
Browse files Browse the repository at this point in the history
Proposing PropagationPolicy Preemption API
  • Loading branch information
karmada-bot committed Jul 14, 2023
2 parents 2d22b74 + 122d6c0 commit ef87bd2
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 22 deletions.
10 changes: 9 additions & 1 deletion api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -15875,8 +15875,16 @@
"default": {},
"$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": {
"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",
"format": "int32"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -620,23 +620,31 @@ spec:
type: object
type: array
type: object
preemption:
default: Never
description: Preemption declares the behaviors for preempting. Valid
options are "Always" and "Never".
enum:
- Always
- Never
type: string
priority:
default: 0
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
In 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 by selector(resourceSelector.labelSelector)
- matching by selector(resourceSelector.labelSelector) has higher
priority than by APIVersion(resourceSelector.apiVersion) and Kind(resourceSelector.kind).
If 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 The higher the value, the higher the priority. Defaults
to zero."
preempted by following policies even with a higher priority. See
Preemption for more details. \n In 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 by selector(resourceSelector.labelSelector) - matching by selector(resourceSelector.labelSelector)
has higher priority than by APIVersion(resourceSelector.apiVersion)
and Kind(resourceSelector.kind). If 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 The higher the value, the
higher the priority. Defaults to zero."
format: int32
type: integer
propagateDeps:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,23 +616,31 @@ spec:
type: object
type: array
type: object
preemption:
default: Never
description: Preemption declares the behaviors for preempting. Valid
options are "Always" and "Never".
enum:
- Always
- Never
type: string
priority:
default: 0
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
In 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 by selector(resourceSelector.labelSelector)
- matching by selector(resourceSelector.labelSelector) has higher
priority than by APIVersion(resourceSelector.apiVersion) and Kind(resourceSelector.kind).
If 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 The higher the value, the higher the priority. Defaults
to zero."
preempted by following policies even with a higher priority. See
Preemption for more details. \n In 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 by selector(resourceSelector.labelSelector) - matching by selector(resourceSelector.labelSelector)
has higher priority than by APIVersion(resourceSelector.apiVersion)
and Kind(resourceSelector.kind). If 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 The higher the value, the
higher the priority. Defaults to zero."
format: int32
type: integer
propagateDeps:
Expand Down
33 changes: 33 additions & 0 deletions pkg/apis/policy/v1alpha1/propagation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type PropagationSpec struct {
// 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.
//
// In case of two policies have the same priority, the one with a more precise
// matching rules in ResourceSelectors wins:
Expand All @@ -91,6 +92,14 @@ type PropagationSpec struct {
// +kubebuilder:default=0
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)
// which must present before the current PropagationPolicy takes effect.
//
Expand Down Expand Up @@ -443,6 +452,30 @@ const (
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

// PropagationPolicyList contains a list of PropagationPolicy.
Expand Down
10 changes: 9 additions & 1 deletion pkg/generated/openapi/zz_generated.openapi.go

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

0 comments on commit ef87bd2

Please sign in to comment.