kudobuilder / kuttl

KUbernetes Test TooL (kuttl)
https://kuttl.dev
Apache License 2.0
688 stars 85 forks source link

Add CEL expression support #562

Open kumar-mallikarjuna opened 2 months ago

kumar-mallikarjuna commented 2 months ago

What would you like to be added: A Common Expression Language (CEL) based assertion semantic.

The Common Expression Language (CEL) provides a standardized way to evaluate expressions, facilitating easier interoperability between different applications.

Reference: https://github.com/google/cel-spec

Why is this needed:

Currently, Kuttl lacks support for complex data manipulation in assertions. Here are a few examples where this limitation is apparent:

These issues could be resolved by incorporating a CEL engine into Kuttl, allowing for expression evaluation and more flexible assertions.

How would this look like syntactically:

apiVersion: kuttl.dev/v1beta1
kind: TestAssert
celAssert:
  resources:
    - apiVersion: apps/v1
       kind: Deployment
       name: coredns
       namespace: kube-system
       id: resource
  expression: "resource.status.readyReplicas > 1"

Edit: Incorporate the comments from @porridge .

porridge commented 2 months ago

I totally agree with the rationale. Kuttl definitely needs more powerful assertion capabilities. Discussions on how to best express this never concluded. I actually like how chainsaw solved this, some of the things there don't really look like YAML any more 😆

Your suggestion looks functional, even if somewhat different from how assertions are currently expressed in kuttl.

I wonder if you could write up a really short KEP do describe this and announce on the slack channel, to give others a chance to comment?

Personally I'd just maybe use id instead of identifier and put this into TestAssert rather than TestStep.

eddycharly commented 2 months ago

I have plan to support CEL in chainsaw, didn't have time to work on it yet though :(

kumar-mallikarjuna commented 2 months ago

Sure, will do, @porridge .