Kubernetes Common Expression Language (CEL)


Details
If you have been using Kubernetes for a while you might have written very lengthy Yaml files and most of the times it goes in selection criteria of the spec field related lines of Yaml. Just look at the below example
Below example is for Requesting GPUs with Minimum Memory in the context of DRA, by the way we covered DRA in our last meetup
Without CEL
apiVersion: resource.k8s.io/v1beta2
kind: ResourceClaim
metadata:
name: some-gpu
namespace: dra-tutorial
spec:
devices:
requests:
- name: some-gpu
exactly:
deviceClassName: gpu.example.com
- This will request any GPU device of the class `gpu.example.com`.
- There is no constraint on memory size in this version.
- The system will allocate any available GPU, regardless of its memory capacity.
With CEL
apiVersion: resource.k8s.io/v1beta2
kind: ResourceClaim
metadata:
name: some-gpu
namespace: dra-tutorial
spec:
devices:
requests:
- name: some-gpu
exactly:
deviceClassName: gpu.example.com
selectors:
- cel:
expression: "device.capacity['gpu.example.com'].memory.compareTo(quantity('10Gi')) >= 0"
- This request selects from GPUs in the class `gpu.example.com` that have at least 10Gi of memory.
- The CEL expression filters devices by checking their memory capacity attribute.
- Only GPUs satisfying the memory requirement are considered for allocation.
As you can see in the above example, we can use more selection options with CEL than without it. There's much more to CEL, it is evolving as it's own language and you can find the documentation here https://kubernetes.io/docs/reference/using-api/cel/
During this session, we will deep dive and get into the rabbit hole of CEL as far as we can. By the end of this meetup, i expect you to ditch the CELess way and adopt CEL wherever it's possible and applicable.

Kubernetes Common Expression Language (CEL)