From 8810a03fc9aea88ae06548d776c637eb625a2d75 Mon Sep 17 00:00:00 2001 From: "zhangxinjie.next" Date: Tue, 25 Jul 2023 14:53:24 +0800 Subject: [PATCH] feat: add ReschedulePolicy for pp/cpp --- ...admiral.io_clusterpropagationpolicies.yaml | 43 ++++++++++++++- ...re.kubeadmiral.io_propagationpolicies.yaml | 43 ++++++++++++++- .../generic_propagationpolicies.src.sh | 1 + .../core/v1alpha1/types_propagationpolicy.go | 52 +++++++++++++++++++ .../core/v1alpha1/zz_generated.deepcopy.go | 47 +++++++++++++++++ 5 files changed, 182 insertions(+), 4 deletions(-) diff --git a/config/crds/core.kubeadmiral.io_clusterpropagationpolicies.yaml b/config/crds/core.kubeadmiral.io_clusterpropagationpolicies.yaml index f37078463..2d8fc0dc7 100644 --- a/config/crds/core.kubeadmiral.io_clusterpropagationpolicies.yaml +++ b/config/crds/core.kubeadmiral.io_clusterpropagationpolicies.yaml @@ -160,7 +160,7 @@ spec: type: object type: array replicaRescheduling: - description: Configures behaviors related to replica rescheduling. Default set via a post-generation patch. See patch file for details. + description: 'Configures behaviors related to replica rescheduling. Default set via a post-generation patch. See patch file for details. Deprecated: Please use reschedulePolicy.disableRescheduling instead. This field will be removed in the next release.' properties: avoidDisruption: default: true @@ -168,6 +168,45 @@ spec: type: boolean type: object default: {} + reschedulePolicy: + default: + rescheduleWhen: + policyContentChanged: true + description: Configures behaviors related to rescheduling. + properties: + disableRescheduling: + description: DisableRescheduling determines if a federated object can be rescheduled. + type: boolean + replicaRescheduling: + description: Configures behaviors related to replica rescheduling. Default set via a post-generation patch. See patch file for details. + properties: + avoidDisruption: + default: true + description: If set to true, the scheduler will attempt to prevent migrating existing replicas during rescheduling. In order to do so, replica scheduling preferences might not be fully respected. If set to false, the scheduler will always rebalance the replicas based on the specified preferences, which might cause temporary service disruption. + type: boolean + type: object + default: {} + rescheduleWhen: + description: When the related objects should be subject to reschedule. + properties: + clusterApiResourcesChanged: + default: false + description: If set to true, changes to clusters' enabled list of api resources will trigger rescheduling. It set to false, the scheduler will reschedule only when other options are triggered or the replicas or the requested resources of the template changed. + type: boolean + clusterJoined: + default: false + description: If set to true, clusters joining the federation will trigger rescheduling. It set to false, the scheduler will reschedule only when other options are triggered or the replicas or the requested resources of the template changed. + type: boolean + clusterLabelsChanged: + default: false + description: If set to true, changes to cluster labels will trigger rescheduling. It set to false, the scheduler will reschedule only when other options are triggered or the replicas or the requested resources of the template changed. + type: boolean + policyContentChanged: + default: true + description: If set to true, the scheduler will trigger rescheduling when the semantics of the policy changes. For example, modifying placement, schedulingMode, maxClusters, clusterSelector, and other configurations related to scheduling (includes reschedulePolicy itself) will immediately trigger rescheduling. Modifying the labels, annotations, autoMigration configuration will not trigger rescheduling. It set to false, the scheduler will not reschedule when the policy content changes. + type: boolean + type: object + type: object schedulingMode: description: SchedulingMode determines the mode used for scheduling. enum: @@ -178,7 +217,7 @@ spec: description: Profile determines the scheduling profile to be used for scheduling type: string stickyCluster: - description: StickyCluster determines if a federated object can be rescheduled. + description: 'StickyCluster determines if a federated object can be rescheduled. Deprecated: Please use reschedulePolicy.disableRescheduling instead. This field will be removed in the next release.' type: boolean tolerations: description: Tolerations describe a set of cluster taints that the policy tolerates. diff --git a/config/crds/core.kubeadmiral.io_propagationpolicies.yaml b/config/crds/core.kubeadmiral.io_propagationpolicies.yaml index 424b87d86..c478763e8 100644 --- a/config/crds/core.kubeadmiral.io_propagationpolicies.yaml +++ b/config/crds/core.kubeadmiral.io_propagationpolicies.yaml @@ -160,7 +160,7 @@ spec: type: object type: array replicaRescheduling: - description: Configures behaviors related to replica rescheduling. Default set via a post-generation patch. See patch file for details. + description: 'Configures behaviors related to replica rescheduling. Default set via a post-generation patch. See patch file for details. Deprecated: Please use reschedulePolicy.disableRescheduling instead. This field will be removed in the next release.' properties: avoidDisruption: default: true @@ -168,6 +168,45 @@ spec: type: boolean type: object default: {} + reschedulePolicy: + default: + rescheduleWhen: + policyContentChanged: true + description: Configures behaviors related to rescheduling. + properties: + disableRescheduling: + description: DisableRescheduling determines if a federated object can be rescheduled. + type: boolean + replicaRescheduling: + description: Configures behaviors related to replica rescheduling. Default set via a post-generation patch. See patch file for details. + properties: + avoidDisruption: + default: true + description: If set to true, the scheduler will attempt to prevent migrating existing replicas during rescheduling. In order to do so, replica scheduling preferences might not be fully respected. If set to false, the scheduler will always rebalance the replicas based on the specified preferences, which might cause temporary service disruption. + type: boolean + type: object + default: {} + rescheduleWhen: + description: When the related objects should be subject to reschedule. + properties: + clusterApiResourcesChanged: + default: false + description: If set to true, changes to clusters' enabled list of api resources will trigger rescheduling. It set to false, the scheduler will reschedule only when other options are triggered or the replicas or the requested resources of the template changed. + type: boolean + clusterJoined: + default: false + description: If set to true, clusters joining the federation will trigger rescheduling. It set to false, the scheduler will reschedule only when other options are triggered or the replicas or the requested resources of the template changed. + type: boolean + clusterLabelsChanged: + default: false + description: If set to true, changes to cluster labels will trigger rescheduling. It set to false, the scheduler will reschedule only when other options are triggered or the replicas or the requested resources of the template changed. + type: boolean + policyContentChanged: + default: true + description: If set to true, the scheduler will trigger rescheduling when the semantics of the policy changes. For example, modifying placement, schedulingMode, maxClusters, clusterSelector, and other configurations related to scheduling (includes reschedulePolicy itself) will immediately trigger rescheduling. Modifying the labels, annotations, autoMigration configuration will not trigger rescheduling. It set to false, the scheduler will not reschedule when the policy content changes. + type: boolean + type: object + type: object schedulingMode: description: SchedulingMode determines the mode used for scheduling. enum: @@ -178,7 +217,7 @@ spec: description: Profile determines the scheduling profile to be used for scheduling type: string stickyCluster: - description: StickyCluster determines if a federated object can be rescheduled. + description: 'StickyCluster determines if a federated object can be rescheduled. Deprecated: Please use reschedulePolicy.disableRescheduling instead. This field will be removed in the next release.' type: boolean tolerations: description: Tolerations describe a set of cluster taints that the policy tolerates. diff --git a/config/crds/patches/generic_propagationpolicies.src.sh b/config/crds/patches/generic_propagationpolicies.src.sh index 7b3690d01..012d5b308 100644 --- a/config/crds/patches/generic_propagationpolicies.src.sh +++ b/config/crds/patches/generic_propagationpolicies.src.sh @@ -1,6 +1,7 @@ # controller-gen does not respect {} as default value for a struct field # issue: https://github.com/kubernetes-sigs/controller-tools/issues/622 yq eval -i '.spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.replicaRescheduling.default = {}' "$1" +yq eval -i '.spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.reschedulePolicy.properties.replicaRescheduling.default = {}' "$1" # policies are always referenced from labels, the value of which has limited length yq eval -i '.spec.versions[].schema.openAPIV3Schema.properties.metadata |= diff --git a/pkg/apis/core/v1alpha1/types_propagationpolicy.go b/pkg/apis/core/v1alpha1/types_propagationpolicy.go index 5773cb864..0135bc941 100644 --- a/pkg/apis/core/v1alpha1/types_propagationpolicy.go +++ b/pkg/apis/core/v1alpha1/types_propagationpolicy.go @@ -68,6 +68,7 @@ type PropagationPolicySpec struct { SchedulingMode SchedulingMode `json:"schedulingMode"` // StickyCluster determines if a federated object can be rescheduled. // +optional + // Deprecated: Please use reschedulePolicy.disableRescheduling instead. This field will be removed in the next release. StickyCluster bool `json:"stickyCluster"` // ClusterSelector is a label query over clusters to consider for scheduling. @@ -106,7 +107,13 @@ type PropagationPolicySpec struct { // +optional // Default set via a post-generation patch. // See patch file for details. + // Deprecated: Please use reschedulePolicy.disableRescheduling instead. This field will be removed in the next release. ReplicaRescheduling *ReplicaRescheduling `json:"replicaRescheduling,omitempty"` + + // Configures behaviors related to rescheduling. + // +optional + // +kubebuilder:default:={rescheduleWhen:{policyContentChanged:true}} + ReschedulePolicy *ReschedulePolicy `json:"reschedulePolicy,omitempty"` } type PropagationPolicyStatus struct { @@ -187,3 +194,48 @@ type ReplicaRescheduling struct { // +kubebuilder:default:=true AvoidDisruption bool `json:"avoidDisruption"` } + +// ReschedulePolicy describes the rescheduling policy. +type ReschedulePolicy struct { + // DisableRescheduling determines if a federated object can be rescheduled. + // +optional + DisableRescheduling bool `json:"disableRescheduling,omitempty"` + // When the related objects should be subject to reschedule. + // +optional + Trigger *RescheduleTrigger `json:"rescheduleWhen,omitempty"` + // Configures behaviors related to replica rescheduling. + // +optional + // Default set via a post-generation patch. + // See patch file for details. + ReplicaRescheduling *ReplicaRescheduling `json:"replicaRescheduling,omitempty"` +} + +// RescheduleTrigger configures the criteria for triggering rescheduling. +type RescheduleTrigger struct { + // If set to true, the scheduler will trigger rescheduling when the semantics of the policy changes. For example, + // modifying placement, schedulingMode, maxClusters, clusterSelector, and other configurations related to + // scheduling (includes reschedulePolicy itself) will immediately trigger rescheduling. Modifying the labels, + // annotations, autoMigration configuration will not trigger rescheduling. + // It set to false, the scheduler will not reschedule when the policy content changes. + // +optional + // +kubebuilder:default:=true + PolicyContentChanged bool `json:"policyContentChanged"` + // If set to true, clusters joining the federation will trigger rescheduling. + // It set to false, the scheduler will reschedule only when other options are triggered or the replicas or the + // requested resources of the template changed. + // +optional + // +kubebuilder:default:=false + ClusterJoined bool `json:"clusterJoined"` + // If set to true, changes to cluster labels will trigger rescheduling. + // It set to false, the scheduler will reschedule only when other options are triggered or the replicas or the + // requested resources of the template changed. + // +optional + // +kubebuilder:default:=false + ClusterLabelsChanged bool `json:"clusterLabelsChanged"` + // If set to true, changes to clusters' enabled list of api resources will trigger rescheduling. + // It set to false, the scheduler will reschedule only when other options are triggered or the replicas or the + // requested resources of the template changed. + // +optional + // +kubebuilder:default:=false + ClusterApiResourcesChanged bool `json:"clusterApiResourcesChanged"` +} diff --git a/pkg/apis/core/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/core/v1alpha1/zz_generated.deepcopy.go index 1226a6c04..1362b8009 100644 --- a/pkg/apis/core/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/core/v1alpha1/zz_generated.deepcopy.go @@ -1613,6 +1613,11 @@ func (in *PropagationPolicySpec) DeepCopyInto(out *PropagationPolicySpec) { *out = new(ReplicaRescheduling) **out = **in } + if in.ReschedulePolicy != nil { + in, out := &in.ReschedulePolicy, &out.ReschedulePolicy + *out = new(ReschedulePolicy) + (*in).DeepCopyInto(*out) + } return } @@ -1675,6 +1680,48 @@ func (in *ReplicaRescheduling) DeepCopy() *ReplicaRescheduling { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ReschedulePolicy) DeepCopyInto(out *ReschedulePolicy) { + *out = *in + if in.Trigger != nil { + in, out := &in.Trigger, &out.Trigger + *out = new(RescheduleTrigger) + **out = **in + } + if in.ReplicaRescheduling != nil { + in, out := &in.ReplicaRescheduling, &out.ReplicaRescheduling + *out = new(ReplicaRescheduling) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ReschedulePolicy. +func (in *ReschedulePolicy) DeepCopy() *ReschedulePolicy { + if in == nil { + return nil + } + out := new(ReschedulePolicy) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RescheduleTrigger) DeepCopyInto(out *RescheduleTrigger) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RescheduleTrigger. +func (in *RescheduleTrigger) DeepCopy() *RescheduleTrigger { + if in == nil { + return nil + } + out := new(RescheduleTrigger) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Resources) DeepCopyInto(out *Resources) { *out = *in