violation to check if key exists #525
Answered
by
anderseknert
equick
asked this question in
Gatekeeper
|
How do I raise a violation if a key is missing in a pod? For example, this violation prevents a pod being created if nodeSelectorTerms don't match. However it ignores the pod if the affinity configuration is missing. Do I need another violation to check if Thanks, |
Answered by
anderseknert
Nov 30, 2023
Replies: 2 comments 1 reply
|
This works using |
0 replies
|
If you want to make that attribute required, I'd add another violation. That way you'll can have the error message explain in detail why it fails: violation[{"msg": msg}] {
not pod.spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms
msg := "missing required pod.spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms"
} |
1 reply
Answer selected by
equick
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you want to make that attribute required, I'd add another violation. That way you'll can have the error message explain in detail why it fails:
violation[{"msg": msg}] { not pod.spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms msg := "missing required pod.spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms" }