Skip to content

Commit b080ba2

Browse files
committed
change matchLabelSelectors to matchLabelKeys and mismatchLabelKeys
1 parent c641305 commit b080ba2

File tree

2 files changed

+46
-50
lines changed

2 files changed

+46
-50
lines changed

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

+44-48
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,9 @@ 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-
349-
// Only `In` and `NotIn` are expected for LabelSelectorOperator.
350-
const (
351-
InLabelSelectorOperator LabelSelectorOperator = "In"
352-
NotInLabelSelectorOperator LabelSelectorOperator = "NotIn"
353-
)
354-
355344
type MatchLabelSelector struct {
356345
// Key is used to lookup value from the incoming pod labels,
357346
// and that key-value label is merged with `LabelSelector`.
@@ -372,21 +361,30 @@ type PodAffinityTerm struct {
372361
TopologyKey string
373362
NamespaceSelector *metav1.LabelSelector
374363

375-
// MatchLabelSelectors is a set of pod label keys to select the group of existing pods
376-
// which pods will be taken into consideration for the incoming pod's pod (anti) affinity.
377-
// The default value is empty.
378-
// +optional
379-
MatchLabelSelectors []MatchLabelSelector
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
380380
}
381381
```
382382

383383
When a Pod is created, kube-apiserver will obtain the labels from the pod
384-
labels by the key in `MatchLabelSelectors.Key`, and merge to `LabelSelector` of `PodAffinityTerm` depending on `Operator`:
385-
- If Operator is `In`, `key in (value)` is merged with LabelSelector.
386-
- If Operator is `NotIn`, `key notin (value)` is merged with LabelSelector.
387-
388-
Only `In` and `NotIn` are supported in `Operator` of `MatchLabelSelectors`,
389-
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.
390388

391389
For example, when this sample Pod is created,
392390

@@ -402,9 +400,8 @@ metadata:
402400
affinity:
403401
podAntiAffinity:
404402
requiredDuringSchedulingIgnoredDuringExecution:
405-
- matchLabelSelectors:
406-
- key: tenant
407-
operator: NotIn
403+
- mismatchLabelKeys:
404+
- tenant
408405
labelSelector:
409406
matchExpressions:
410407
- key: tenant
@@ -418,9 +415,8 @@ kube-apiserver modifies the labelSelector like the following:
418415
affinity:
419416
podAntiAffinity:
420417
requiredDuringSchedulingIgnoredDuringExecution:
421-
- matchLabelSelectors:
422-
- key: tenant
423-
operator: NotIn
418+
- mismatchLabelKeys:
419+
- tenant
424420
labelSelector:
425421
matchExpressions:
426422
- key: tenant
@@ -491,9 +487,9 @@ https://storage.googleapis.com/k8s-triage/index.html
491487
-->
492488

493489
- These tests will be added.
494-
- `MatchLabelSelectors` in `PodAffinity` (both in Filter and Score) works as expected.
495-
- `MatchLabelSelectors` in `PodAntiAffinity` (both in Filter and Score) works as expected.
496-
- `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.
497493

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

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

628624
**Downgrade**
629625

630-
kube-apiserver will reject Pod creation with `MatchLabelSelectors` in PodAffinity/PodAntiAffinity.
631-
But, regarding existing Pods, we leave `MatchLabelSelectors` and `LabelSelector` created from `MatchLabelSelectors` even after downgraded.
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.
632628

633629
### Version Skew Strategy
634630

@@ -690,7 +686,7 @@ well as the [existing list] of feature gates.
690686
-->
691687

692688
- [x] Feature gate (also fill in values in `kep.yaml`)
693-
- Feature gate name: `MatchLabelSelectorsInPodAffinity`
689+
- Feature gate name: `MatchLabelKeysInPodAffinity`
694690
- Components depending on the feature gate: `kube-apiserver`
695691
- [ ] Other
696692

@@ -719,7 +715,7 @@ NOTE: Also set `disable-supported` to `true` or `false` in `kep.yaml`.
719715
The feature can be disabled in Alpha and Beta versions
720716
by restarting kube-apiserver the feature-gate off.
721717
In terms of Stable versions, users can choose to opt-out by not setting the
722-
`MatchLabelSelectors` field.
718+
`matchLabelKeys`/`mismatchLabelKeys` field.
723719

724720

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

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)