You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This KEP proposes introducing a complementary field `MatchLabelSelectors` to `PodAffinityTerm`.
181
+
This KEP proposes introducing a complementary field `MatchLabelKeys` to `PodAffinityTerm`.
182
182
This enables users to finely control the scope where Pods are expected to co-exist (PodAffinity)
183
183
or not (PodAntiAffinity), on top of the existing `LabelSelector`.
184
184
@@ -210,7 +210,7 @@ The same issue applies to other scheduling directives as well. For example, Matc
210
210
211
211
### Goals
212
212
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.
214
214
215
215
### Non-Goals
216
216
@@ -219,7 +219,7 @@ What is out of scope for this KEP? Listing non-goals helps to focus discussion
219
219
and make progress.
220
220
-->
221
221
222
-
- Apply additional internal labels when evaluating `MatchLabelSelectors`
222
+
- Apply additional internal labels when evaluating `MatchLabelKeys` or `MismatchLabelKeys`
223
223
224
224
## Proposal
225
225
@@ -266,9 +266,8 @@ metadata:
266
266
values:
267
267
- database
268
268
topologyKey: topology.kubernetes.io/zone
269
-
matchLabelSelectors: # ADDED
270
-
- key: pod-template-hash
271
-
operator: In
269
+
matchLabelKeys: # ADDED
270
+
- pod-template-hash
272
271
```
273
272
274
273
#### Story 2
@@ -282,15 +281,13 @@ By applying the following affinity globally using a mutating webhook, the cluste
282
281
affinity:
283
282
podAffinity: # ensures the pods of this tenant land on the same node pool
284
283
requiredDuringSchedulingIgnoredDuringExecution:
285
-
- matchLabelSelectors:
286
-
- key: tenant
287
-
operator: In
284
+
- matchLabelKeys:
285
+
- tenant
288
286
topologyKey: node-pool
289
287
podAntiAffinity: # ensures only Pods from this tenant lands on the same node pool
290
288
requiredDuringSchedulingIgnoredDuringExecution:
291
-
- matchLabelSelectors:
292
-
- key: tenant
293
-
operator: NotIn
289
+
- mismatchLabelKeys:
290
+
- tenant
294
291
labelSelector:
295
292
matchExpressions:
296
293
- key: tenant
@@ -328,7 +325,7 @@ Consider including folks who also work outside the SIG or subproject.
328
325
-->
329
326
330
327
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
332
329
which pods should be grouped. If so, the user needs to ensure that it is
333
330
correct and not duplicated with other unrelated workloads.
334
331
@@ -341,17 +338,16 @@ required) or even code snippets. If there's any ambiguity about HOW your
341
338
proposal will be implemented, this is the place to discuss them.
342
339
-->
343
340
344
-
A new optional field `MatchLabelSelectors` is introduced to `PodAffinityTerm`.
341
+
A new optional fields `matchLabelKeys` and `mismatchLabelKeys` are introduced to `PodAffinityTerm`.
345
342
346
343
```go
347
-
type LabelSelectorOperator string
348
-
349
344
type MatchLabelSelector struct {
350
345
// Key is used to lookup value from the incoming pod labels,
351
346
// and that key-value label is merged with `LabelSelector`.
352
347
// Key that doesn't exist in the incoming pod labels will be ignored.
353
348
Key string
354
349
// Operator defines how key-value, fetched via the above `Keys`, is merged into LabelSelector.
350
+
// Only `In` and `NotIn` are expected.
355
351
// If Operator is `In`, `key in (value)` is merged with LabelSelector.
356
352
// If Operator is `NotIn`, `key notin (value)` is merged with LabelSelector.
357
353
//
@@ -365,21 +361,30 @@ type PodAffinityTerm struct {
365
361
TopologyKey string
366
362
NamespaceSelector *metav1.LabelSelector
367
363
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
373
380
}
374
381
```
375
382
376
383
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.
383
388
384
389
For example, when this sample Pod is created,
385
390
@@ -395,9 +400,8 @@ metadata:
395
400
affinity:
396
401
podAntiAffinity:
397
402
requiredDuringSchedulingIgnoredDuringExecution:
398
-
- matchLabelSelectors:
399
-
- key: tenant
400
-
operator: NotIn
403
+
- mismatchLabelKeys:
404
+
- tenant
401
405
labelSelector:
402
406
matchExpressions:
403
407
- key: tenant
@@ -411,9 +415,8 @@ kube-apiserver modifies the labelSelector like the following:
0 commit comments