Skip to content

Commit

Permalink
copy typemeta from request to response (#335)
Browse files Browse the repository at this point in the history
* copy ttypemeta from request to response

Signed-off-by: Stuart Hayton <[email protected]>

* fix description
  • Loading branch information
sjhx authored Jun 16, 2021
1 parent c9a1b60 commit 06dfd28
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions pkg/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ func (s *Server) Run() {
func reviewResponseToByte(admissionResponse *admissionv1.AdmissionResponse, admissionReview admissionv1.AdmissionReview) []byte {
response := admissionv1.AdmissionReview{}
if admissionResponse != nil {
response.TypeMeta = admissionReview.TypeMeta
response.Response = admissionResponse
if admissionReview.Request != nil {
response.Response.UID = admissionReview.Request.UID
Expand Down
18 changes: 15 additions & 3 deletions pkg/webhook/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

fakeController "github.com/IBM/portieris/pkg/controller/fakecontroller"
admissionv1 "k8s.io/api/admission/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)

Expand Down Expand Up @@ -80,7 +81,7 @@ func Test_reviewResponseToByte(t *testing.T) {
wantAdmissionReview admissionv1.AdmissionReview
}{
{
name: "Review response matches inputted review with matching request/response UID",
name: "Review response has UUID matching the request",
admissionResponse: &admissionv1.AdmissionResponse{UID: "responseUID", Allowed: true},
admissionReview: admissionv1.AdmissionReview{
Request: &admissionv1.AdmissionRequest{UID: "requestUID"},
Expand All @@ -94,13 +95,24 @@ func Test_reviewResponseToByte(t *testing.T) {
admissionResponse: &admissionv1.AdmissionResponse{},
admissionReview: admissionv1.AdmissionReview{
Request: &admissionv1.AdmissionRequest{
UID: "requestUID",
Object: runtime.RawExtension{Raw: []byte("SomeBytes")},
OldObject: runtime.RawExtension{Raw: []byte("SomeBytes")},
},
},
wantAdmissionReview: admissionv1.AdmissionReview{
Response: &admissionv1.AdmissionResponse{UID: "requestUID"},
Response: &admissionv1.AdmissionResponse{},
},
},
{
name: "Review response object has TypeMeta from incoming review",
admissionResponse: &admissionv1.AdmissionResponse{},
admissionReview: admissionv1.AdmissionReview{
TypeMeta: v1.TypeMeta{Kind: "someKind", APIVersion: "APIVersion10"},
Request: &admissionv1.AdmissionRequest{},
},
wantAdmissionReview: admissionv1.AdmissionReview{
TypeMeta: v1.TypeMeta{Kind: "someKind", APIVersion: "APIVersion10"},
Response: &admissionv1.AdmissionResponse{},
},
},
}
Expand Down

0 comments on commit 06dfd28

Please sign in to comment.