- 
                Notifications
    You must be signed in to change notification settings 
- Fork 258
Add CEL template #1012
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
Add CEL template #1012
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like there is some AI-generated code in this PR. That's fine but I'd advice to add a note in the description about that .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice and compact, I'm a fan!
I understand that due to being an expression language, a CEL check is a bit limited compared to a check in some procedural language, where you can accumulate state. I'm not sure how important this limitation will be so I'm in favor of merging CEL support.
We can then try to implement open requests for checks using this CEL template and see how far we can go.
Signed-off-by: Tomasz Janiszewski <tomek@redhat.com>
Signed-off-by: Tomasz Janiszewski <tomek@redhat.com>
Signed-off-by: Tomasz Janiszewski <tomek@redhat.com>
| This dangling service can accumulate state, which means it can basically do anything we've done with Go. The issue is that it can get messy for big projects, especially since we're keeping it all in one YAML file. Moving forward, we should make CEL development easier by: 
 | 
This PR adds a fallback when decoding unknown resources to be able to handle CRDs. The schema validation could be then performed with kubeconform check from #1033 and CEL from #1012. This should fix #606 Changes: - Modified parseObjects to use unstructured decoder as fallback for unknown resource types - Added comprehensive test suite covering standard K8s resources and CRDs - Maintained backward compatibility for existing decode error handling - Added test cases for Tekton Task CRD and other custom resources The fallback allows kube-linter to parse CRDs like Tekton Pipelines without failing, while delegating proper schema validation to specialized templates like kubeconform and CEL expressions. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Tomasz Janiszewski <tomek@redhat.com>
This PR adds a fallback when decoding unknown resources to be able to handle CRDs. The schema validation could be then performed with kubeconform check from #1033 and CEL from #1012. This should fix #606 Changes: - Modified parseObjects to use unstructured decoder as fallback for unknown resource types - Added comprehensive test suite covering standard K8s resources and CRDs - Maintained backward compatibility for existing decode error handling - Added test cases for Tekton Task CRD and other custom resources The fallback allows kube-linter to parse CRDs like Tekton Pipelines without failing, while delegating proper schema validation to specialized templates like kubeconform and CEL expressions. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Tomasz Janiszewski <tomek@redhat.com>
This PR adds a fallback when decoding unknown resources to be able to handle CRDs. The schema validation could be then performed with kubeconform check from #1033 and CEL from #1012. This should fix #606 Changes: - Modified parseObjects to use unstructured decoder as fallback for unknown resource types - Added comprehensive test suite covering standard K8s resources and CRDs - Maintained backward compatibility for existing decode error handling - Added test cases for Tekton Task CRD and other custom resources The fallback allows kube-linter to parse CRDs like Tekton Pipelines without failing, while delegating proper schema validation to specialized templates like kubeconform and CEL expressions. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Tomasz Janiszewski <tomek@redhat.com>
Add CEL Template for Custom Expression-Based Checks
This PR introduces a new
cel-expressiontemplate that enables users to write custom checks using the Common Expression Language (CEL). This powerful addition allows for flexible, expression-based validation of Kubernetes resources without requiring Go code changes.🚀 Features
cel-expressiontemplate inpkg/templates/cel/template.go:18objectkinds.Any🔧 How It Works
The template provides two variables to CEL expressions:
subject: The current Kubernetes resource being evaluatedobjects: Array of all Kubernetes resources in the current contextCEL expressions should return:
""if the check passes📝 Usage Examples
Replace complex template logic with simple CEL expressions:
Example 1: Forbidden Annotation Check
Example 2: IRSA Role Validation
🧪 Testing
e2etests/bats-tests.shdemonstrates the CEL template replacing traditional forbidden annotation checkspkg/templates/cel/template_test.goe2etests/testdata/cel-config.yamlandtests/checks/cel.yml💡 Benefits
🔄 Migration Path
This template can replace many existing specialized templates. For example, the forbidden annotation functionality previously requiring a dedicated template can now be implemented with a simple CEL expression (as shown in the e2e tests).
📚 Resources
🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com