Skip to content

Commit

Permalink
feat: add ReschedulePolicy for pp/cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
JackZxj committed Jul 25, 2023
1 parent ea75f7c commit 8810a03
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 4 deletions.
43 changes: 41 additions & 2 deletions config/crds/core.kubeadmiral.io_clusterpropagationpolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,53 @@ 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
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: {}
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:
Expand All @@ -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.
Expand Down
43 changes: 41 additions & 2 deletions config/crds/core.kubeadmiral.io_propagationpolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,53 @@ 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
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: {}
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:
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions config/crds/patches/generic_propagationpolicies.src.sh
Original file line number Diff line number Diff line change
@@ -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 |=
Expand Down
52 changes: 52 additions & 0 deletions pkg/apis/core/v1alpha1/types_propagationpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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"`

Check failure on line 240 in pkg/apis/core/v1alpha1/types_propagationpolicy.go

View workflow job for this annotation

GitHub Actions / lint

ST1003: struct field ClusterApiResourcesChanged should be ClusterAPIResourcesChanged (stylecheck)

Check failure on line 240 in pkg/apis/core/v1alpha1/types_propagationpolicy.go

View workflow job for this annotation

GitHub Actions / lint

json(goCamel): got 'clusterApiResourcesChanged' want 'clusterAPIResourcesChanged' (tagliatelle)
}
47 changes: 47 additions & 0 deletions pkg/apis/core/v1alpha1/zz_generated.deepcopy.go

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

0 comments on commit 8810a03

Please sign in to comment.