Skip to content

Commit

Permalink
optimize webhook patchResponse function (openkruise#1334)
Browse files Browse the repository at this point in the history
  • Loading branch information
zmberg authored Jul 18, 2023
1 parent f762f95 commit 9e717af
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/webhook/pod/mutating/pod_create_update_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (h *PodCreateHandler) Handle(ctx context.Context, req admission.Request) ad
if obj.Namespace == "" {
obj.Namespace = req.Namespace
}

oriObj := obj.DeepCopy()
var changed bool

if skip := injectPodReadinessGate(req, obj); !skip {
Expand Down Expand Up @@ -110,7 +110,11 @@ func (h *PodCreateHandler) Handle(ctx context.Context, req admission.Request) ad
if err != nil {
return admission.Errored(http.StatusInternalServerError, err)
}
return admission.PatchResponseFromRaw(req.AdmissionRequest.Object.Raw, marshalled)
original, err := json.Marshal(oriObj)
if err != nil {
return admission.Errored(http.StatusInternalServerError, err)
}
return admission.PatchResponseFromRaw(original, marshalled)
}

var _ inject.Client = &PodCreateHandler{}
Expand Down

0 comments on commit 9e717af

Please sign in to comment.