1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-09 01:16:55 +00:00
kyverno/test/cli/test-mutate/karpenter-annotations-to-nodeselector/policy.yaml
Charles-Edouard Brétéché fb97629ab5
fix: kyverno test are applying previous mutation rules to subsequent test cases causing failures (#8363)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2023-09-12 20:19:14 +00:00

79 lines
No EOL
2.5 KiB
YAML

# https://github.com/kyverno/kyverno/issues/6816
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: karpenter-annotations-to-nodeselector
spec:
rules:
- name: nodeselector-lifecycle-on-demand
preconditions:
all:
- key: "{{ request.operation }}"
operator: Equals
value: CREATE
- key: "{{ request.object.spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution || '' }}"
operator: Equals
value: ''
- key: "{{ request.object.spec.affinity.nodeAffinity.preferredDuringSchedulingIgnoredDuringExecution || '' }}"
operator: Equals
value: ''
exclude:
any:
- resources:
annotations:
reserved-nodes: "*"
- resources:
annotations:
special-hardware: "*"
match:
all:
- resources:
kinds:
- Pod
annotations:
spot-toleration: "false"
mutate:
patchesJson6902: |-
- op: add
path: "/spec/affinity/nodeAffinity"
value:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: karpenter.sh/capacity-type
operator: In
values:
- on-demand
- name: hard-nodeselector-lifecycle-on-demand
preconditions:
all:
- key: "{{ request.operation }}"
operator: Equals
value: CREATE
- key: "{{ request.object.spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution || '' }}"
operator: NotEquals
value: ''
exclude:
any:
- resources:
annotations:
reserved-nodes: "*"
- resources:
annotations:
special-hardware: "*"
match:
all:
- resources:
kinds:
- Pod
annotations:
spot-toleration: "false"
mutate:
patchesJson6902: |-
- op: add
path: "/spec/affinity/nodeAffinity/requiredDuringSchedulingIgnoredDuringExecution/nodeSelectorTerms/0/matchExpressions/-"
value:
key: karpenter.sh/capacity-type
operator: NotIn
values:
- spot