Skip to content

Commit

Permalink
optimize webhook patchResponse function (#1334)
Browse files Browse the repository at this point in the history
Signed-off-by: liheng.zms <[email protected]>
  • Loading branch information
zmberg authored Jul 18, 2023
1 parent 6ec9dee commit 4e35a1d
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 4e35a1d

Please sign in to comment.