Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save larkintuckerllc/963a1ac7330eb9caf385691670177d2b to your computer and use it in GitHub Desktop.
Save larkintuckerllc/963a1ac7330eb9caf385691670177d2b to your computer and use it in GitHub Desktop.
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: nodepool-selector-affinites-notexist
annotations:
pod-policies.kyverno.io/autogen-controllers: none
spec:
rules:
- name: nodepool-selector-affinites-notexist
match:
any:
- resources:
annotations:
example.com/nodepool: "*"
kinds:
- Pod
namespaceSelector:
matchLabels:
example.com/match: "true"
operations:
- CREATE
exclude:
any:
- resources:
annotations:
example.com/nodepool-selector-affinites: "true"
preconditions:
any:
- key: "{{ request.object.spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms || '' }}"
operator: Equals
value: ""
mutate:
patchesJson6902: |-
- op: add
path: "/metadata/annotations/example.com~1nodepool-selector-affinites"
value: "true"
- path: "/spec/affinity/nodeAffinity/requiredDuringSchedulingIgnoredDuringExecution/nodeSelectorTerms/-1/matchExpressions/-1"
op: add
value:
key: example.com/nodepool
operator: In
values :
- '{{ request.object.metadata.annotations."example.com/nodepool" }}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment