-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinject-node-affinity.yaml
31 lines (30 loc) · 1.5 KB
/
inject-node-affinity.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
apiVersion: generic-webhook/v1beta1
kind: GenericWebhookConfig
webhooks:
- name: patch-node-affinity
path: /patch-node-affinity
actions:
# If the pod doesn't have any node affinity that involves the `myorg.io/instance-cost`
# label, then we inject a preferred node affinity for the nodes that have
# the value `cheap` for the `myorg.io/instance-cost` label
- condition:
and:
# We are analysing a Pod
- .kind == "Pod"
# {key: myorg.io/instance-cost} doesn't appear in preferredDuringSchedulingIgnoredDuringExecution
- all: .spec.affinity.nodeAffinity.preferredDuringSchedulingIgnoredDuringExecution.*.preference.matchExpressions.* -> .key != "myorg.io/instance-cost"
# {key: myorg.io/instance-cost} doesn't appear in requiredDuringSchedulingIgnoredDuringExecution
- all: .spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms.*.matchExpressions.* -> .key != "myorg.io/instance-cost"
patch:
# Inject a preferred node affinity for the nodes that have the label
# `myorg.io/instance-cost = cheap`
- op: add
path: .spec.affinity.nodeAffinity.preferredDuringSchedulingIgnoredDuringExecution
value:
preference:
matchExpressions:
- key: myorg.io/instance-cost
operator: In
values:
- cheap
weight: 1