Tips for Understanding Kyverno and CEL Syntax
Asked by
+18 credits earned
I'm currently in the process of updating my Kyverno cluster policies to comply with the new ValidatingPolicy and MutatingPolicy standards, and I'm really struggling with CEL. It feels incredibly complicated, and I can't find any straightforward documentation that explains the CEL syntax in an easy-to-understand way. Am I missing something? Is this language supposed to be user-friendly? Even the basic examples from Kyverno seem quite confusing to meโit's like a whole different world! For instance, here's a simple ValidatingPolicy I've come across:
```yaml
apiVersion: policies.kyverno.io/v1
kind: ValidatingPolicy
metadata:
name: check-labels
spec:
validationActions:
- Deny
matchConstraints:
resourceRules:
- apiGroups: ['']
apiVersions: [v1]
operations: [CREATE, UPDATE]
resources: [pods]
validations:
- message: label 'environment' is required
expression: "'environment' in object.metadata.?labels.orValue([])"
```
Can anyone help me wrap my head around this?
Answers
Honestly, I recommend just using regex for your rules instead. CEL can be hard to read, and the regex approach is sometimes much clearer! You can find some good practices about label requirements on the Kyverno website too. It's worth checking out!
Reply to this answer
Have you checked out the detailed documentation on CEL? It might seem overwhelming, but it provides a pretty solid foundation. I know it can feel dense, but it helps to break down the specifics instead of trying to get it all at once. You might find it beneficial to start with the basics before diving into policies. Hang in there!
Reply to this answer
If you're looking to test these policies in CI, it's definitely possible! You can run tests with the Kyverno CLI tool as long as you have it installed in your CI setup. And yes, you can run those tests without needing full cluster access. It's a great way to check that everything works as expected.
Reply to this answer
Add your answer
Answers are reviewed before publication.
+18 credits earned: Thanks for the tip! I actually hadn't looked at the general CEL docs, just the official ones regarding Kyverno. Iโll definitely give it a shot, even if it looks a bit heavy.