Skip to content
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

Merged

Conversation

abhipatnala
Copy link
Contributor

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:

@abhipatnala abhipatnala requested a review from a team as a code owner August 22, 2024 22:38
Copy link
Contributor

@maxsmythe maxsmythe left a 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!

}

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.
Copy link
Contributor

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.

Copy link
Contributor Author

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 {
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

@maxsmythe maxsmythe left a 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")
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Avinash Patnala added 4 commits August 29, 2024 11:56
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]>
@codecov-commenter
Copy link

codecov-commenter commented Aug 29, 2024

Codecov Report

Attention: Patch coverage is 85.18519% with 4 lines in your changes missing coverage. Please review.

Project coverage is 48.05%. Comparing base (3350319) to head (5ebffcf).
Report is 139 commits behind head on master.

Files with missing lines Patch % Lines
pkg/webhook/policy.go 78.94% 2 Missing and 2 partials ⚠️

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

HEAD has 1 upload less than BASE
Flag BASE (3350319) HEAD (5ebffcf)
unittests 2 1
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     
Flag Coverage Δ
unittests 48.05% <85.18%> (-6.44%) ⬇️

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.

Copy link
Contributor

@JaydipGabani JaydipGabani left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Contributor

@David-Jaeyoon-Lee David-Jaeyoon-Lee left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Member

@ritazh ritazh left a 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

@ritazh ritazh merged commit 5de3edb into open-policy-agent:master Sep 11, 2024
19 checks passed
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.

Move the obj == oldObject on DELETE logic to the TargetHandler instead of the webhook validation handler
7 participants