Skip to content

Permit literal string validation for CEL expressions #1754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Danil-Grigorev
Copy link
Member

Motivation

In order to simplify usage of CEL in schema generation with x_kube macro, users interested in simple validation should be able to specify simple &str data without additional syntax, like mandatory .into() call for conversion into Rule type required now.

Solution

This change allows to write simple CEL expressions like so:

#[x_kube(validation = "self.nonNullable == oldSelf.nonNullable")]

as opposed to previous:

#[x_kube(validation = "self.nonNullable == oldSelf.nonNullable".into())]

or

#[x_kube(validation = Rule::new("self.metadata.name != 'forbidden'"))]

and combine multiple more complex expressions with different input types, in case a message or a reason context needs to be specified:

#[x_kube(validation = "self != 'not legal'", validation = Rule::new("self != 'not that'"))]
#[x_kube(validation = ("self != 'also not that'", "some pretty good reason"))]

Copy link

codecov bot commented May 1, 2025

Codecov Report

Attention: Patch coverage is 76.92308% with 3 lines in your changes missing coverage. Please review.

Project coverage is 76.2%. Comparing base (0d79006) to head (6c7fcb6).

Files with missing lines Patch % Lines
kube-core/src/cel.rs 66.7% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main   #1754     +/-   ##
=======================================
- Coverage   76.2%   76.2%   -0.0%     
=======================================
  Files         84      84             
  Lines       7883    7889      +6     
=======================================
+ Hits        6003    6006      +3     
- Misses      1880    1883      +3     
Files with missing lines Coverage Δ
kube-derive/src/cel_schema.rs 93.7% <100.0%> (ø)
kube-derive/src/custom_resource.rs 84.1% <ø> (ø)
kube-derive/src/lib.rs 0.0% <ø> (ø)
kube-derive/tests/crd_schema_test.rs 97.1% <ø> (ø)
kube-core/src/cel.rs 62.5% <66.7%> (-1.2%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant