feat: [cel] add CEL-based assertions and offline VAP evaluation#569
feat: [cel] add CEL-based assertions and offline VAP evaluation#569crandles wants to merge 3 commits into
Conversation
Signed-off-by: Chris Randles <randles.chris@gmail.com>
Signed-off-by: Chris Randles <randles.chris@gmail.com>
Signed-off-by: Chris Randles <randles.chris@gmail.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: crandles The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @crandles. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Tip We noticed you've done this a few times! Consider joining the org to skip this step and gain Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
PR needs rebase. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
/ok-to-test |
|
@crandles - At the risk of completely misrepresenting your intent with your API design, I am going to propose a design that simplifies the API a bit. You welcome to push back if you think I am missing your point.
Single assertion: Current: ev, err := celpkg.NewEvaluator()
if err := ev.Assert(
"object.spec.replicas >= 1",
celpkg.ObjectBinding(dep),
); err != nil {
t.Fatal(err)
}Proposed: ev, err := cel.NewEvaluator(cel.WithObjectBinding(dep))
// or ev.AddObjectBinding(obj)
ev.AddExpression("object.spec.replicas >= 1")
result, err := ev.Check(). // or ev.Evaluate()
if result.Passed() { ... }Multi-validation policy: Today: pol := policy.Policy{
Name: "deployment-replicas",
Validations: []policy.Validation{
{Expression: "object.spec.replicas >= 1", Message: "replicas must be at least 1"},
{Expression: "object.spec.replicas <= 100", Message: "replicas must not exceed 100"},
},
}
ev, _ := celpkg.NewEvaluator()
res := pol.Check(ev, newDeployment("cel-demo", 2))Proposed: ev, _ := cel.NewEvaluator(cel.WithObjectBinding(newDeployment("cel-demo", 2)))
ev.AddExpression("object.spec.replicas >= 1", "replicas must be at least 1")
ev.AddExpression("object.spec.replicas <= 100", "replicas must not exceed 100")
result, err := ev.Check()
if result.Passed(){ ... }Let's start with that. Let me know what you think |
vladimirvivien
left a comment
There was a problem hiding this comment.
See my PR comment.
|
I think I like your proposal -- no objections with the interface. The struct field options appears overly verbose, with no strong benefit. Will push up changes shortly. |
What type of PR is this?
/kind feature
What this PR does / why we need it:
Adds a
celpackage for writing CEL-based assertions against Kubernetes objects in tests. Same expression language the API server uses for CRD validation and admission policies, so tests don't drift from the policies they exercise.Split out from #562 -- this PR includes the following packages:
cel(Evaluator, Bindings, Libraries, program cache),cel/policy(offline VAP evaluation,FromVAP), and a small offlineexamples/celtest that exercises both.The
cel/decoder,cel/feature,cel/waitsub-packages and the live-cluster example will follow in a second PR layered on this one. (WIP: crandles#3)Design doc: docs/cel-assertions.md.
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?