-
Notifications
You must be signed in to change notification settings - Fork 779
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: expose AdmissionReview for gator verify (#2348)
* feat: expose AdmissionReview for gator verify Signed-off-by: Alex Pana <8968914+acpana@users.noreply.github.com> * review: error out on lack of objects Signed-off-by: Alex Pana <8968914+acpana@users.noreply.github.com> * review: mimick g8r webhook behavior on DELETE Signed-off-by: Alex Pana <8968914+acpana@users.noreply.github.com> * move arr logic into helper func Signed-off-by: Alex Pana <8968914+acpana@users.noreply.github.com> * Update pkg/gator/errors.go Co-authored-by: Rita Zhang <rita.z.zhang@gmail.com> Signed-off-by: alex <8968914+acpana@users.noreply.github.com> * review: no code duplication on check Signed-off-by: Alex Pana <8968914+acpana@users.noreply.github.com> * review: func name Signed-off-by: Alex Pana <8968914+acpana@users.noreply.github.com> Signed-off-by: Alex Pana <8968914+acpana@users.noreply.github.com> Signed-off-by: alex <8968914+acpana@users.noreply.github.com> Co-authored-by: Rita Zhang <rita.z.zhang@gmail.com> Co-authored-by: Sertaç Özercan <852750+sozercan@users.noreply.github.com> Co-authored-by: Max Smythe <smythe@google.com>
- Loading branch information
1 parent
66539ed
commit 4ec4f34
Showing
8 changed files
with
375 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package util | ||
|
||
import ( | ||
"errors" | ||
|
||
admissionv1 "k8s.io/api/admission/v1" | ||
"sigs.k8s.io/controller-runtime/pkg/webhook/admission" | ||
) | ||
|
||
// nolint: revive // Moved error out of pkg/webhook/admission; needs capitalization for backwards compat. | ||
var ErrOldObjectIsNil = errors.New("For admission webhooks registered for DELETE operations, please use Kubernetes v1.15.0+.") | ||
|
||
// SetObjectOnDelete enforces that we use at least K8s API v1.15.0+ on DELETE operations | ||
// and copies over the oldObject into the Object field for the given AdmissionRequest. | ||
func SetObjectOnDelete(req *admission.Request) error { | ||
if req.AdmissionRequest.Operation == admissionv1.Delete { | ||
// oldObject is the existing object. | ||
// It is null for DELETE operations in API servers prior to v1.15.0. | ||
// https://github.com/kubernetes/website/pull/14671 | ||
if req.AdmissionRequest.OldObject.Raw == nil { | ||
return ErrOldObjectIsNil | ||
} | ||
|
||
// For admission webhooks registered for DELETE operations on k8s built APIs or CRDs, | ||
// the apiserver now sends the existing object as admissionRequest.Request.OldObject to the webhook | ||
// object is the new object being admitted. | ||
// It is null for DELETE operations. | ||
// https://github.com/kubernetes/kubernetes/pull/76346 | ||
req.AdmissionRequest.Object = req.AdmissionRequest.OldObject | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.