From 122d6c09044a59150b7011343e3c0c71377bfe04 Mon Sep 17 00:00:00 2001 From: RainbowMango Date: Wed, 12 Jul 2023 18:16:28 +0800 Subject: [PATCH] Proposing PropagationPolicy Preemption API. Signed-off-by: RainbowMango --- api/openapi-spec/swagger.json | 10 +++++- ...karmada.io_clusterpropagationpolicies.yaml | 28 ++++++++++------ ...policy.karmada.io_propagationpolicies.yaml | 28 ++++++++++------ pkg/apis/policy/v1alpha1/propagation_types.go | 33 +++++++++++++++++++ pkg/generated/openapi/zz_generated.openapi.go | 10 +++++- 5 files changed, 87 insertions(+), 22 deletions(-) diff --git a/api/openapi-spec/swagger.json b/api/openapi-spec/swagger.json index 7cf6bbd5e771..e5a45f8a63e2 100644 --- a/api/openapi-spec/swagger.json +++ b/api/openapi-spec/swagger.json @@ -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" }, 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 d981791b3401..4089b1c62b64 100644 --- a/charts/karmada/_crds/bases/policy/policy.karmada.io_clusterpropagationpolicies.yaml +++ b/charts/karmada/_crds/bases/policy/policy.karmada.io_clusterpropagationpolicies.yaml @@ -620,6 +620,14 @@ 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 @@ -627,16 +635,16 @@ spec: 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: 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 920ec7e381ff..defefade180d 100644 --- a/charts/karmada/_crds/bases/policy/policy.karmada.io_propagationpolicies.yaml +++ b/charts/karmada/_crds/bases/policy/policy.karmada.io_propagationpolicies.yaml @@ -616,6 +616,14 @@ 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 @@ -623,16 +631,16 @@ spec: 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: diff --git a/pkg/apis/policy/v1alpha1/propagation_types.go b/pkg/apis/policy/v1alpha1/propagation_types.go index 36de0a639992..00a702c1e87a 100644 --- a/pkg/apis/policy/v1alpha1/propagation_types.go +++ b/pkg/apis/policy/v1alpha1/propagation_types.go @@ -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: @@ -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. // @@ -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. diff --git a/pkg/generated/openapi/zz_generated.openapi.go b/pkg/generated/openapi/zz_generated.openapi.go index 81d1b9f1d876..a971e98b65fa 100755 --- a/pkg/generated/openapi/zz_generated.openapi.go +++ b/pkg/generated/openapi/zz_generated.openapi.go @@ -4282,11 +4282,19 @@ func schema_pkg_apis_policy_v1alpha1_PropagationSpec(ref common.ReferenceCallbac }, "priority": { 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"}, 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": { 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.",