use kube_cel::{
analysis::{self, ScopeContext},
compilation::compile_schema,
};
use serde_json::json;
fn main() {
let schema = json!({
"type": "object",
"properties": {
"name": {"type": "string", "maxLength": 253},
"tags": {
"type": "array",
"items": {"type": "string"}
},
"replicas": {"type": "integer"}
}
});
let compiled = compile_schema(&schema);
let rules = [
"self.replicas >= 0",
"self.name.size() > 0",
"self.tags.all(tag, tag.size() > 0)",
"request.userInfo.username != 'admin'",
];
println!("=== CEL Rule Analysis ===\n");
for rule in &rules {
println!("Rule: {rule}");
let warnings = analysis::analyze_rule(rule, &compiled, ScopeContext::CrdValidation);
if warnings.is_empty() {
println!(" OK — no issues found\n");
} else {
for w in &warnings {
println!(" [{:?}] {}", w.kind, w.message);
}
println!();
}
}
}