Skip to content

Instantly share code, notes, and snippets.

@sebdoido
Created September 12, 2022 12:51
Show Gist options
  • Save sebdoido/69773801dc7414dcd12bcc5f6c5e52db to your computer and use it in GitHub Desktop.
Save sebdoido/69773801dc7414dcd12bcc5f6c5e52db to your computer and use it in GitHub Desktop.
bbc-kyverno-preemptible-to-spot
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: add-tolerations
spec:
rules:
- name: volatile-toleration
match:
any:
- resources:
kinds:
- Pod
preconditions:
any:
- key: "cloud.google.com/gke-preemptible"
operator: AnyIn
value: "{{ request.object.spec.tolerations[].key || `[]` }}"
mutate:
patchStrategicMerge:
spec:
# Add the `affinity`if not already specified.
+(affinity):
+(nodeAffinity):
+(requiredDuringSchedulingIgnoredDuringExecution):
nodeSelectorTerms:
- matchExpressions:
- key: cloud.blabla.io/k8s-volatile
operator: Exists
tolerations:
- effect: NoSchedule
key: cloud.blabla.io/k8s-volatile
operator: Equal
value: "true"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment