diff --git a/pkg/webhook/node/mutating/mutating_handler.go b/pkg/webhook/node/mutating/mutating_handler.go index 42e7f81b6..2e40846e6 100644 --- a/pkg/webhook/node/mutating/mutating_handler.go +++ b/pkg/webhook/node/mutating/mutating_handler.go @@ -131,7 +131,11 @@ func (h *NodeMutatingHandler) Handle(ctx context.Context, req admission.Request) klog.Errorf("Failed to marshal mutated Node %s, err: %v", obj.Name, err) return admission.Errored(http.StatusInternalServerError, err) } - return admission.PatchResponseFromRaw(req.AdmissionRequest.Object.Raw, marshaled) + original, err := json.Marshal(clone) + if err != nil { + return admission.Errored(http.StatusInternalServerError, err) + } + return admission.PatchResponseFromRaw(original, marshaled) } var _ inject.Client = &NodeMutatingHandler{} diff --git a/pkg/webhook/pod/mutating/mutating_handler.go b/pkg/webhook/pod/mutating/mutating_handler.go index 1c8874bd2..539c3bd1f 100644 --- a/pkg/webhook/pod/mutating/mutating_handler.go +++ b/pkg/webhook/pod/mutating/mutating_handler.go @@ -94,7 +94,11 @@ func (h *PodMutatingHandler) Handle(ctx context.Context, req admission.Request) klog.Errorf("Failed to marshal mutated Pod %s/%s, err: %v", obj.Namespace, obj.Name, err) return admission.Errored(http.StatusInternalServerError, err) } - return admission.PatchResponseFromRaw(req.AdmissionRequest.Object.Raw, marshaled) + original, err := json.Marshal(clone) + if err != nil { + return admission.Errored(http.StatusInternalServerError, err) + } + return admission.PatchResponseFromRaw(original, marshaled) } func (h *PodMutatingHandler) handleCreate(ctx context.Context, req admission.Request, obj *corev1.Pod) error {