1- # Default Even Pod Spreading
1+ # Default Pod Topology Spread
22
33## Table of Contents
44
1414 - [ Story 2] ( #story-2 )
1515 - [ Implementation Details/Notes/Constraints] ( #implementation-detailsnotesconstraints )
1616 - [ Feature gate] ( #feature-gate )
17- - [ Relationship with " ; DefaultPodTopologySpread " ; plugin] ( #relationship-with-defaultpodtopologyspread -plugin )
17+ - [ Relationship with " ; SelectorSpread " ; plugin] ( #relationship-with-selectorspread -plugin )
1818 - [ Risks and Mitigations] ( #risks-and-mitigations )
1919- [ Design Details] ( #design-details )
2020 - [ API] ( #api )
2121 - [ Default constraints] ( #default-constraints )
2222 - [ How user stories are addressed] ( #how-user-stories-are-addressed )
2323 - [ Implementation Details] ( #implementation-details )
24- - [ In the metadata/predicates/priorities flow] ( #in-the-metadatapredicatespriorities-flow )
25- - [ In the scheduler framework] ( #in-the-scheduler-framework )
2624 - [ Test Plan] ( #test-plan )
2725 - [ Graduation Criteria] ( #graduation-criteria )
2826 - [ Alpha (v1.19):] ( #alpha-v119 )
3836- [ ] Test plan is in place, giving consideration to SIG Architecture and SIG Testing input
3937- [ ] Graduation criteria is in place
4038- [ ] "Implementation History" section is up-to-date for milestone
41- - [ ] User-facing documentation has been created in [ kubernetes/website] , for publication to [ kubernetes.io]
42- - [ ] Supporting documentation e.g., additional design documents, links to mailing list discussions/SIG meetings, relevant PRs/issues, release notes
39+ - [x ] User-facing documentation has been created in [ kubernetes/website] , for publication to [ kubernetes.io]
40+ - [x ] Supporting documentation e.g., additional design documents, links to mailing list discussions/SIG meetings, relevant PRs/issues, release notes
4341
4442## Summary
4543
46- With [ Even Pods Spreading ] ( /keps/sig-scheduling/20190221-even-pods-spreading.md ) ,
44+ With [ Pod Topology Spread ] ( /keps/sig-scheduling/895-pod-topology-spread ) ,
4745workload authors can define spreading rules for their loads based on the topology of the clusters.
4846The spreading rules are defined in the ` PodSpec ` , thus they are tied to the pod.
4947
@@ -76,7 +74,7 @@ them suitable to provide default spreading constraints for all workloads in thei
7674### Non-Goals
7775
7876- Set defaults for specific namespaces or according to other selectors.
79- - Removal of ` DefaultPodTopologySpread ` plugin.
77+ - Removal of ` SelectorSpread ` plugin.
8078
8179## Proposal
8280
@@ -85,7 +83,7 @@ them suitable to provide default spreading constraints for all workloads in thei
8583#### Story 1
8684
8785As a cluster operator, I want to set default spreading constraints for workloads in the cluster.
88- Currently, ` SelectorSpreadPriority ` provides a canned priority that spreads across nodes
86+ Currently, ` SelectorSpread ` plugin provides a canned scoring that spreads across nodes
8987and zones (` topology.kubernetes.io/zone ` ). However, the nodes in my cluster have custom topology
9088keys (for physical host, rack, etc.).
9189
@@ -101,45 +99,45 @@ As a workload author, I want to spread the workload in the cluster, but:
10199#### Feature gate
102100
103101Setting a default for ` PodTopologySpread ` will be guarded with the feature gate
104- ` DefaultEvenPodsSpread ` . This feature gate will depend on ` EvenPodsSpread ` to also be enabled .
102+ ` DefaultPodTopologySpread ` .
105103
106- #### Relationship with "DefaultPodTopologySpread " plugin
104+ #### Relationship with "SelectorSpread " plugin
107105
108- Note that Default ` topologySpreadConstraints ` has a similar effect to ` DefaultPodTopologySpread `
106+ Note that Default ` topologySpreadConstraints ` has a similar effect to ` SelectorSpread `
109107plugin (` SelectorSpreadingPriority ` when using the Policy API).
110108Given that the latter is not configurable, they could return conflicting priorities, which
111109may not be the intention of the cluster operator or workload author. On the other hand, a proper
112- default for ` topologySpreadConstraints ` could provide the same score as
113- ` DefaultPodTopologySpread ` . Thus, there's no need for the features to co-exist.
110+ default for ` topologySpreadConstraints ` can provide the same score as
111+ ` SelectorSpread ` . Thus, there's no need for the features to co-exist.
114112
115113When the feature gate is enabled:
116114
117- - K8s will set Default ` topologySpreadConstraints ` and remove ` DefaultPodTopologySpread ` from the
115+ - K8s will set Default ` topologySpreadConstraints ` and remove ` SelectorSpread ` from the
118116k8s providers (` DefaultProvider ` and ` ClusterAutoscalerProvider ` ). The
119- [ Default] ( #default-constraints ) will have a similar effect .
120- - When a policy is used, ` SelectorSpreadingPriority ` will map to ` PodTopologySpread ` .
121- - When setting plugins in the Component Config API, plugins are added as requested. Since an
122- operator is manually enabling the plugins, we assume they are aware of their intentions .
117+ [ Default constraints ] ( #default-constraints ) will produce a similar score .
118+ - When setting plugins in the Component Config API, operators can specify plugins they want to enable .
119+ Since this is a manual operation, if an operator decides to enable both plugins, this is respected.
120+ - [ Beta ] When using the Policy API, ` SelectorSpreadingPriority ` will map to ` PodTopologySpread ` .
123121
124122### Risks and Mitigations
125123
126124The ` PodTopologySpread ` plugin has some overhead compared to other plugins. We currently ensure that
127125pods that don't use the feature get minimally affected. After Default ` topologySpreadConstraints `
128126is rolled out, all pods will run through the plugin.
129127We should ensure that the running overhead is not significantly higher than
130- ` DefaultPodTopologySpread ` with the k8s Default.
128+ ` SelectorSpread ` with the k8s Default.
131129
132130## Design Details
133131
134132### API
135133
136- A new structure ` Args ` is introduced in ` pkg/scheduler/framework/plugins/podtopologyspread ` .
134+ A new structure ` PodTopologySpreadArgs ` is introduced in ` pkg/scheduler/apis/config/ ` .
137135Values are decoded from the ` pluginConfig ` slice in the kube-scheduler Component Config and used in
138136` podtopologyspread.New ` .
139137
140138``` go
141- // pkg/scheduler/framework/plugins/podtopologyspread/plugin .go
142- type Args struct {
139+ // pkg/scheduler/apis/config/types_pluginargs .go
140+ type PodTopologySpreadArgs struct {
143141 // DefaultConstraints defines topology spread constraints to be applied to pods
144142 // that don't define any in `pod.spec.topologySpreadConstraints`. Pod selectors must
145143 // be empty, as they are deduced from the resources that the pod belongs to
@@ -168,6 +166,12 @@ defaultConstraints:
168166 whenUnsatisfiable : ScheduleAnyway
169167` ` `
170168
169+ An operator can choose to disable the default constraints using:
170+
171+ ` ` ` yaml
172+ defaultConstraints : []
173+ ` ` `
174+
171175### How user stories are addressed
172176
173177Let's say we have a cluster that has a topology based on physical hosts and racks.
@@ -225,21 +229,15 @@ topologySpreadConstraints:
225229 app: demo
226230` ` `
227231
228- Please note that these constraints are honored internally in the scheduler, but they are NOT
232+ Please note that these constraints get applied internally in the scheduler, but they are NOT
229233persisted in the PodSpec via API Server.
230234
231235# ## Implementation Details
232236
233- # ### In the metadata/predicates/priorities flow
234-
235- 1. Calculate the spreading constraints for the pod as part of the metadata calculation.
236- Use the constraints provided by the pod or calculate the default ones if they don't provide any.
237- 1. When running the predicates or priorities, use the constraints stored in the metadata.
238-
239- # ### In the scheduler framework
240-
2412371. Calculate spreading constraints for the pod in the `PreFilter` extension point. Store them
242- in the `PluginContext`.
238+ in the `PluginContext`. The constraints are obtained from `.spec.topologySpreadConstraints`. If
239+ they are not defined, a default is calculated from the plugin's default constraints, using the
240+ selectors of the Services, ReplicaSets, StatefulSets or ReplicationControllers the pod belongs to.
2432411. In the `Filter` and `Score` extension points, use the stored spreading constraints instead of
244242 the ones defined by the pod.
245243
@@ -257,11 +255,11 @@ To ensure this feature to be rolled out in high quality. Following tests are man
257255# ### Alpha (v1.19):
258256
259257- [x] Args struct for `podtopologyspread.New`.
260- - [ ] Defaults and validation.
261- - [ ] Score extension point implementation. Add support for `maxSkew`.
258+ - [x ] Defaults and validation.
259+ - [x ] Score extension point implementation. Add support for `maxSkew`.
262260- [x] Filter extension point implementation.
263- - [ ] Disabling `DefaultPodTopologySpread ` when the feature is enabled.
264- - [ ] Test cases mentioned in the [Test Plan](#test-plan).
261+ - [x ] Disabling `SelectorSpread ` when the feature is enabled.
262+ - [x] Unit, Integration and benchmark test cases mentioned in the [Test Plan](#test-plan).
265263
266264# # Implementation History
267265
@@ -271,7 +269,7 @@ To ensure this feature to be rolled out in high quality. Following tests are man
271269
272270# # Alternatives
273271
274- - Make the topology keys used in `SelectorSpreadingPriority ` configurable.
272+ - Make the topology keys used in `SelectorSpread ` configurable.
275273
276274 While this moves the scheduler in the right direction, there are two problems :
277275
@@ -282,5 +280,4 @@ To ensure this feature to be rolled out in high quality. Following tests are man
282280
283281 This approach would likely allow us to provide a more flexible interface that
284282 can set defaults for specific namespaces or with other selectors. However, that
285- wouldn't allow us to replace `SelectorSpreadingPriority` with
286- ` EvenPodsSpreading` .
283+ wouldn't allow us to replace `SelectorSpread` with `PodTopologySpread`.
0 commit comments