evaluator: update implementation and tests; refresh policy test fixtures#1
Closed
zemanlx wants to merge 4 commits into
Closed
evaluator: update implementation and tests; refresh policy test fixtures#1zemanlx wants to merge 4 commits into
zemanlx wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for namespace selector matching in Kubernetes admission policy bindings. The evaluator now properly evaluates namespaceSelector specifications in both ValidatingAdmissionPolicyBinding and MutatingAdmissionPolicyBinding objects, allowing policies to be selectively applied based on namespace labels.
Changes:
- Added namespace selector evaluation logic in the evaluator with two new helper functions
- Updated
EvaluateTest,evaluatePolicy,EvaluateMutating, andEvaluateValidatingto accept and use binding parameters - Modified
main.goto look up and pass both policies and their bindings to the evaluator - Added comprehensive test fixtures for namespace selector scenarios (In, NotIn, Exists, DoesNotExist operators)
Reviewed changes
Copilot reviewed 40 out of 40 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| internal/evaluator/evaluator.go | Added matchesNamespaceSelector and matchesNamespaceSelectorV1Beta1 functions; updated evaluation functions to accept and evaluate bindings |
| internal/evaluator/evaluator_test.go | Updated test structure to include mutatingBinding parameter in function calls |
| internal/evaluator/evaluator_params_test.go | Updated EvaluateMutating call to pass nil for mutating binding parameter |
| internal/evaluator/evaluator_authorizer_test.go | Updated EvaluateMutating call to pass nil for mutating binding parameter |
| main.go | Updated findPolicies to return bindings and modified runSuite to pass bindings to evaluator |
| test-policies-pass/validating/namespace-selector-binding/* | New test policy demonstrating In operator for namespace selector |
| test-policies-pass/validating/namespace-selector-doesnotexist/* | New test policy demonstrating DoesNotExist operator |
| test-policies-pass/validating/namespace-selector-operators/* | New test policy demonstrating NotIn and Exists operators |
| test-policies-pass/mutating/namespace-selector-binding-mutating/* | New test policy demonstrating namespace selector in mutating policies |
| testdata/*.golden | Updated golden files to include new test fixtures and their passing results |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Update `internal/evaluator` implementation and improve unit tests. - Modify `main.go` to align with evaluator changes. - Add/refresh multiple policy bindings and test cases under `test-policies-pass` (mutating and validating suites). - Update golden testdata files in `testdata/`.
eac17f9 to
dc12d65
Compare
Co-authored-by: zemanlx <18702153+zemanlx@users.noreply.github.com>
evaluator: deduplicate namespace selector matching via shared helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
internal/evaluatorimplementation and improve unit tests.main.goto align with evaluator changes.test-policies-pass(mutating and validating suites).testdata/.