Skip to content

Commit 9044007

Browse files
authored
Merge pull request #4069 from sanposhiho/matchlabelselector-remaining
fix(kep-3633): redesign matchLabelSelectors as matchLabelKeys + mismatchLabelKeys
2 parents d89ebb1 + b080ba2 commit 9044007

File tree

2 files changed

+50
-45
lines changed

2 files changed

+50
-45
lines changed

keps/sig-scheduling/3633-matchlabelselectors-to-podaffinity/README.md renamed to keps/sig-scheduling/3633-matchlabelkeys-to-podaffinity/README.md

+48-43
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ If none of those approvers are still appropriate, then changes to that list
5858
should be approved by the remaining approvers and/or the owning SIG (or
5959
SIG Architecture for cross-cutting KEPs).
6060
-->
61-
# KEP-3633: Introduce MatchLabelSelectors to PodAffinity and PodAntiAffinity
61+
# KEP-3633: Introduce MatchLabelKeys and MismatchLabelKeys to PodAffinity and PodAntiAffinity
6262

6363
<!--
6464
This is the title of your KEP. Keep it short, simple, and descriptive. A good
@@ -178,7 +178,7 @@ updates.
178178
[documentation style guide]: https://github.com/kubernetes/community/blob/master/contributors/guide/style-guide.md
179179
-->
180180

181-
This KEP proposes introducing a complementary field `MatchLabelSelectors` to `PodAffinityTerm`.
181+
This KEP proposes introducing a complementary field `MatchLabelKeys` to `PodAffinityTerm`.
182182
This enables users to finely control the scope where Pods are expected to co-exist (PodAffinity)
183183
or not (PodAntiAffinity), on top of the existing `LabelSelector`.
184184

@@ -210,7 +210,7 @@ The same issue applies to other scheduling directives as well. For example, Matc
210210

211211
### Goals
212212

213-
- Introduce `MatchLabelSelectors` in `PodAffinityTerm` to let users define the scope where Pods are evaluated in required and preferred Pod(Anti)Affinity.
213+
- Introduce `MatchLabelKeys` and `MismatchLabelKeys` in `PodAffinityTerm` to let users define the scope where Pods are evaluated in required and preferred Pod(Anti)Affinity.
214214

215215
### Non-Goals
216216

@@ -219,7 +219,7 @@ What is out of scope for this KEP? Listing non-goals helps to focus discussion
219219
and make progress.
220220
-->
221221

222-
- Apply additional internal labels when evaluating `MatchLabelSelectors`
222+
- Apply additional internal labels when evaluating `MatchLabelKeys` or `MismatchLabelKeys`
223223

224224
## Proposal
225225

@@ -266,9 +266,8 @@ metadata:
266266
values:
267267
- database
268268
topologyKey: topology.kubernetes.io/zone
269-
matchLabelSelectors: # ADDED
270-
- key: pod-template-hash
271-
operator: In
269+
matchLabelKeys: # ADDED
270+
- pod-template-hash
272271
```
273272
274273
#### Story 2
@@ -282,15 +281,13 @@ By applying the following affinity globally using a mutating webhook, the cluste
282281
affinity:
283282
podAffinity: # ensures the pods of this tenant land on the same node pool
284283
requiredDuringSchedulingIgnoredDuringExecution:
285-
- matchLabelSelectors:
286-
- key: tenant
287-
operator: In
284+
- matchLabelKeys:
285+
- tenant
288286
topologyKey: node-pool
289287
podAntiAffinity: # ensures only Pods from this tenant lands on the same node pool
290288
requiredDuringSchedulingIgnoredDuringExecution:
291-
- matchLabelSelectors:
292-
- key: tenant
293-
operator: NotIn
289+
- mismatchLabelKeys:
290+
- tenant
294291
labelSelector:
295292
matchExpressions:
296293
- key: tenant
@@ -328,7 +325,7 @@ Consider including folks who also work outside the SIG or subproject.
328325
-->
329326

330327
In addition to using `pod-template-hash` added by the Deployment controller,
331-
users can also provide the customized key in `MatchLabelSelectors.Key` to identify
328+
users can also provide the customized key in `matchLabelKeys` to identify
332329
which pods should be grouped. If so, the user needs to ensure that it is
333330
correct and not duplicated with other unrelated workloads.
334331

@@ -341,17 +338,16 @@ required) or even code snippets. If there's any ambiguity about HOW your
341338
proposal will be implemented, this is the place to discuss them.
342339
-->
343340

344-
A new optional field `MatchLabelSelectors` is introduced to `PodAffinityTerm`.
341+
A new optional fields `matchLabelKeys` and `mismatchLabelKeys` are introduced to `PodAffinityTerm`.
345342

346343
```go
347-
type LabelSelectorOperator string
348-
349344
type MatchLabelSelector struct {
350345
// Key is used to lookup value from the incoming pod labels,
351346
// and that key-value label is merged with `LabelSelector`.
352347
// Key that doesn't exist in the incoming pod labels will be ignored.
353348
Key string
354349
// Operator defines how key-value, fetched via the above `Keys`, is merged into LabelSelector.
350+
// Only `In` and `NotIn` are expected.
355351
// If Operator is `In`, `key in (value)` is merged with LabelSelector.
356352
// If Operator is `NotIn`, `key notin (value)` is merged with LabelSelector.
357353
//
@@ -365,21 +361,30 @@ type PodAffinityTerm struct {
365361
TopologyKey string
366362
NamespaceSelector *metav1.LabelSelector
367363

368-
// MatchLabelSelectors is a set of pod label keys to select the group of existing pods
369-
// which pods will be taken into consideration for the incoming pod's pod (anti) affinity.
370-
// The default value is empty.
371-
// +optional
372-
MatchLabelSelectors []strinMatchLabelSelectorg
364+
// MatchLabelKeys is a set of pod label keys to select which pods will
365+
// be taken into consideration. The keys are used to lookup values from the
366+
// incoming pod labels, those key-value labels are merged with `LabelSelector` as `key in (value)`
367+
// to select the group of existing pods which pods will be taken into consideration
368+
// for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming
369+
// pod labels will be ignored. The default value is empty.
370+
// +optional
371+
MatchLabelKeys []string
372+
// MismatchLabelKeys is a set of pod label keys to select which pods will
373+
// be taken into consideration. The keys are used to lookup values from the
374+
// incoming pod labels, those key-value labels are merged with `LabelSelector` as `key notin (value)`
375+
// to select the group of existing pods which pods will be taken into consideration
376+
// for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming
377+
// pod labels will be ignored. The default value is empty.
378+
// +optional
379+
MismatchLabelKeys []string
373380
}
374381
```
375382

376383
When a Pod is created, kube-apiserver will obtain the labels from the pod
377-
labels by the key in `MatchLabelSelectors.Key`, and merge to `LabelSelector` of `PodAffinityTerm` depending on `Operator`:
378-
- If Operator is `In`, `key in (value)` is merged with LabelSelector.
379-
- If Operator is `NotIn`, `key notin (value)` is merged with LabelSelector.
380-
381-
Only `In` and `NotIn` are supported in `Operator` of `MatchLabelSelectors`,
382-
and kube-apiserver rejects other operators (`Exist` and `DoesNotExist`).
384+
labels by the key in `matchLabelKeys` or `mismatchLabelKeys`,
385+
and merge to `LabelSelector` of `PodAffinityTerm` depending on field:
386+
- If `matchLabelKeys`, `key in (value)` is merged with LabelSelector.
387+
- If `mismatchLabelKeys`, `key notin (value)` is merged with LabelSelector.
383388

384389
For example, when this sample Pod is created,
385390

@@ -395,9 +400,8 @@ metadata:
395400
affinity:
396401
podAntiAffinity:
397402
requiredDuringSchedulingIgnoredDuringExecution:
398-
- matchLabelSelectors:
399-
- key: tenant
400-
operator: NotIn
403+
- mismatchLabelKeys:
404+
- tenant
401405
labelSelector:
402406
matchExpressions:
403407
- key: tenant
@@ -411,9 +415,8 @@ kube-apiserver modifies the labelSelector like the following:
411415
affinity:
412416
podAntiAffinity:
413417
requiredDuringSchedulingIgnoredDuringExecution:
414-
- matchLabelSelectors:
415-
- key: tenant
416-
operator: NotIn
418+
- mismatchLabelKeys:
419+
- tenant
417420
labelSelector:
418421
matchExpressions:
419422
- key: tenant
@@ -484,9 +487,9 @@ https://storage.googleapis.com/k8s-triage/index.html
484487
-->
485488

486489
- These tests will be added.
487-
- `MatchLabelSelectors` in `PodAffinity` (both in Filter and Score) works as expected.
488-
- `MatchLabelSelectors` in `PodAntiAffinity` (both in Filter and Score) works as expected.
489-
- `MatchLabelSelectors` with the feature gate enabled/disabled.
490+
- `matchLabelKeys`/`mismatchLabelKeys` in `PodAffinity` (both in Filter and Score) works as expected.
491+
- `matchLabelKeys`/`mismatchLabelKeys` in `PodAntiAffinity` (both in Filter and Score) works as expected.
492+
- `matchLabelKeys`/`mismatchLabelKeys` with the feature gate enabled/disabled.
490493

491494
**Filter**
492495
- `k8s.io/kubernetes/test/integration/scheduler/filters/filters_test.go`: https://storage.googleapis.com/k8s-triage/index.html?test=TestPodTopologySpreadFilter
@@ -616,12 +619,12 @@ The previous PodAffinity/PodAntiAffinity behavior will not be broken. Users can
616619
their Pod specs as it is.
617620

618621
To use this enhancement, users need to enable the feature gate (during this feature is in the alpha.),
619-
and add `MatchLabelSelectors` on their PodAffinity/PodAntiAffinity.
622+
and add `matchLabelKeys`/`mismatchLabelKeys` on their PodAffinity/PodAntiAffinity.
620623

621624
**Downgrade**
622625

623-
kube-apiserver will ignore `MatchLabelSelectors` in PodAffinity/PodAntiAffinity,
624-
and thus, kube-scheduler will also do nothing with it.
626+
kube-apiserver will reject Pod creation with `matchLabelKeys`/`mismatchLabelKeys` in PodAffinity/PodAntiAffinity.
627+
But, regarding existing Pods, we leave `matchLabelKeys`/`mismatchLabelKeys` and generated `LabelSelector` even after downgraded.
625628

626629
### Version Skew Strategy
627630

@@ -683,7 +686,7 @@ well as the [existing list] of feature gates.
683686
-->
684687

685688
- [x] Feature gate (also fill in values in `kep.yaml`)
686-
- Feature gate name: `MatchLabelSelectorsInPodAffinity`
689+
- Feature gate name: `MatchLabelKeysInPodAffinity`
687690
- Components depending on the feature gate: `kube-apiserver`
688691
- [ ] Other
689692

@@ -712,12 +715,13 @@ NOTE: Also set `disable-supported` to `true` or `false` in `kep.yaml`.
712715
The feature can be disabled in Alpha and Beta versions
713716
by restarting kube-apiserver the feature-gate off.
714717
In terms of Stable versions, users can choose to opt-out by not setting the
715-
`MatchLabelSelectors` field.
718+
`matchLabelKeys`/`mismatchLabelKeys` field.
716719

717720

718721
###### What happens if we reenable the feature if it was previously rolled back?
719722

720-
Scheduling of new Pods is affected. (Scheduled Pods aren't affected.)
723+
Scheduling of newly created pods with MatchLabelSelector set is affected.
724+
All already existing pods are unafected.
721725

722726
###### Are there any tests for feature enablement/disablement?
723727

@@ -993,6 +997,7 @@ Major milestones might include:
993997
-->
994998

995999
- 2022-11-09: Initial KEP PR is submitted.
1000+
- 2023-05-14 / 2023-06-08: PRs to change it from MatchLabelKeys to MatchLabelSelector are submitted. (to satisfy the user story 2)
9961001

9971002
## Drawbacks
9981003

keps/sig-scheduling/3633-matchlabelselectors-to-podaffinity/kep.yaml renamed to keps/sig-scheduling/3633-matchlabelkeys-to-podaffinity/kep.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
title: Introduce MatchLabelSelectors to PodAffinity and PodAntiAffinity
1+
title: Introduce MatchLabelKeys and MismatchLabelKeys to PodAffinity and PodAntiAffinity
22
kep-number: 3633
33
authors:
44
- "@sanposhiho"
@@ -23,7 +23,7 @@ milestone:
2323
stable: "v1.31"
2424

2525
feature-gates:
26-
- name: MatchLabelSelectorsInPodAffinity
26+
- name: MatchLabelKeysInPodAffinity
2727
components:
2828
- kube-apiserver
2929
disable-supported: true

0 commit comments

Comments
 (0)