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

Return TypeMeta as part of the admission response #1444

Merged
merged 1 commit into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion webhook/admission.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@ func admissionHandler(rootLogger *zap.SugaredLogger, stats StatsReporter, c Admi

ctx := logging.WithLogger(r.Context(), logger)

var response admissionv1.AdmissionReview
response := admissionv1.AdmissionReview{
// Use the same type meta as the request - this is required by the K8s API
// note: v1beta1 & v1 AdmissionReview shapes are identical so even though
// we're using v1 types we still support v1beta1 admission requests
TypeMeta: review.TypeMeta,
}

reviewResponse := c.Admit(ctx, review.Request)
var patchType string
if reviewResponse.PatchType != nil {
Expand Down
6 changes: 6 additions & 0 deletions webhook/admission_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"testing"
"time"

"github.com/google/go-cmp/cmp"
"golang.org/x/sync/errgroup"
jsonpatch "gomodules.xyz/jsonpatch/v2"
admissionv1 "k8s.io/api/admission/v1"
Expand Down Expand Up @@ -156,6 +157,11 @@ func TestAdmissionValidResponseForResource(t *testing.T) {
t.Errorf("Failed to decode response: %v", err)
return
}

if diff := cmp.Diff(rev.TypeMeta, reviewResponse.TypeMeta); diff != "" {
t.Errorf("expected the response typeMeta to be the same as the request (-want, +got)\n%s", diff)
return
}
}()

// Check that Admit calls block when they are initiated before informers sync.
Expand Down