-
Notifications
You must be signed in to change notification settings - Fork 765
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
refactor: Move setting up Obj to old obj on Delete logic to target handler #3511
refactor: Move setting up Obj to old obj on Delete logic to target handler #3511
Conversation
b26531c
to
41e70be
Compare
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.
LGTM with one nit. Thanks for the PR!
pkg/webhook/policy.go
Outdated
} | ||
|
||
trace, dump := h.tracingLevel(ctx, req) | ||
resp, err := h.review(ctx, review, trace, dump) | ||
if err != nil { | ||
return nil, fmt.Errorf("error reviewing resource %s: %w", req.Name, err) | ||
} | ||
|
||
// resultants slice will be empty if expand is skipped. |
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.
no need to comment about this, it can be inferred from the code without extra context.
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.
Deleted that comment.
return nil, fmt.Errorf("unable to expand object: %w", err) | ||
resultants := []*expansion.Resultant{} | ||
// Skip the expansion if admissionRequest.Obj is nil. | ||
if req.AdmissionRequest.Object.Raw != nil { |
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.
Probably out of scope for this PR, but once deletion expansion is fixed. This should probably follow the behavior of use oldObject.Raw for deletion requests (when object is nil) and object.Raw otherwise. Correct me if Im wrong @maxsmythe.
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.
discussed offline with max. You can ignore this for this PR.
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.
LGTM
@@ -18,6 +18,9 @@ import ( | |||
"k8s.io/apimachinery/pkg/util/validation/field" | |||
) | |||
|
|||
// nolint: revive // Moved error out of pkg/webhook/admission; needs capitalization for backwards compat. | |||
var ErrOldObjectIsNil = errors.New("oldObject cannot be nil for DELETE operations") |
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.
No good place to suggest this change -
Update runner_test.go#1160 to {Name: "no oldObject on delete", Error: &clienterrors.ErrorMap{target.Name: constraintclient.ErrReview}},
And import this in the same test file -
"github.com/open-policy-agent/gatekeeper/v3/pkg/target"
clienterrors "github.com/open-policy-agent/frameworks/constraint/pkg/client/errors"
This should fix the CI error.
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.
Thank You. I have included those changes.
2.Add unit tests 3.Update runner and webhook Signed-off-by: Avinash Patnala <[email protected]>
Signed-off-by: Avinash Patnala <[email protected]>
Signed-off-by: Avinash Patnala <[email protected]>
Signed-off-by: Avinash Patnala <[email protected]>
903cea5
to
71af237
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3511 +/- ##
==========================================
- Coverage 54.49% 48.05% -6.44%
==========================================
Files 134 218 +84
Lines 12329 15167 +2838
==========================================
+ Hits 6719 7289 +570
- Misses 5116 7064 +1948
- Partials 494 814 +320
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.
lgtm
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.
LGTM!
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.
LGTM
Thanks for the PR @abhipatnala
What this PR does / why we need it:
Which issue(s) this PR fixes (optional, using
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when the PR gets merged):Fixes #3441
Special notes for your reviewer: