Skip to content

fix: preserve admission operation for expanded reviews#4560

Open
Zakharden wants to merge 1 commit into
open-policy-agent:masterfrom
Zakharden:fix/expanded-review-operation
Open

fix: preserve admission operation for expanded reviews#4560
Zakharden wants to merge 1 commit into
open-policy-agent:masterfrom
Zakharden:fix/expanded-review-operation

Conversation

@Zakharden
Copy link
Copy Markdown

Fixes generated/expanded resource reviews losing input.review.operation, with CREATE/UPDATE/DELETE regression coverage. Validation: targeted go test ./pkg/webhook, go test ./pkg/target, git diff --check.

Copilot AI review requested due to automatic review settings May 12, 2026 10:08
@Zakharden Zakharden requested a review from a team as a code owner May 12, 2026 10:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a regression where expanded/generated resource reviews were losing input.review.operation, ensuring constraints can reliably reason about CREATE/UPDATE/DELETE during expansion flows.

Changes:

  • Thread the admission Operation through expanded (resultant) review creation in the webhook handler.
  • Extend target.AugmentedUnstructured and its conversion to an admission-like review to preserve Operation, including DELETE semantics.
  • Add regression tests covering CREATE/UPDATE/DELETE to ensure expanded reviews keep the original operation.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
pkg/webhook/policy.go Passes the admission operation into generated/resultant reviews so expanded evaluations preserve input.review.operation.
pkg/webhook/policy_test.go Adds regression coverage validating expanded resources preserve CREATE/UPDATE/DELETE operation in review input.
pkg/target/target.go Propagates Operation from AugmentedUnstructured into the internal review object; maps DELETE to OldObject as needed.
pkg/target/data.go Adds Operation to AugmentedUnstructured so non-admission review wrappers can carry operation when applicable.

Comment thread pkg/target/data.go Outdated
Comment on lines +24 to +28
@@ -24,5 +25,6 @@ func IsWipeData(o interface{}) bool {
type AugmentedUnstructured struct {
Object unstructured.Unstructured
Namespace *corev1.Namespace
Operation admissionv1.Operation
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the latest push: the AugmentedUnstructured doc comment now mentions the optional admission operation and when it is populated.

@Zakharden Zakharden force-pushed the fix/expanded-review-operation branch from 4d0a19b to 1f36ee9 Compare May 13, 2026 06:54
@Zakharden Zakharden changed the title Preserve admission operation for expanded reviews fix: preserve admission operation for expanded reviews May 13, 2026
@Zakharden Zakharden force-pushed the fix/expanded-review-operation branch from 1f36ee9 to 8886b16 Compare May 15, 2026 12:12
Copilot AI review requested due to automatic review settings May 15, 2026 12:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread pkg/target/target.go
review.namespace = obj.Namespace
review.Operation = obj.Operation
if obj.Operation == admissionv1.Delete {
review.OldObject = review.Object
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the latest push: DELETE reviews now move the generated object into OldObject and clear Object with the zero runtime.RawExtension{} value. I also added TestAugmentedUnstructuredDeleteUsesOldObject to cover this path before the DELETE review normalization step.

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 44.52%. Comparing base (3350319) to head (8886b16).
⚠️ Report is 699 commits behind head on master.

Files with missing lines Patch % Lines
pkg/target/target.go 33.33% 1 Missing and 1 partial ⚠️

❗ There is a different number of reports uploaded between BASE (3350319) and HEAD (8886b16). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (3350319) HEAD (8886b16)
unittests 2 1
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4560      +/-   ##
==========================================
- Coverage   54.49%   44.52%   -9.97%     
==========================================
  Files         134      282     +148     
  Lines       12329    20721    +8392     
==========================================
+ Hits         6719     9227    +2508     
- Misses       5116    10699    +5583     
- Partials      494      795     +301     
Flag Coverage Δ
unittests 44.52% <66.66%> (-9.97%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Signed-off-by: Zakhar Dvurechensky <72825626+Zakharden@users.noreply.github.com>
@Zakharden Zakharden force-pushed the fix/expanded-review-operation branch from 8886b16 to 45c4d4d Compare May 16, 2026 10:43
@Zakharden
Copy link
Copy Markdown
Author

@grosser @alban @tim775 check it plz

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.

3 participants